1
0
mirror of https://github.com/pcvolkmer/mv64e-onkostar-data.git synced 2025-09-14 00:12:52 +00:00

feat: add initial Therapieplan support

This commit is contained in:
2025-06-22 16:26:23 +02:00
parent 684c866b97
commit a24855ec7a
6 changed files with 236 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
package dev.pcvolkmer.onco.datamapper.datacatalogues;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.jdbc.core.JdbcTemplate;
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.verify;
@ExtendWith(MockitoExtension.class)
class TherapieplanCatalogueTest {
JdbcTemplate jdbcTemplate;
TherapieplanCatalogue catalogue;
@BeforeEach
void setUp(@Mock JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
this.catalogue = TherapieplanCatalogue.create(jdbcTemplate);
}
@Test
void shouldUseCorrectQuery(@Mock Map<String, Object> resultSet) {
doAnswer(invocationOnMock -> List.of(resultSet))
.when(jdbcTemplate)
.queryForList(anyString(), anyInt());
this.catalogue.getById(1);
var captor = ArgumentCaptor.forClass(String.class);
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
assertThat(captor.getValue())
.isEqualTo("SELECT * FROM dk_dnpm_therapieplan JOIN prozedur ON (prozedur.id = dk_dnpm_therapieplan.id) WHERE geloescht = 0 AND prozedur.id = ?");
}
@Test
void shouldUseCorrectQueryForKpaRelatedProcedures(@Mock Map<String, Object> resultSet) {
doAnswer(invocationOnMock -> List.of(resultSet))
.when(jdbcTemplate)
.queryForList(anyString(), anyInt());
this.catalogue.getByKpaId(1);
var captor = ArgumentCaptor.forClass(String.class);
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
assertThat(captor.getValue())
.isEqualTo("SELECT prozedur.id AS procedure_id FROM dk_dnpm_therapieplan JOIN prozedur ON (prozedur.id = dk_dnpm_therapieplan.id) WHERE geloescht = 0 AND ref_dnpm_klinikanamnese = ?");
}
}

View File

@@ -0,0 +1,62 @@
package dev.pcvolkmer.onco.datamapper.mapper;
import dev.pcvolkmer.mv64e.mtb.MtbCarePlan;
import dev.pcvolkmer.mv64e.mtb.Reference;
import dev.pcvolkmer.onco.datamapper.PropertyCatalogue;
import dev.pcvolkmer.onco.datamapper.ResultSet;
import dev.pcvolkmer.onco.datamapper.datacatalogues.TherapieplanCatalogue;
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.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;
@ExtendWith(MockitoExtension.class)
class TherapieplanDataMapperTest {
TherapieplanCatalogue therapieplanCatalogue;
PropertyCatalogue propertyCatalogue;
TherapieplanDataMapper dataMapper;
@BeforeEach
void setUp(
@Mock TherapieplanCatalogue therapieplanCatalogue,
@Mock PropertyCatalogue propertyCatalogue
) {
this.therapieplanCatalogue = therapieplanCatalogue;
this.propertyCatalogue = propertyCatalogue;
this.dataMapper = new TherapieplanDataMapper(therapieplanCatalogue, propertyCatalogue);
}
@Test
void shouldCreateCarePlan(@Mock ResultSet resultSet) {
final var testData = Map.of(
"id", "1",
"patient_id", "42"
);
doAnswer(invocationOnMock -> {
var columnName = invocationOnMock.getArgument(0, String.class);
return testData.get(columnName);
}).when(resultSet).getString(anyString());
doAnswer(invocationOnMock -> resultSet)
.when(therapieplanCatalogue)
.getById(anyInt());
var actual = this.dataMapper.getById(1);
assertThat(actual).isInstanceOf(MtbCarePlan.class);
assertThat(actual.getId()).isEqualTo("1");
assertThat(actual.getPatient())
.isEqualTo(Reference.builder().id("42").type("Patient").build());
}
}