From 8ef93e3f06f40b739adffca79156ecd1cbf3c504 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Tue, 28 Oct 2025 09:38:30 +0100 Subject: feat: do not convert MII consent again (#169) --- .../etl/processor/consent/GicsConsentService.java | 18 +++++++++++++++ .../processor/consent/GicsConsentServiceTest.java | 26 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java b/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java index a1a613e..9b785ab 100644 --- a/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java +++ b/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java @@ -307,6 +307,11 @@ public class GicsConsentService implements IConsentService { Bundle.BundleEntryComponent bundleEntryComponent = gIcsResultBundle.getEntry().getFirst(); var consentAsOne = (Consent) bundleEntryComponent.getResource(); + + if (isMiiConsent(consentAsOne)) { + return gIcsResultBundle; + } + if (consentAsOne.getPolicy().stream().noneMatch(p -> p.getUri().equals(BROAD_CONSENT_POLICY))) { consentAsOne.addPolicy(new Consent.ConsentPolicyComponent().setUri(BROAD_CONSENT_POLICY)); } @@ -347,6 +352,19 @@ public class GicsConsentService implements IConsentService { return gIcsResultBundle; } + private static boolean isMiiConsent(Consent consent) { + for (var category : consent.getCategory()) { + for (var categoryCoding : category.getCoding()) { + if ("https://www.medizininformatik-initiative.de/fhir/modul-consent/CodeSystem/mii-cs-consent-consent_category" + .equals(categoryCoding.getSystem()) + && "2.16.840.1.113883.3.1937.777.24.2.184".equals(categoryCoding.getCode())) { + return true; + } + } + } + return false; + } + protected Bundle anonymizeBroadConsent(Bundle bundle) { Bundle.BundleEntryComponent bundleEntryComponent = bundle.getEntry().getFirst(); hashBundleEntry(bundleEntryComponent); diff --git a/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java b/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java index 40fdc52..bbc53be 100644 --- a/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java +++ b/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java @@ -210,4 +210,30 @@ class GicsConsentServiceTest { var actual = gicsConsentService.anonymizeBroadConsent(miiConsentBundle); assertThat(fhirJsonParser.encodeToString(actual)).doesNotContain(currentPatientId); } + + @Test + void miiBroadConsentShouldNotBeConvertedAgain() throws Exception { + var fhirJsonParser = FhirContext.forR4().newJsonParser(); + fhirJsonParser.setPrettyPrint(true); + + var gicsInputStream = + Objects.requireNonNull( + this.getClass() + .getClassLoader() + .getResourceAsStream("fake_broadConsent_mii_response_permit.json")); + var gicsConsentBundle = + (Bundle) + fhirJsonParser.parseResource(IOUtils.toString(gicsInputStream, StandardCharsets.UTF_8)); + + var miiInputStream = + Objects.requireNonNull( + this.getClass() + .getClassLoader() + .getResourceAsStream("fake_broadConsent_mii_response_permit.json")); + var miiConsent = IOUtils.toString(miiInputStream, StandardCharsets.UTF_8); + + var actual = gicsConsentService.convertGicsResultToMiiBroadConsent(gicsConsentBundle); + + assertThat(fhirJsonParser.encodeToString(actual)).isEqualTo(miiConsent); + } } -- cgit v1.2.3