mirror of
https://github.com/pcvolkmer/mv64e-onkostar-data.git
synced 2025-07-02 02:22:54 +00:00
feat: add mapping for KPA prozeduren
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package dev.pcvolkmer.onco.datamapper;
|
||||
|
||||
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@ -25,8 +27,35 @@ public class ResultSet {
|
||||
return rawData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the procedure id
|
||||
*
|
||||
* @return The procedure id if any
|
||||
*/
|
||||
public Integer getProcedureId() {
|
||||
var procedureId = this.getInteger("procedure.id");
|
||||
if (procedureId == null) {
|
||||
throw new DataAccessException("No procedure id found");
|
||||
}
|
||||
return procedureId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the disease id
|
||||
*
|
||||
* @return The procedure id if any
|
||||
*/
|
||||
public Integer getDiseaseId() {
|
||||
var diseaseId = this.getInteger("erkrankung.id");
|
||||
if (diseaseId == null) {
|
||||
throw new DataAccessException("No disease id found");
|
||||
}
|
||||
return diseaseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column value as String and cast value if possible
|
||||
*
|
||||
* @param columnName The name of the column
|
||||
* @return The column value as String
|
||||
*/
|
||||
@ -46,6 +75,7 @@ public class ResultSet {
|
||||
|
||||
/**
|
||||
* Get column value as Integer and cast value if possible
|
||||
*
|
||||
* @param columnName The name of the column
|
||||
* @return The column value as Integer
|
||||
*/
|
||||
@ -61,8 +91,29 @@ public class ResultSet {
|
||||
throw new IllegalArgumentException("Cannot convert " + raw.getClass() + " to Integer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column value as Long and cast value if possible
|
||||
*
|
||||
* @param columnName The name of the column
|
||||
* @return The column value as Integer
|
||||
*/
|
||||
public Long getLong(String columnName) {
|
||||
var raw = this.rawData.get(columnName);
|
||||
|
||||
if (raw == null) {
|
||||
return null;
|
||||
} else if (raw instanceof Integer) {
|
||||
return ((Integer) raw).longValue();
|
||||
} else if (raw instanceof Long) {
|
||||
return ((Long) raw);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Cannot convert " + raw.getClass() + " to Integer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column value as Date and cast value if possible
|
||||
*
|
||||
* @param columnName The name of the column
|
||||
* @return The column value as Date
|
||||
*/
|
||||
|
@ -4,6 +4,9 @@ import dev.pcvolkmer.onco.datamapper.ResultSet;
|
||||
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Common implementations for all data catalogues
|
||||
*
|
||||
@ -45,4 +48,21 @@ public abstract class AbstractDataCatalogue implements DataCatalogue {
|
||||
return ResultSet.from(result.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns related diseases
|
||||
* @param procedureId The procedure id
|
||||
* @return the diseases
|
||||
*/
|
||||
public List<ResultSet> getDiseases(int procedureId) {
|
||||
return this.jdbcTemplate.queryForList(
|
||||
String.format(
|
||||
"SELECT * FROM erkrankung_prozedur JOIN erkrankung ON (erkrankung.id = erkrankung_prozedur.erkrankung.id) WHERE erkrankung_prozedur.prozedur_id = ?",
|
||||
getTableName(),
|
||||
getTableName()
|
||||
),
|
||||
procedureId)
|
||||
.stream()
|
||||
.map(ResultSet::from)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,12 @@ public abstract class AbstractSubformDataCatalogue extends AbstractDataCatalogue
|
||||
protected abstract String getTableName();
|
||||
|
||||
/**
|
||||
* Get procedure result sets by main procedure id
|
||||
* Get procedure result sets by parent procedure id
|
||||
*
|
||||
* @param id The procedure id
|
||||
* @return The procedure id
|
||||
* @param id The parents procedure id
|
||||
* @return The sub procedures
|
||||
*/
|
||||
public List<ResultSet> getAllByMainId(int id) {
|
||||
public List<ResultSet> getAllByParentId(int id) {
|
||||
return this.jdbcTemplate.queryForList(
|
||||
String.format(
|
||||
"SELECT * FROM %s JOIN prozedur ON (prozedur.id = %s.id) WHERE geloescht = 0 AND hauptprozedur_id = ?",
|
||||
|
@ -0,0 +1,149 @@
|
||||
package dev.pcvolkmer.onco.datamapper.mapper;
|
||||
|
||||
import dev.pcvolkmer.mv64e.mtb.*;
|
||||
import dev.pcvolkmer.onco.datamapper.ResultSet;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.ProzedurCatalogue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Mapper class to load and map prozedur data from database table 'dk_dnpm_uf_prozedur'
|
||||
*
|
||||
* @author Paul-Christian Volkmer
|
||||
* @since 0.1
|
||||
*/
|
||||
public class KpaProzedurDataMapper implements SubformDataMapper<OncoProcedure> {
|
||||
|
||||
private final ProzedurCatalogue catalogue;
|
||||
|
||||
public KpaProzedurDataMapper(final ProzedurCatalogue catalogue) {
|
||||
this.catalogue = catalogue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and maps Prozedur related by database id
|
||||
*
|
||||
* @param id The database id of the procedure data set
|
||||
* @return The loaded MtbDiagnosis file
|
||||
*/
|
||||
@Override
|
||||
public OncoProcedure getById(final int id) {
|
||||
var data = catalogue.getById(id);
|
||||
return this.map(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OncoProcedure> getByParentId(final int parentId) {
|
||||
return catalogue.getAllByParentId(parentId)
|
||||
.stream()
|
||||
.map(this::map)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private OncoProcedure map(final ResultSet resultSet) {
|
||||
var diseases = catalogue.getDiseases(resultSet.getProcedureId());
|
||||
|
||||
if (diseases.size() != 1) {
|
||||
throw new IllegalStateException(String.format("No unique disease for procedure %s", resultSet.getProcedureId()));
|
||||
}
|
||||
|
||||
var builder = OncoProcedure.builder();
|
||||
builder
|
||||
.id(resultSet.getString("id"))
|
||||
.patient(Reference.builder().id(resultSet.getString("patient_id")).build())
|
||||
.basedOn(Reference.builder().id(diseases.get(0).getDiseaseId().toString()).build())
|
||||
.recordedOn(resultSet.getDate("erfassungsdatum"))
|
||||
.therapyLine(resultSet.getLong("therapielinie"))
|
||||
.intent(getMtbTherapyIntentCoding(resultSet.getString("intention")))
|
||||
.status(getTherapyStatusCoding(resultSet.getString("status")))
|
||||
.statusReason(getMtbTherapyStatusReasonCoding(resultSet.getString("statusgrund")))
|
||||
.period(PeriodDate.builder().start(resultSet.getDate("beginn")).end(resultSet.getDate("ende")).build())
|
||||
.code(getOncoProcedureCoding(resultSet.getString("typ")))
|
||||
;
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private MtbTherapyIntentCoding getMtbTherapyIntentCoding(String value) {
|
||||
if (value == null || ! Arrays.stream(MtbTherapyIntentCodingCode.values()).map(MtbTherapyIntentCodingCode::toValue).collect(Collectors.toSet()).contains(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var resultBuilder = MtbTherapyIntentCoding.builder();
|
||||
|
||||
switch (value) {
|
||||
case "X":
|
||||
resultBuilder.code(MtbTherapyIntentCodingCode.X);
|
||||
break;
|
||||
case "K":
|
||||
resultBuilder.code(MtbTherapyIntentCodingCode.K);
|
||||
break;
|
||||
case "P":
|
||||
resultBuilder.code(MtbTherapyIntentCodingCode.P);
|
||||
break;
|
||||
case "S":
|
||||
resultBuilder.code(MtbTherapyIntentCodingCode.S);
|
||||
break;
|
||||
}
|
||||
|
||||
return resultBuilder.build();
|
||||
}
|
||||
|
||||
private TherapyStatusCoding getTherapyStatusCoding(String value) {
|
||||
if (value == null || ! Arrays.stream(TherapyStatusCodingCode.values()).map(TherapyStatusCodingCode::toValue).collect(Collectors.toSet()).contains(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var resultBuilder = TherapyStatusCoding.builder();
|
||||
|
||||
switch (value) {
|
||||
case "not-done":
|
||||
resultBuilder.code(TherapyStatusCodingCode.NOT_DONE);
|
||||
break;
|
||||
case "on-going":
|
||||
resultBuilder.code(TherapyStatusCodingCode.ON_GOING);
|
||||
break;
|
||||
case "stopped":
|
||||
resultBuilder.code(TherapyStatusCodingCode.STOPPED);
|
||||
break;
|
||||
case "completed":
|
||||
resultBuilder.code(TherapyStatusCodingCode.COMPLETED);
|
||||
break;
|
||||
}
|
||||
|
||||
return resultBuilder.build();
|
||||
}
|
||||
|
||||
private MtbTherapyStatusReasonCoding getMtbTherapyStatusReasonCoding(String value) {
|
||||
if (value == null || ! Arrays.stream(MtbTherapyStatusReasonCodingCode.values()).map(MtbTherapyStatusReasonCodingCode::toValue).collect(Collectors.toSet()).contains(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var resultBuilder = MtbTherapyStatusReasonCoding.builder();
|
||||
try {
|
||||
resultBuilder.code(MtbTherapyStatusReasonCodingCode.forValue(value));
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return resultBuilder.build();
|
||||
}
|
||||
|
||||
private OncoProcedureCoding getOncoProcedureCoding(String value) {
|
||||
if (value == null || ! Arrays.stream(OncoProcedureCodingCode.values()).map(OncoProcedureCodingCode::toValue).collect(Collectors.toSet()).contains(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var resultBuilder = OncoProcedureCoding.builder();
|
||||
try {
|
||||
resultBuilder.code(OncoProcedureCodingCode.forValue(value));
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("No valid code found");
|
||||
}
|
||||
|
||||
return resultBuilder.build();
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import dev.pcvolkmer.mv64e.mtb.Mtb;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.DataCatalogueFactory;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.KpaCatalogue;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.PatientCatalogue;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.ProzedurCatalogue;
|
||||
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -60,6 +61,7 @@ public class MtbDataMapper implements DataMapper<Mtb> {
|
||||
var patientDataMapper = new PatientDataMapper(catalogueFactory.catalogue(PatientCatalogue.class));
|
||||
var kpaPatientDataMapper = new KpaPatientDataMapper(kpaCatalogue);
|
||||
var diagnosisDataMapper = new KpaDiagnosisDataMapper(kpaCatalogue);
|
||||
var prozedurMapper = new KpaProzedurDataMapper(catalogueFactory.catalogue(ProzedurCatalogue.class));
|
||||
|
||||
var resultBuilder = Mtb.builder();
|
||||
|
||||
@ -70,7 +72,9 @@ public class MtbDataMapper implements DataMapper<Mtb> {
|
||||
|
||||
resultBuilder
|
||||
.patient(kpaPatient)
|
||||
.diagnoses(List.of(diagnosisDataMapper.getById(kpaId)));
|
||||
.diagnoses(List.of(diagnosisDataMapper.getById(kpaId)))
|
||||
.guidelineProcedures(prozedurMapper.getByParentId(kpaId))
|
||||
;
|
||||
} catch (DataAccessException e) {
|
||||
logger.error("Error while getting Mtb.", e);
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package dev.pcvolkmer.onco.datamapper.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* General interface for subform data mappers
|
||||
*
|
||||
* @since 0.1
|
||||
* @author Paul-Christian Volkmer
|
||||
* @param <T> The destination type
|
||||
*/
|
||||
public interface SubformDataMapper<T> extends DataMapper<T> {
|
||||
|
||||
/**
|
||||
* Loads a data set from database and maps it into destination data type
|
||||
* @param parentId The database id of the parent procedure data set
|
||||
* @return The data set to be loaded
|
||||
*/
|
||||
List<T> getByParentId(int parentId);
|
||||
|
||||
}
|
@ -26,6 +26,13 @@ class ResultSetTest {
|
||||
assertThat(data.getInteger("int")).isEqualTo(42);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnLongValues() {
|
||||
var data = getTestData();
|
||||
|
||||
assertThat(data.getLong("int")).isEqualTo(42L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnDateValues() {
|
||||
var data = getTestData();
|
||||
|
@ -50,7 +50,7 @@ class EcogCatalogueTest {
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
|
||||
this.catalogue.getAllByMainId(1);
|
||||
this.catalogue.getAllByParentId(1);
|
||||
|
||||
var captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
||||
|
@ -50,7 +50,7 @@ class HistologieCatalogueTest {
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
|
||||
this.catalogue.getAllByMainId(1);
|
||||
this.catalogue.getAllByParentId(1);
|
||||
|
||||
var captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
||||
|
@ -50,7 +50,7 @@ class ProzedurCatalogueTest {
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
|
||||
this.catalogue.getAllByMainId(1);
|
||||
this.catalogue.getAllByParentId(1);
|
||||
|
||||
var captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
||||
|
@ -50,7 +50,7 @@ class TherapielinieCatalogueTest {
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
|
||||
this.catalogue.getAllByMainId(1);
|
||||
this.catalogue.getAllByParentId(1);
|
||||
|
||||
var captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
||||
|
@ -50,7 +50,7 @@ class TumorausbreitungCatalogueTest {
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
|
||||
this.catalogue.getAllByMainId(1);
|
||||
this.catalogue.getAllByParentId(1);
|
||||
|
||||
var captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
||||
|
@ -50,7 +50,7 @@ class TumorgradingCatalogueTest {
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
|
||||
this.catalogue.getAllByMainId(1);
|
||||
this.catalogue.getAllByParentId(1);
|
||||
|
||||
var captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
||||
|
@ -50,7 +50,7 @@ class VerwandteCatalogueTest {
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
|
||||
this.catalogue.getAllByMainId(1);
|
||||
this.catalogue.getAllByParentId(1);
|
||||
|
||||
var captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
||||
|
@ -50,7 +50,7 @@ class VorbefundeCatalogueTest {
|
||||
.when(jdbcTemplate)
|
||||
.queryForList(anyString(), anyInt());
|
||||
|
||||
this.catalogue.getAllByMainId(1);
|
||||
this.catalogue.getAllByParentId(1);
|
||||
|
||||
var captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
||||
|
@ -0,0 +1,105 @@
|
||||
package dev.pcvolkmer.onco.datamapper.mapper;
|
||||
|
||||
import dev.pcvolkmer.mv64e.mtb.*;
|
||||
import dev.pcvolkmer.onco.datamapper.ResultSet;
|
||||
import dev.pcvolkmer.onco.datamapper.datacatalogues.ProzedurCatalogue;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class KpaProzedurDataMapperTest {
|
||||
|
||||
ProzedurCatalogue catalogue;
|
||||
|
||||
KpaProzedurDataMapper dataMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp(@Mock ProzedurCatalogue catalogue) {
|
||||
this.catalogue = catalogue;
|
||||
this.dataMapper = new KpaProzedurDataMapper(catalogue);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMapResultSet(@Mock ResultSet resultSet) {
|
||||
var testData = Map.of(
|
||||
"erkrankung.id", "1",
|
||||
"id", "1",
|
||||
"beginn", new java.sql.Date(Date.from(Instant.parse("2000-01-01T12:00:00Z")).getTime()),
|
||||
"ende", new java.sql.Date(Date.from(Instant.parse("2024-06-19T12:00:00Z")).getTime()),
|
||||
"erfassungsdatum", new java.sql.Date(Date.from(Instant.parse("2024-06-19T12:00:00Z")).getTime()),
|
||||
"intention", "S",
|
||||
"status", "stopped",
|
||||
"statusgrund", "patient-death",
|
||||
"therapielinie", 1L,
|
||||
"typ", "surgery"
|
||||
);
|
||||
|
||||
doAnswer(invocationOnMock -> {
|
||||
var columnName = invocationOnMock.getArgument(0, String.class);
|
||||
return testData.get(columnName);
|
||||
}).when(resultSet).getString(anyString());
|
||||
|
||||
doAnswer(invocationOnMock -> {
|
||||
var columnName = invocationOnMock.getArgument(0, String.class);
|
||||
return testData.get(columnName);
|
||||
}).when(resultSet).getLong(anyString());
|
||||
|
||||
doAnswer(invocationOnMock -> {
|
||||
var columnName = invocationOnMock.getArgument(0, String.class);
|
||||
return testData.get(columnName);
|
||||
}).when(resultSet).getDate(anyString());
|
||||
|
||||
when(resultSet.getDiseaseId()).thenReturn(1);
|
||||
when(resultSet.getProcedureId()).thenReturn(1);
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(resultSet))
|
||||
.when(catalogue)
|
||||
.getAllByParentId(anyInt());
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(resultSet))
|
||||
.when(catalogue)
|
||||
.getDiseases(anyInt());
|
||||
|
||||
var actualList = this.dataMapper.getByParentId(1);
|
||||
assertThat(actualList).hasSize(1);
|
||||
|
||||
var actual = actualList.get(0);
|
||||
assertThat(actual).isInstanceOf(OncoProcedure.class);
|
||||
assertThat(actual.getId()).isEqualTo("1");
|
||||
assertThat(actual.getPeriod()).isEqualTo(
|
||||
PeriodDate.builder()
|
||||
.start(Date.from(Instant.parse("2000-01-01T12:00:00Z")))
|
||||
.end(Date.from(Instant.parse("2024-06-19T12:00:00Z")))
|
||||
.build()
|
||||
);
|
||||
assertThat(actual.getRecordedOn()).isEqualTo(Date.from(Instant.parse("2024-06-19T12:00:00Z")));
|
||||
assertThat(actual.getIntent()).isEqualTo(
|
||||
MtbTherapyIntentCoding.builder().code(MtbTherapyIntentCodingCode.S).build()
|
||||
);
|
||||
assertThat(actual.getStatus()).isEqualTo(
|
||||
TherapyStatusCoding.builder().code(TherapyStatusCodingCode.STOPPED).build()
|
||||
);
|
||||
assertThat(actual.getStatusReason()).isEqualTo(
|
||||
MtbTherapyStatusReasonCoding.builder().code(MtbTherapyStatusReasonCodingCode.PATIENT_DEATH).build()
|
||||
);
|
||||
assertThat(actual.getTherapyLine()).isEqualTo(1);
|
||||
assertThat(actual.getCode()).isEqualTo(
|
||||
OncoProcedureCoding.builder().code(OncoProcedureCodingCode.SURGERY).build()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user