mirror of
https://github.com/pcvolkmer/mv64e-onkostar-data.git
synced 2025-09-13 07:52:52 +00:00
feat: initial support for NGS reports
This commit is contained in:
@@ -93,6 +93,8 @@ public class DataCatalogueFactory {
|
|||||||
return EinzelempfehlungCatalogue.create(jdbcTemplate);
|
return EinzelempfehlungCatalogue.create(jdbcTemplate);
|
||||||
} else if (c == MolekulargenetikCatalogue.class) {
|
} else if (c == MolekulargenetikCatalogue.class) {
|
||||||
return MolekulargenetikCatalogue.create(jdbcTemplate);
|
return MolekulargenetikCatalogue.create(jdbcTemplate);
|
||||||
|
} else if (c == MolekulargenuntersuchungCatalogue.class) {
|
||||||
|
return MolekulargenuntersuchungCatalogue.create(jdbcTemplate);
|
||||||
} else if (c == RebiopsieCatalogue.class) {
|
} else if (c == RebiopsieCatalogue.class) {
|
||||||
return RebiopsieCatalogue.create(jdbcTemplate);
|
return RebiopsieCatalogue.create(jdbcTemplate);
|
||||||
} else if (c == ReevaluationCatalogue.class) {
|
} else if (c == ReevaluationCatalogue.class) {
|
||||||
|
@@ -20,15 +20,19 @@
|
|||||||
|
|
||||||
package dev.pcvolkmer.onco.datamapper.datacatalogues;
|
package dev.pcvolkmer.onco.datamapper.datacatalogues;
|
||||||
|
|
||||||
|
import dev.pcvolkmer.onco.datamapper.ResultSet;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load raw result sets from database table 'dk_molekulargenetik'
|
* Load raw result sets from database table 'dk_molekulargenetik'
|
||||||
*
|
*
|
||||||
* @author Paul-Christian Volkmer
|
* @author Paul-Christian Volkmer
|
||||||
* @since 0.1
|
* @since 0.1
|
||||||
*/
|
*/
|
||||||
public class MolekulargenetikCatalogue extends AbstractSubformDataCatalogue {
|
public class MolekulargenetikCatalogue extends AbstractDataCatalogue {
|
||||||
|
|
||||||
private MolekulargenetikCatalogue(JdbcTemplate jdbcTemplate) {
|
private MolekulargenetikCatalogue(JdbcTemplate jdbcTemplate) {
|
||||||
super(jdbcTemplate);
|
super(jdbcTemplate);
|
||||||
@@ -43,4 +47,55 @@ public class MolekulargenetikCatalogue extends AbstractSubformDataCatalogue {
|
|||||||
return new MolekulargenetikCatalogue(jdbcTemplate);
|
return new MolekulargenetikCatalogue(jdbcTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get procedure IDs by related Therapieplan procedure id
|
||||||
|
* Related form references in Einzelempfehlung, Rebiopsie, Reevaluation
|
||||||
|
*
|
||||||
|
* @param therapieplanId The procedure id
|
||||||
|
* @return The procedure ids
|
||||||
|
*/
|
||||||
|
public List<Integer> getByTherapieplanId(int therapieplanId) {
|
||||||
|
return this.jdbcTemplate.queryForList(
|
||||||
|
"SELECT DISTINCT ref_molekulargenetik FROM dk_dnpm_uf_einzelempfehlung JOIN prozedur ON (prozedur.id = dk_dnpm_uf_einzelempfehlung.id) "
|
||||||
|
+ " WHERE ref_molekulargenetik IS NOT NULL AND hauptprozedur_id = ? "
|
||||||
|
+ " UNION SELECT ref_molekulargenetik FROM dk_dnpm_uf_rebiopsie JOIN prozedur ON (prozedur.id = dk_dnpm_uf_rebiopsie.id) "
|
||||||
|
+ " WHERE ref_molekulargenetik IS NOT NULL AND hauptprozedur_id = ? "
|
||||||
|
+ " UNION SELECT ref_molekulargenetik FROM dk_dnpm_uf_reevaluation JOIN prozedur ON (prozedur.id = dk_dnpm_uf_reevaluation.id) "
|
||||||
|
+ " WHERE ref_molekulargenetik IS NOT NULL AND hauptprozedur_id = ?;"
|
||||||
|
,
|
||||||
|
therapieplanId,
|
||||||
|
therapieplanId,
|
||||||
|
therapieplanId)
|
||||||
|
.stream()
|
||||||
|
.map(ResultSet::from)
|
||||||
|
.map(rs -> rs.getInteger("ref_molekulargenetik"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get procedure IDs used in related KPA/Therapieplan procedures
|
||||||
|
* Related form references in Einzelempfehlung, Rebiopsie, Reevaluation
|
||||||
|
*
|
||||||
|
* @param kpaId The procedure id
|
||||||
|
* @return The procedure ids
|
||||||
|
*/
|
||||||
|
public List<Integer> getIdsByKpaId(int kpaId) {
|
||||||
|
return this.jdbcTemplate.queryForList(
|
||||||
|
"SELECT DISTINCT ref_molekulargenetik FROM dk_dnpm_uf_einzelempfehlung JOIN prozedur ON (prozedur.id = dk_dnpm_uf_einzelempfehlung.id) "
|
||||||
|
+ " WHERE ref_molekulargenetik IS NOT NULL AND hauptprozedur_id IN (SELECT id FROM dk_dnpm_therapieplan WHERE ref_dnpm_klinikanamnese = ?) "
|
||||||
|
+ " UNION SELECT ref_molekulargenetik FROM dk_dnpm_uf_rebiopsie JOIN prozedur ON (prozedur.id = dk_dnpm_uf_rebiopsie.id) "
|
||||||
|
+ " WHERE ref_molekulargenetik IS NOT NULL AND hauptprozedur_id IN (SELECT id FROM dk_dnpm_therapieplan WHERE ref_dnpm_klinikanamnese = ?) "
|
||||||
|
+ " UNION SELECT ref_molekulargenetik FROM dk_dnpm_uf_reevaluation JOIN prozedur ON (prozedur.id = dk_dnpm_uf_reevaluation.id) "
|
||||||
|
+ " WHERE ref_molekulargenetik IS NOT NULL AND hauptprozedur_id IN (SELECT id FROM dk_dnpm_therapieplan WHERE ref_dnpm_klinikanamnese = ?);"
|
||||||
|
,
|
||||||
|
kpaId,
|
||||||
|
kpaId,
|
||||||
|
kpaId)
|
||||||
|
.stream()
|
||||||
|
.map(ResultSet::from)
|
||||||
|
.map(rs -> rs.getInteger("ref_molekulargenetik"))
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.pcvolkmer.onco.datamapper.datacatalogues;
|
||||||
|
|
||||||
|
import dev.pcvolkmer.onco.datamapper.ResultSet;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load raw result sets from database table 'dk_molekulargenuntersuchung'
|
||||||
|
*
|
||||||
|
* @author Paul-Christian Volkmer
|
||||||
|
* @since 0.1
|
||||||
|
*/
|
||||||
|
public class MolekulargenuntersuchungCatalogue extends AbstractSubformDataCatalogue {
|
||||||
|
|
||||||
|
private MolekulargenuntersuchungCatalogue(JdbcTemplate jdbcTemplate) {
|
||||||
|
super(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTableName() {
|
||||||
|
return "dk_molekulargenuntersuchung";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MolekulargenuntersuchungCatalogue create(JdbcTemplate jdbcTemplate) {
|
||||||
|
return new MolekulargenuntersuchungCatalogue(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
package dev.pcvolkmer.onco.datamapper.genes;
|
package dev.pcvolkmer.onco.datamapper.genes;
|
||||||
|
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.Coding;
|
||||||
import org.apache.commons.csv.CSVFormat;
|
import org.apache.commons.csv.CSVFormat;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -48,6 +49,14 @@ public class GeneUtils {
|
|||||||
return genes().stream().filter(gene -> gene.getSymbol().equalsIgnoreCase(symbol)).findFirst();
|
return genes().stream().filter(gene -> gene.getSymbol().equalsIgnoreCase(symbol)).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Coding toCoding(Gene gene) {
|
||||||
|
return Coding.builder()
|
||||||
|
.code(gene.getHgncId())
|
||||||
|
.display(gene.getSymbol())
|
||||||
|
.system("https://www.genenames.org/")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
private static List<Gene> genes() {
|
private static List<Gene> genes() {
|
||||||
var result = new ArrayList<Gene>();
|
var result = new ArrayList<Gene>();
|
||||||
|
|
||||||
|
@@ -23,7 +23,6 @@ package dev.pcvolkmer.onco.datamapper.mapper;
|
|||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import dev.pcvolkmer.mv64e.mtb.Coding;
|
|
||||||
import dev.pcvolkmer.mv64e.mtb.GeneAlterationReference;
|
import dev.pcvolkmer.mv64e.mtb.GeneAlterationReference;
|
||||||
import dev.pcvolkmer.mv64e.mtb.Reference;
|
import dev.pcvolkmer.mv64e.mtb.Reference;
|
||||||
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
||||||
@@ -53,19 +52,11 @@ public class JsonToMolAltVarianteMapper {
|
|||||||
}).stream()
|
}).stream()
|
||||||
.map(variante -> {
|
.map(variante -> {
|
||||||
var resultBuilder = GeneAlterationReference.builder();
|
var resultBuilder = GeneAlterationReference.builder();
|
||||||
GeneUtils.findBySymbol(variante.getGen()).ifPresent(gene -> {
|
GeneUtils.findBySymbol(variante.getGen()).ifPresent(gene -> resultBuilder
|
||||||
resultBuilder
|
.gene(GeneUtils.toCoding(gene))
|
||||||
.gene(
|
.variant(
|
||||||
Coding.builder()
|
Reference.builder().id(variante.id).type("Variant").build()
|
||||||
.code(gene.getHgncId())
|
));
|
||||||
.display(gene.getSymbol())
|
|
||||||
.system("https://www.genenames.org/")
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.variant(
|
|
||||||
Reference.builder().id(variante.id).type("Variant").build()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return resultBuilder.build();
|
return resultBuilder.build();
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.pcvolkmer.onco.datamapper.mapper;
|
||||||
|
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.*;
|
||||||
|
import dev.pcvolkmer.onco.datamapper.PropertyCatalogue;
|
||||||
|
import dev.pcvolkmer.onco.datamapper.datacatalogues.*;
|
||||||
|
import dev.pcvolkmer.onco.datamapper.genes.GeneUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapper class to load and map prozedur data from database table 'dk_molekulargenetik'
|
||||||
|
*
|
||||||
|
* @author Paul-Christian Volkmer
|
||||||
|
* @since 0.1
|
||||||
|
*/
|
||||||
|
public class KpaMolekulargenetikDataMapper implements DataMapper<SomaticNgsReport> {
|
||||||
|
|
||||||
|
private final MolekulargenetikCatalogue catalogue;
|
||||||
|
private final MolekulargenuntersuchungCatalogue untersuchungCatalogue;
|
||||||
|
|
||||||
|
public KpaMolekulargenetikDataMapper(
|
||||||
|
final MolekulargenetikCatalogue catalogue,
|
||||||
|
final MolekulargenuntersuchungCatalogue untersuchungCatalogue,
|
||||||
|
final PropertyCatalogue propertyCatalogue
|
||||||
|
) {
|
||||||
|
this.catalogue = catalogue;
|
||||||
|
this.untersuchungCatalogue = untersuchungCatalogue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads and maps Prozedur related by database id
|
||||||
|
*
|
||||||
|
* @param id The database id of the procedure data set
|
||||||
|
* @return The loaded Procedure
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SomaticNgsReport getById(final int id) {
|
||||||
|
var data = catalogue.getById(id);
|
||||||
|
|
||||||
|
var builder = SomaticNgsReport.builder();
|
||||||
|
builder
|
||||||
|
.id(data.getString("id"))
|
||||||
|
.patient(data.getPatientReference())
|
||||||
|
.issuedOn(data.getDate("datum"))
|
||||||
|
.specimen(Reference.builder().id(data.getString("einsendenummer")).type("Specimen").build())
|
||||||
|
.results(this.getNgsReportResults(id))
|
||||||
|
;
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads and maps all Prozedur related by KPA database id
|
||||||
|
*
|
||||||
|
* @param kpaId The database id of the KPA procedure data set
|
||||||
|
* @return The loaded Procedures
|
||||||
|
*/
|
||||||
|
public List<SomaticNgsReport> getAllByKpaId(final int kpaId) {
|
||||||
|
return this.catalogue.getIdsByKpaId(kpaId).stream()
|
||||||
|
.distinct()
|
||||||
|
.map(this::getById)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private NgsReportResults getNgsReportResults(int id) {
|
||||||
|
var subforms = this.untersuchungCatalogue.getAllByParentId(id);
|
||||||
|
|
||||||
|
var resultBuilder = NgsReportResults.builder();
|
||||||
|
resultBuilder.simpleVariants(
|
||||||
|
subforms.stream()
|
||||||
|
// P => Einfache Variante
|
||||||
|
.filter(subform -> "P".equals(subform.getString("ergebnis")))
|
||||||
|
.map(subform -> {
|
||||||
|
final var geneOptional = GeneUtils.findBySymbol(subform.getString("untersucht"));
|
||||||
|
if (geneOptional.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final var snvBuilder = Snv.builder()
|
||||||
|
.id(subform.getString("id"))
|
||||||
|
.patient(subform.getPatientReference())
|
||||||
|
.gene(GeneUtils.toCoding(geneOptional.get()))
|
||||||
|
.exonId(subform.getString("exon"))
|
||||||
|
.dnaChange(subform.getString("cdnanomenklatur"))
|
||||||
|
.proteinChange(subform.getString("proteinebenenomenklatur"));
|
||||||
|
|
||||||
|
if (null != subform.getLong("allelfrequenz")) {
|
||||||
|
snvBuilder.allelicFrequency(subform.getLong("allelfrequenz"));
|
||||||
|
}
|
||||||
|
if (null != subform.getLong("evreaddepth")) {
|
||||||
|
snvBuilder.readDepth(subform.getLong("evreaddepth"));
|
||||||
|
}
|
||||||
|
geneOptional.get().getSingleChromosomeInPropertyForm().ifPresent(snvBuilder::chromosome);
|
||||||
|
|
||||||
|
return snvBuilder.build();
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
|
||||||
|
resultBuilder.copyNumberVariants(
|
||||||
|
subforms.stream()
|
||||||
|
.filter(subform -> "CNV".equals(subform.getString("ergebnis")))
|
||||||
|
.map(subform -> {
|
||||||
|
final var geneOptional = GeneUtils.findBySymbol(subform.getString("untersucht"));
|
||||||
|
if (geneOptional.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final var reportedAffectedGenes = new ArrayList<String>();
|
||||||
|
reportedAffectedGenes.add(subform.getString("untersucht"));
|
||||||
|
|
||||||
|
// Weitere betroffene Gene aus Freitextfeld?
|
||||||
|
if (null != subform.getString("cnvbetroffenegene")) {
|
||||||
|
reportedAffectedGenes.addAll(
|
||||||
|
Arrays.stream(subform.getString("cnvbetroffenegene").split("\\s")).collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final var cnvBuilder = Cnv.builder()
|
||||||
|
.id(subform.getString("id"))
|
||||||
|
.patient(subform.getPatientReference())
|
||||||
|
.reportedAffectedGenes(
|
||||||
|
reportedAffectedGenes.stream()
|
||||||
|
.distinct()
|
||||||
|
.map(GeneUtils::findBySymbol)
|
||||||
|
.filter(Optional::isPresent)
|
||||||
|
.map(gene -> GeneUtils.toCoding(gene.get()))
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
)
|
||||||
|
.totalCopyNumber(subform.getLong("cnvtotalcn"));
|
||||||
|
|
||||||
|
geneOptional.get().getSingleChromosomeInPropertyForm().ifPresent(cnvBuilder::chromosome);
|
||||||
|
|
||||||
|
return cnvBuilder.build();
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
return resultBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -124,6 +124,8 @@ public class MtbDataMapper implements DataMapper<Mtb> {
|
|||||||
propertyCatalogue
|
propertyCatalogue
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var kpaMolekulargenetikDataMapper = new KpaMolekulargenetikDataMapper(molekulargenetikCatalogue, catalogueFactory.catalogue(MolekulargenuntersuchungCatalogue.class), propertyCatalogue);
|
||||||
|
|
||||||
var resultBuilder = Mtb.builder();
|
var resultBuilder = Mtb.builder();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -156,6 +158,11 @@ public class MtbDataMapper implements DataMapper<Mtb> {
|
|||||||
Reference.builder().id(diagnosis.getId()).type("MTBDiagnosis").build()
|
Reference.builder().id(diagnosis.getId()).type("MTBDiagnosis").build()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
// NGS Berichte
|
||||||
|
.ngsReports(
|
||||||
|
kpaMolekulargenetikDataMapper.getAllByKpaId(kpaId)
|
||||||
|
)
|
||||||
|
|
||||||
;
|
;
|
||||||
} catch (DataAccessException e) {
|
} catch (DataAccessException e) {
|
||||||
logger.error("Error while getting Mtb.", e);
|
logger.error("Error while getting Mtb.", e);
|
||||||
|
@@ -64,19 +64,4 @@ class MolekulargenetikCatalogueTest {
|
|||||||
.isEqualTo("SELECT patient.patienten_id, dk_molekulargenetik.*, prozedur.* FROM dk_molekulargenetik JOIN prozedur ON (prozedur.id = dk_molekulargenetik.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND prozedur.id = ?");
|
.isEqualTo("SELECT patient.patienten_id, dk_molekulargenetik.*, prozedur.* FROM dk_molekulargenetik JOIN prozedur ON (prozedur.id = dk_molekulargenetik.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND prozedur.id = ?");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldUseCorrectSubformQuery(@Mock Map<String, Object> resultSet) {
|
|
||||||
doAnswer(invocationOnMock -> List.of(resultSet))
|
|
||||||
.when(jdbcTemplate)
|
|
||||||
.queryForList(anyString(), anyInt());
|
|
||||||
|
|
||||||
this.catalogue.getAllByParentId(1);
|
|
||||||
|
|
||||||
var captor = ArgumentCaptor.forClass(String.class);
|
|
||||||
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
|
||||||
|
|
||||||
assertThat(captor.getValue())
|
|
||||||
.isEqualTo("SELECT patient.patienten_id, dk_molekulargenetik.*, prozedur.* FROM dk_molekulargenetik JOIN prozedur ON (prozedur.id = dk_molekulargenetik.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND hauptprozedur_id = ?");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 MolekulargenuntersuchungCatalogueTest {
|
||||||
|
|
||||||
|
JdbcTemplate jdbcTemplate;
|
||||||
|
MolekulargenuntersuchungCatalogue catalogue;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp(@Mock JdbcTemplate jdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
this.catalogue = MolekulargenuntersuchungCatalogue.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 patient.patienten_id, dk_molekulargenuntersuchung.*, prozedur.* FROM dk_molekulargenuntersuchung JOIN prozedur ON (prozedur.id = dk_molekulargenuntersuchung.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND prozedur.id = ?");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldUseCorrectSubformQuery(@Mock Map<String, Object> resultSet) {
|
||||||
|
doAnswer(invocationOnMock -> List.of(resultSet))
|
||||||
|
.when(jdbcTemplate)
|
||||||
|
.queryForList(anyString(), anyInt());
|
||||||
|
|
||||||
|
this.catalogue.getAllByParentId(1);
|
||||||
|
|
||||||
|
var captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
verify(this.jdbcTemplate).queryForList(captor.capture(), anyInt());
|
||||||
|
|
||||||
|
assertThat(captor.getValue())
|
||||||
|
.isEqualTo("SELECT patient.patienten_id, dk_molekulargenuntersuchung.*, prozedur.* FROM dk_molekulargenuntersuchung JOIN prozedur ON (prozedur.id = dk_molekulargenuntersuchung.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND hauptprozedur_id = ?");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user