From 0c14eefe6eb2e3b7567ce06b3118b54e1618058b Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 4 Dec 2025 16:02:36 +0100 Subject: feat: check MII broad consent (#213) --- .../consent/GicsGetBroadConsentService.java | 5 ++ .../consent/MiiBroadConsentEvaluator.java | 78 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/main/java/dev/dnpm/etl/processor/consent/MiiBroadConsentEvaluator.java (limited to 'src/main/java') diff --git a/src/main/java/dev/dnpm/etl/processor/consent/GicsGetBroadConsentService.java b/src/main/java/dev/dnpm/etl/processor/consent/GicsGetBroadConsentService.java index 246d84c..d657306 100644 --- a/src/main/java/dev/dnpm/etl/processor/consent/GicsGetBroadConsentService.java +++ b/src/main/java/dev/dnpm/etl/processor/consent/GicsGetBroadConsentService.java @@ -131,4 +131,9 @@ public class GicsGetBroadConsentService extends AbstractConsentService { return null; } } + + @Override + protected TtpConsentStatus evaluateConsentResponse(@Nullable String consentStatusResponse) { + return MiiBroadConsentEvaluator.evaluate(this.fhirContext, consentStatusResponse); + } } diff --git a/src/main/java/dev/dnpm/etl/processor/consent/MiiBroadConsentEvaluator.java b/src/main/java/dev/dnpm/etl/processor/consent/MiiBroadConsentEvaluator.java new file mode 100644 index 0000000..0640142 --- /dev/null +++ b/src/main/java/dev/dnpm/etl/processor/consent/MiiBroadConsentEvaluator.java @@ -0,0 +1,78 @@ +package dev.dnpm.etl.processor.consent; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.parser.DataFormatException; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Consent; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Evaluates MII Broad Consent + * + * @since 0.12 + */ +@NullMarked +public class MiiBroadConsentEvaluator { + + private static final Logger log = LoggerFactory.getLogger(MiiBroadConsentEvaluator.class); + + /** + * Evaluates MII Broad Consent + * + * @param fhirContext FHIR context + * @param consentStatusResponse Nullable String containing FHIR String + * @return consent status + */ + public static TtpConsentStatus evaluate( + FhirContext fhirContext, @Nullable String consentStatusResponse) { + if (null == consentStatusResponse) { + return TtpConsentStatus.FAILED_TO_ASK; + } + try { + var response = fhirContext.newJsonParser().parseResource(consentStatusResponse); + + if (response instanceof Bundle bundle) { + Boolean mdatStoreAndProcessGiven = null; + Boolean mdatResearchUse = null; + Boolean patdatStoreAndUse = null; + for (var entry : bundle.getEntry()) { + if (entry.getResource() instanceof Consent consent) { + for (var provision : consent.getProvision().getProvision()) { + for (var code : provision.getCode()) { + for (var coding : code.getCoding()) { + if ("2.16.840.1.113883.3.1937.777.24.5.3.7".equals(coding.getCode())) { + mdatStoreAndProcessGiven = + Consent.ConsentProvisionType.PERMIT.equals(provision.getType()); + } else if ("2.16.840.1.113883.3.1937.777.24.5.3.8".equals(coding.getCode())) { + mdatResearchUse = + Consent.ConsentProvisionType.PERMIT.equals(provision.getType()); + } else if ("2.16.840.1.113883.3.1937.777.24.5.3.1".equals(coding.getCode())) { + patdatStoreAndUse = + Consent.ConsentProvisionType.PERMIT.equals(provision.getType()); + } + } + } + } + } + } + if (null != mdatStoreAndProcessGiven + && null != mdatResearchUse + && mdatStoreAndProcessGiven + && mdatResearchUse) { + return TtpConsentStatus.BROAD_CONSENT_GIVEN; + } + + if (null != patdatStoreAndUse && patdatStoreAndUse) { + return TtpConsentStatus.BROAD_CONSENT_GIVEN; + } + return TtpConsentStatus.BROAD_CONSENT_MISSING_OR_REJECTED; + } + } catch (DataFormatException dfe) { + log.error("failed to parse response to FHIR R4 resource.", dfe); + } + return TtpConsentStatus.FAILED_TO_ASK; + } +} -- cgit v1.2.3