From fa24991c9912b00180b435bb40ca21f058d00ed1 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sat, 12 Jul 2025 13:12:12 +0200 Subject: [PATCH] feat: add project model consent --- README.md | 1 + .../datacatalogues/ConsentMvCatalogue.java | 46 ++++++ .../ConsentMvVerlaufCatalogue.java | 46 ++++++ .../mapper/ConsentMvDataMapper.java | 138 ++++++++++++++++++ .../ConsentMvCatalogueTest.java | 67 +++++++++ .../ConsentMvVerlaufCatalogueTest.java | 83 +++++++++++ .../mapper/ConsentMvDataMapperTest.java | 124 ++++++++++++++++ 7 files changed, 505 insertions(+) create mode 100644 src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvCatalogue.java create mode 100644 src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvVerlaufCatalogue.java create mode 100644 src/main/java/dev/pcvolkmer/onco/datamapper/mapper/ConsentMvDataMapper.java create mode 100644 src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvCatalogueTest.java create mode 100644 src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvVerlaufCatalogueTest.java create mode 100644 src/test/java/dev/pcvolkmer/onco/datamapper/mapper/ConsentMvDataMapperTest.java diff --git a/README.md b/README.md index fd7bd43..b18e759 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Um Mithilfe wird gebeten. | DNPM-Datenmodell 2.1 - Bereich | Status | Anmerkung | |----------------------------------|--------|---------------------------------------------------------------------------------------| + | MV Metadaten | ⛅ | MV Consent anhand DNPM-Formular. Kein Broad Consent | Patient | ✅ | Verwendet Patienten-ID, nicht Datenbank-ID. Keine Managing Site | | Episoden | ✅ | | | Diagnosen | ✅ | Entsprechend Formularaufbau nur Diagnose der aktuellen Episode | diff --git a/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvCatalogue.java b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvCatalogue.java new file mode 100644 index 0000000..22b976e --- /dev/null +++ b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvCatalogue.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_dnpm_consentmv' + * + * @author Paul-Christian Volkmer + * @since 0.1 + */ +public class ConsentMvCatalogue extends AbstractDataCatalogue { + + private ConsentMvCatalogue(JdbcTemplate jdbcTemplate) { + super(jdbcTemplate); + } + + @Override + protected String getTableName() { + return "dk_dnpm_consentmv"; + } + + public static ConsentMvCatalogue create(JdbcTemplate jdbcTemplate) { + return new ConsentMvCatalogue(jdbcTemplate); + } + +} diff --git a/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvVerlaufCatalogue.java b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvVerlaufCatalogue.java new file mode 100644 index 0000000..68dc32c --- /dev/null +++ b/src/main/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvVerlaufCatalogue.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_dnpm_uf_consentmvverlauf' + * + * @author Paul-Christian Volkmer + * @since 0.1 + */ +public class ConsentMvVerlaufCatalogue extends AbstractSubformDataCatalogue { + + private ConsentMvVerlaufCatalogue(JdbcTemplate jdbcTemplate) { + super(jdbcTemplate); + } + + @Override + protected String getTableName() { + return "dk_dnpm_uf_consentmvverlauf"; + } + + public static ConsentMvVerlaufCatalogue create(JdbcTemplate jdbcTemplate) { + return new ConsentMvVerlaufCatalogue(jdbcTemplate); + } + +} diff --git a/src/main/java/dev/pcvolkmer/onco/datamapper/mapper/ConsentMvDataMapper.java b/src/main/java/dev/pcvolkmer/onco/datamapper/mapper/ConsentMvDataMapper.java new file mode 100644 index 0000000..3ae1758 --- /dev/null +++ b/src/main/java/dev/pcvolkmer/onco/datamapper/mapper/ConsentMvDataMapper.java @@ -0,0 +1,138 @@ +/* + * 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.mapper; + +import dev.pcvolkmer.mv64e.mtb.ConsentProvision; +import dev.pcvolkmer.mv64e.mtb.ModelProjectConsent; +import dev.pcvolkmer.mv64e.mtb.ModelProjectConsentPurpose; +import dev.pcvolkmer.mv64e.mtb.Provision; +import dev.pcvolkmer.onco.datamapper.ResultSet; +import dev.pcvolkmer.onco.datamapper.datacatalogues.ConsentMvCatalogue; +import dev.pcvolkmer.onco.datamapper.datacatalogues.ConsentMvVerlaufCatalogue; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Mapper class to load and map diagnosis data from database table 'dk_dnpm_consentmv' + * + * @author Paul-Christian Volkmer + * @since 0.1 + */ +public class ConsentMvDataMapper implements DataMapper { + + private final ConsentMvCatalogue catalogue; + private final ConsentMvVerlaufCatalogue consentMvVerlaufCatalogue; + + public ConsentMvDataMapper( + final ConsentMvCatalogue catalogue, + final ConsentMvVerlaufCatalogue consentMvVerlaufCatalogue + ) { + this.catalogue = catalogue; + this.consentMvVerlaufCatalogue = consentMvVerlaufCatalogue; + } + + /** + * Loads and maps consent data using the consent form database id + * + * @param id The database id of the procedure data set + * @return The loaded Consent data + */ + @Override + public ModelProjectConsent getById(int id) { + var data = catalogue.getById(id); + + var builder = ModelProjectConsent.builder(); + builder + .date(data.getDate("date")) + .version(getLatestVersion(id)) + .provisions(getProvisions(data)) + ; + return builder.build(); + } + + private String getLatestVersion(int id) { + return consentMvVerlaufCatalogue.getAllByParentId(id).stream() + .sorted((rs1, rs2) -> rs2.getDate("date").compareTo(rs1.getDate("date"))) + .map(resultSet -> resultSet.getString("version")) + .findFirst() + .orElse(""); + } + + private List getProvisions(final ResultSet resultSet) { + var result = new ArrayList(); + var date = resultSet.getDate("date"); + + if (ConsentProvision.PERMIT.toValue().equals(resultSet.getString("sequencing"))) { + result.add( + Provision.builder() + .date(date) + .purpose(ModelProjectConsentPurpose.SEQUENCING).type(ConsentProvision.PERMIT) + .build() + ); + } else { + result.add( + Provision.builder() + .date(date) + .purpose(ModelProjectConsentPurpose.SEQUENCING).type(ConsentProvision.DENY) + .build() + ); + } + + if (ConsentProvision.PERMIT.toValue().equals(resultSet.getString("caseidentification"))) { + result.add( + Provision.builder() + .date(date) + .purpose(ModelProjectConsentPurpose.CASE_IDENTIFICATION).type(ConsentProvision.PERMIT) + .build() + ); + } else { + result.add( + Provision.builder() + .date(date) + .purpose(ModelProjectConsentPurpose.CASE_IDENTIFICATION).type(ConsentProvision.DENY) + .build() + ); + } + + if (ConsentProvision.PERMIT.toValue().equals(resultSet.getString("reidentification"))) { + result.add( + Provision.builder() + .date(date) + .purpose(ModelProjectConsentPurpose.REIDENTIFICATION).type(ConsentProvision.PERMIT) + .build() + ); + } else { + result.add( + Provision.builder() + .date(date) + .purpose(ModelProjectConsentPurpose.REIDENTIFICATION).type(ConsentProvision.DENY) + .build() + ); + } + + return result; + + } + +} diff --git a/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvCatalogueTest.java b/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvCatalogueTest.java new file mode 100644 index 0000000..7392ce8 --- /dev/null +++ b/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvCatalogueTest.java @@ -0,0 +1,67 @@ +/* + * 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.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 ConsentMvCatalogueTest { + + JdbcTemplate jdbcTemplate; + ConsentMvCatalogue catalogue; + + @BeforeEach + void setUp(@Mock JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + this.catalogue = ConsentMvCatalogue.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_dnpm_consentmv.*, prozedur.patient_id, prozedur.hauptprozedur_id FROM dk_dnpm_consentmv JOIN prozedur ON (prozedur.id = dk_dnpm_consentmv.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND prozedur.id = ?"); + } + +} diff --git a/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvVerlaufCatalogueTest.java b/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvVerlaufCatalogueTest.java new file mode 100644 index 0000000..48e132b --- /dev/null +++ b/src/test/java/dev/pcvolkmer/onco/datamapper/datacatalogues/ConsentMvVerlaufCatalogueTest.java @@ -0,0 +1,83 @@ +/* + * 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 ConsentMvVerlaufCatalogueTest { + + JdbcTemplate jdbcTemplate; + ConsentMvVerlaufCatalogue catalogue; + + @BeforeEach + void setUp(@Mock JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + this.catalogue = ConsentMvVerlaufCatalogue.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_dnpm_uf_consentmvverlauf.*, prozedur.patient_id, prozedur.hauptprozedur_id FROM dk_dnpm_uf_consentmvverlauf JOIN prozedur ON (prozedur.id = dk_dnpm_uf_consentmvverlauf.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND prozedur.id = ?"); + } + + @Test + void shouldUseCorrectSubformQuery(@Mock Map 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_dnpm_uf_consentmvverlauf.*, prozedur.patient_id, prozedur.hauptprozedur_id FROM dk_dnpm_uf_consentmvverlauf JOIN prozedur ON (prozedur.id = dk_dnpm_uf_consentmvverlauf.id) JOIN patient ON (patient.id = prozedur.patient_id) WHERE geloescht = 0 AND hauptprozedur_id = ?"); + } + +} diff --git a/src/test/java/dev/pcvolkmer/onco/datamapper/mapper/ConsentMvDataMapperTest.java b/src/test/java/dev/pcvolkmer/onco/datamapper/mapper/ConsentMvDataMapperTest.java new file mode 100644 index 0000000..7885031 --- /dev/null +++ b/src/test/java/dev/pcvolkmer/onco/datamapper/mapper/ConsentMvDataMapperTest.java @@ -0,0 +1,124 @@ +/* + * 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.mapper; + +import dev.pcvolkmer.mv64e.mtb.ConsentProvision; +import dev.pcvolkmer.mv64e.mtb.ModelProjectConsent; +import dev.pcvolkmer.mv64e.mtb.ModelProjectConsentPurpose; +import dev.pcvolkmer.mv64e.mtb.Provision; +import dev.pcvolkmer.onco.datamapper.ResultSet; +import dev.pcvolkmer.onco.datamapper.datacatalogues.ConsentMvCatalogue; +import dev.pcvolkmer.onco.datamapper.datacatalogues.ConsentMvVerlaufCatalogue; +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 javax.sql.DataSource; +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.Mockito.doAnswer; + +@ExtendWith(MockitoExtension.class) +class ConsentMvDataMapperTest { + + ConsentMvCatalogue catalogue; + ConsentMvVerlaufCatalogue consentMvVerlaufCatalogue; + ConsentMvDataMapper dataMapper; + + @BeforeEach + void setUp( + @Mock ConsentMvCatalogue catalogue, + @Mock ConsentMvVerlaufCatalogue consentMvVerlaufCatalogue + ) { + this.catalogue = catalogue; + this.consentMvVerlaufCatalogue = consentMvVerlaufCatalogue; + this.dataMapper = new ConsentMvDataMapper(catalogue, consentMvVerlaufCatalogue); + } + + @Test + void shouldCreateDataMapper(@Mock DataSource dataSource) { + assertThat(MtbDataMapper.create(dataSource)).isNotNull(); + } + + @Test + void shouldCreateConsent() { + doAnswer(invocationOnMock -> + ResultSet.from( + Map.of( + "id", "1", + "date", new java.sql.Date(Date.from(Instant.parse("2025-07-12T12:00:00Z")).getTime()), + "sequencing", "permit", + "caseidentification", "deny", + "reidentification", "deny" + ) + ) + ) + .when(catalogue) + .getById(anyInt()); + + doAnswer(invocationOnMock -> + List.of( + ResultSet.from( + Map.of( + "id", "1", + "date", new java.sql.Date(Date.from(Instant.parse("2025-07-12T12:00:00Z")).getTime()), + "version", "01" + ) + ) + ) + ) + .when(consentMvVerlaufCatalogue) + .getAllByParentId(anyInt()); + + var actual = this.dataMapper.getById(1); + assertThat(actual).isInstanceOf(ModelProjectConsent.class); + assertThat(actual.getDate()).isEqualTo(Date.from(Instant.parse("2025-07-12T00:00:00Z"))); + assertThat(actual.getVersion()).isEqualTo("01"); + assertThat(actual.getProvisions()).hasSize(3); + assertThat(actual.getProvisions()).containsAll( + List.of( + Provision.builder() + .date(Date.from(Instant.parse("2025-07-12T00:00:00Z"))) + .purpose(ModelProjectConsentPurpose.SEQUENCING) + .type(ConsentProvision.PERMIT) + .build(), + Provision.builder() + .date(Date.from(Instant.parse("2025-07-12T00:00:00Z"))) + .purpose(ModelProjectConsentPurpose.CASE_IDENTIFICATION) + .type(ConsentProvision.DENY) + .build(), + Provision.builder() + .date(Date.from(Instant.parse("2025-07-12T00:00:00Z"))) + .purpose(ModelProjectConsentPurpose.REIDENTIFICATION) + .type(ConsentProvision.DENY) + .build() + ) + ); + } + +}