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

feat: add project model consent

This commit is contained in:
2025-07-12 13:12:12 +02:00
parent e9ef03f791
commit fa24991c99
7 changed files with 505 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ Um Mithilfe wird gebeten.
| DNPM-Datenmodell 2.1 - Bereich | Status | Anmerkung | | 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 | | Patient | ✅ | Verwendet Patienten-ID, nicht Datenbank-ID. Keine Managing Site |
| Episoden | ✅ | | | Episoden | ✅ | |
| Diagnosen | ✅ | Entsprechend Formularaufbau nur Diagnose der aktuellen Episode | | Diagnosen | ✅ | Entsprechend Formularaufbau nur Diagnose der aktuellen Episode |

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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);
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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);
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<ModelProjectConsent> {
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<Provision> getProvisions(final ResultSet resultSet) {
var result = new ArrayList<Provision>();
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;
}
}

View File

@@ -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 <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 ConsentMvCatalogueTest {
JdbcTemplate jdbcTemplate;
ConsentMvCatalogue catalogue;
@BeforeEach
void setUp(@Mock JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
this.catalogue = ConsentMvCatalogue.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_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 = ?");
}
}

View File

@@ -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 <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.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<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_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<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_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 = ?");
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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()
)
);
}
}