mirror of
https://github.com/pcvolkmer/mv64e-onkostar-data.git
synced 2025-09-13 16:02:52 +00:00
feat: add selection by patient id and tumor id
This commit is contained in:
@@ -45,6 +45,38 @@ public class KpaCatalogue extends AbstractDataCatalogue {
|
||||
return result.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest procedure database id by patient id and tumor id
|
||||
*
|
||||
* @param patientId The patients id (not database id)
|
||||
* @param tumorId The tumor identifier
|
||||
* @return The procedure id
|
||||
*/
|
||||
public int getLatestProcedureIdByPatientIdAndTumor(String patientId, int tumorId) {
|
||||
var sql = "SELECT prozedur.id FROM dk_dnpm_kpa " +
|
||||
" JOIN prozedur ON (prozedur.id = dk_dnpm_kpa.id) " +
|
||||
" JOIN erkrankung_prozedur ON (erkrankung_prozedur.prozedur_id = prozedur.id) " +
|
||||
" JOIN erkrankung ON (erkrankung_prozedur.erkrankung_id = erkrankung.id) " +
|
||||
" JOIN patient ON (patient.id = prozedur.patient_id) " +
|
||||
" WHERE patient.patienten_id = ? AND erkrankung.tumoridentifikator = ? " +
|
||||
" ORDER BY dk_dnpm_kpa.anmeldedatummtb DESC " +
|
||||
" LIMIT 1";
|
||||
|
||||
var result = this.jdbcTemplate.query(
|
||||
sql,
|
||||
(resultSet, i) -> resultSet.getInt(1),
|
||||
patientId, tumorId);
|
||||
|
||||
if (result.isEmpty()) {
|
||||
throw new DataAccessException(String.format("No record found for patient '%s' and tumor '%d'", patientId, tumorId));
|
||||
} else if (result.size() > 1) {
|
||||
// This should not happen due to LIMIT 1
|
||||
throw new DataAccessException(String.format("Multiple records found for patient '%s' and tumor '%d'", patientId, tumorId));
|
||||
}
|
||||
|
||||
return result.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get patient database id by case id
|
||||
*
|
||||
|
@@ -131,4 +131,18 @@ public class MtbDataMapper implements DataMapper<Mtb> {
|
||||
this.catalogueFactory.catalogue(KpaCatalogue.class).getProcedureIdByCaseId(caseId)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and maps a Mtb file using the patient id and tumor id
|
||||
*
|
||||
* @param patientId The patients id (not database id)
|
||||
* @param tumorId The tumor identification
|
||||
* @return The loaded Mtb file
|
||||
*/
|
||||
public Mtb getLatestByPatientIdAndTumorId(String patientId, int tumorId) {
|
||||
return this.getById(
|
||||
this.catalogueFactory.catalogue(KpaCatalogue.class)
|
||||
.getLatestProcedureIdByPatientIdAndTumor(patientId, tumorId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user