diff --git a/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/DataCatalogueFactory.java b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/DataCatalogueFactory.java index 44cbf46..a45758b 100644 --- a/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/DataCatalogueFactory.java +++ b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/DataCatalogueFactory.java @@ -97,6 +97,10 @@ public class DataCatalogueFactory { return MolekulargenuntersuchungCatalogue.create(jdbcTemplate); } else if (c == MolekulargenMsiCatalogue.class) { return MolekulargenMsiCatalogue.create(jdbcTemplate); + } else if (c == MolekularImmunhistoCatalogue.class) { + return MolekularImmunhistoCatalogue.create(jdbcTemplate); + } else if (c == MolekularPcrCatalogue.class) { + return MolekularPcrCatalogue.create(jdbcTemplate); } else if (c == RebiopsieCatalogue.class) { return RebiopsieCatalogue.create(jdbcTemplate); } else if (c == ReevaluationCatalogue.class) { diff --git a/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularImmunhistoCatalogue.java b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularImmunhistoCatalogue.java new file mode 100644 index 0000000..7ca49ab --- /dev/null +++ b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularImmunhistoCatalogue.java @@ -0,0 +1,46 @@ +/* + * This file is part of mv64e-onkostar-data + * + * Copyright (C) 2025 Paul-Christian Volkmer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + */ + +package dev.pcvolkmer.onco.datamapper.datacatalogues; + +import org.springframework.jdbc.core.JdbcTemplate; + +/** + * Load raw result sets from database table 'dk_molekularimmunhisto' + * + * @author Paul-Christian Volkmer + * @since 0.1 + */ +public class MolekularImmunhistoCatalogue extends AbstractSubformDataCatalogue { + + private MolekularImmunhistoCatalogue(JdbcTemplate jdbcTemplate) { + super(jdbcTemplate); + } + + @Override + protected String getTableName() { + return "dk_molekularimmunhisto"; + } + + public static MolekularImmunhistoCatalogue create(JdbcTemplate jdbcTemplate) { + return new MolekularImmunhistoCatalogue(jdbcTemplate); + } + +} diff --git a/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularPcrCatalogue.java b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularPcrCatalogue.java new file mode 100644 index 0000000..e707f2c --- /dev/null +++ b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularPcrCatalogue.java @@ -0,0 +1,46 @@ +/* + * This file is part of mv64e-onkostar-data + * + * Copyright (C) 2025 Paul-Christian Volkmer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + */ + +package dev.pcvolkmer.onco.datamapper.datacatalogues; + +import org.springframework.jdbc.core.JdbcTemplate; + +/** + * Load raw result sets from database table 'dk_molekularpcr' + * + * @author Paul-Christian Volkmer + * @since 0.1 + */ +public class MolekularPcrCatalogue extends AbstractSubformDataCatalogue { + + private MolekularPcrCatalogue(JdbcTemplate jdbcTemplate) { + super(jdbcTemplate); + } + + @Override + protected String getTableName() { + return "dk_molekularpcr"; + } + + public static MolekularPcrCatalogue create(JdbcTemplate jdbcTemplate) { + return new MolekularPcrCatalogue(jdbcTemplate); + } + +} diff --git a/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularImmunhistochemieCatalogueTest.java b/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularImmunhistochemieCatalogueTest.java new file mode 100644 index 0000000..7b6f03b --- /dev/null +++ b/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularImmunhistochemieCatalogueTest.java @@ -0,0 +1,111 @@ +/* + * This file is part of mv64e-onkostar-data + * + * Copyright (C) 2025 Paul-Christian Volkmer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + */ + +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.ArrayList; +import java.util.HashMap; +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.*; + +@ExtendWith(MockitoExtension.class) +class MolekularImmunhistochemieCatalogueTest { + + JdbcTemplate jdbcTemplate; + MolekularImmunhistoCatalogue catalogue; + + @BeforeEach + void setUp(@Mock JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + this.catalogue = MolekularImmunhistoCatalogue.create(jdbcTemplate); + } + + @Test + void shouldUseCorrectQuery(@Mock Map 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 patient.patienten_id, dk_molekularimmunhisto.*, prozedur.patient_id, prozedur.hauptprozedur_id FROM dk_molekularimmunhisto JOIN prozedur ON (prozedur.id = dk_molekularimmunhisto.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND prozedur.id = ?"); + } + + @Test + void shouldUseCorrectMerkmalQuery(@Mock Map resultSet) { + when(resultSet.get(anyString())) + .thenReturn(Map.of("feldname", "name", "feldwert", "wert")); + + doAnswer(invocationOnMock -> List.of(resultSet)) + .when(jdbcTemplate) + .queryForList(anyString(), anyInt()); + + this.catalogue.getMerkmaleById(1); + + var captor = ArgumentCaptor.forClass(String.class); + verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt()); + + assertThat(captor.getValue()) + .isEqualTo("SELECT feldname, feldwert FROM dk_molekularimmunhisto_merkmale WHERE eintrag_id = ?"); + } + + @Test + void shouldUseMerkmalList() { + doAnswer(invocationOnMock -> { + var sql = invocationOnMock.getArgument(0, String.class); + ArrayList> result = new ArrayList<>(); + if (sql.startsWith("SELECT feldname")) { + result.add(Map.of("feldname", "name", "feldwert", "wert1")); + result.add(Map.of("feldname", "name", "feldwert", "wert2")); + } else { + var map = new HashMap(); + map.put("id", 1); + map.put("name", "x"); + result.add(map); + } + return result; + }) + .when(jdbcTemplate) + .queryForList(anyString(), anyInt()); + + var result = this.catalogue.getById(1); + + assertThat(result.getInteger("id")).isEqualTo(1); + assertThat(result.getMerkmalList("name")).isEqualTo(List.of("wert1", "wert2")); + } + +} diff --git a/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularPcrCatalogueTest.java b/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularPcrCatalogueTest.java new file mode 100644 index 0000000..e64ef46 --- /dev/null +++ b/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/MolekularPcrCatalogueTest.java @@ -0,0 +1,111 @@ +/* + * This file is part of mv64e-onkostar-data + * + * Copyright (C) 2025 Paul-Christian Volkmer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + */ + +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.ArrayList; +import java.util.HashMap; +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.*; + +@ExtendWith(MockitoExtension.class) +class MolekularPcrCatalogueTest { + + JdbcTemplate jdbcTemplate; + MolekularPcrCatalogue catalogue; + + @BeforeEach + void setUp(@Mock JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + this.catalogue = MolekularPcrCatalogue.create(jdbcTemplate); + } + + @Test + void shouldUseCorrectQuery(@Mock Map 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 patient.patienten_id, dk_molekularpcr.*, prozedur.patient_id, prozedur.hauptprozedur_id FROM dk_molekularpcr JOIN prozedur ON (prozedur.id = dk_molekularpcr.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND prozedur.id = ?"); + } + + @Test + void shouldUseCorrectMerkmalQuery(@Mock Map resultSet) { + when(resultSet.get(anyString())) + .thenReturn(Map.of("feldname", "name", "feldwert", "wert")); + + doAnswer(invocationOnMock -> List.of(resultSet)) + .when(jdbcTemplate) + .queryForList(anyString(), anyInt()); + + this.catalogue.getMerkmaleById(1); + + var captor = ArgumentCaptor.forClass(String.class); + verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt()); + + assertThat(captor.getValue()) + .isEqualTo("SELECT feldname, feldwert FROM dk_molekularpcr_merkmale WHERE eintrag_id = ?"); + } + + @Test + void shouldUseMerkmalList() { + doAnswer(invocationOnMock -> { + var sql = invocationOnMock.getArgument(0, String.class); + ArrayList> result = new ArrayList<>(); + if (sql.startsWith("SELECT feldname")) { + result.add(Map.of("feldname", "name", "feldwert", "wert1")); + result.add(Map.of("feldname", "name", "feldwert", "wert2")); + } else { + var map = new HashMap(); + map.put("id", 1); + map.put("name", "x"); + result.add(map); + } + return result; + }) + .when(jdbcTemplate) + .queryForList(anyString(), anyInt()); + + var result = this.catalogue.getById(1); + + assertThat(result.getInteger("id")).isEqualTo(1); + assertThat(result.getMerkmalList("name")).isEqualTo(List.of("wert1", "wert2")); + } + +}