Search in sources :

Example 1 with ConsentPolicyComponent

use of org.hl7.fhir.r4.model.Consent.ConsentPolicyComponent in project odm2fhir by num-codex.

the class BroadConsent method createConsent.

@SuppressWarnings("fallthrough")
private Consent createConsent(FormData formData) {
    var identifier = createIdentifier(CONSENT, formData.getItemData("miibc_consent_status"));
    var consent = (Consent) new Consent().addIdentifier(identifier).setDateTimeElement(createDateTimeType(formData.getItemData("miibc_dat_dok"))).addOrganization(getOrganizationReference()).setScope(RESEARCH).addCategory(createCodeableConcept(createCoding(LOINC, "57016-8", "Privacy policy acknowledgment Document"))).addPolicy(new ConsentPolicyComponent().setUri(POLICY)).setMeta(createMeta(GERMAN_CONSENT));
    switch(formData.getItemData("miibc_consent_status").getValue()) {
        case // agreed
        "1":
            consent.setStatus(ConsentState.ACTIVE);
            break;
        case // rejected
        "2":
            consent.setStatus(REJECTED);
            break;
        case // revoked
        "3":
            var revocationDateItem = formData.getItemData("miibc_w_dat_dok");
            switch(formData.getItemData("miibc_widerruf").getValue()) {
                case // fully revoked
                "1":
                    consent.setStatus(INACTIVE).setDateTimeElement(// revocation -> replace 'consentDate' by 'revocationDate'
                    createDateTimeType(revocationDateItem));
                    break;
                case // partly revoked
                "2":
                    // revocation -> replace 'consentDate' by 'revocationDate'
                    consent.setDateTimeElement(createDateTimeType(revocationDateItem));
                // not revoked
                case "3":
                case // unknown (REVOCATION-Status, not CONSENT-Status!)
                "4":
                    // default if not revoked
                    consent.setStatus(ConsentState.ACTIVE);
                    break;
            }
            break;
        case // unknown
        "4":
            // skip if general CONSENT-Status is 'unknown'
            return new Consent();
    }
    var mainProvisionComponent = new Consent.provisionComponent().setType(DENY);
    if (consent.getDateTime() != null) {
        mainProvisionComponent.setPeriod(new Period().setStart(consent.getDateTime()).setEnd(addYears(consent.getDateTime(), 30)));
    }
    if (ConsentState.ACTIVE == consent.getStatus()) {
        // add more Consent details only if consented/not fully revoked
        mainProvisionComponent.setProvision(ELEMENTS.stream().map(key -> "gee_" + key).map(formData::getItemData).filter(not(ItemData::isEmpty)).map(itemData -> {
            var specificAnswerItemName = itemData.getItemOID();
            var specificAnswerItemValue = itemData.getValue();
            var partProvisionComponent = new Consent.provisionComponent().addCode(createCodeableConcept(createCoding("urn:oid:" + BASE_OID, BASE_OID + "." + OIDS.get(removeStart(specificAnswerItemName, "gee_") + "_" + specificAnswerItemValue), specificAnswerItemName)));
            if (!mainProvisionComponent.getPeriod().isEmpty()) {
                var period = mainProvisionComponent.getPeriod().copy();
                if ("gee_krankenkassendaten_retro".equals(specificAnswerItemName)) {
                    period.setEnd(period.getStart()).setStart(addYears(period.getStart(), -5));
                } else if ("gee_krankenkassendaten_pro".equals(specificAnswerItemName)) {
                    period.setEnd(addYears(period.getStart(), 5));
                }
                partProvisionComponent.setPeriod(period);
            }
            switch(specificAnswerItemValue) {
                case // agreed
                "1":
                    partProvisionComponent.setType(PERMIT);
                    break;
                // rejected
                case "2":
                case // revoked
                "4":
                    partProvisionComponent.setType(DENY);
                    break;
                // unknown
                case "3":
            }
            return partProvisionComponent;
        }).collect(toList()));
    }
    return consent.setProvision(mainProvisionComponent);
}
Also used : ItemData(de.difuture.uds.odm2fhir.odm.model.ItemData) PERMIT(org.hl7.fhir.r4.model.Consent.ConsentProvisionType.PERMIT) INACTIVE(org.hl7.fhir.r4.model.Consent.ConsentState.INACTIVE) FormData(de.difuture.uds.odm2fhir.odm.model.FormData) ConsentPolicyComponent(org.hl7.fhir.r4.model.Consent.ConsentPolicyComponent) Period(org.hl7.fhir.r4.model.Period) Consent(org.hl7.fhir.r4.model.Consent) CONSENT(org.hl7.fhir.r4.model.codesystems.ResourceTypes.CONSENT) Item(de.difuture.uds.odm2fhir.fhir.mapper.Item) DomainResource(org.hl7.fhir.r4.model.DomainResource) HashMap(java.util.HashMap) LOINC(de.difuture.uds.odm2fhir.fhir.util.CommonCodeSystem.LOINC) List(java.util.List) REJECTED(org.hl7.fhir.r4.model.Consent.ConsentState.REJECTED) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) ConsentState(org.hl7.fhir.r4.model.Consent.ConsentState) GERMAN_CONSENT(de.difuture.uds.odm2fhir.fhir.util.CommonStructureDefinition.GERMAN_CONSENT) Map(java.util.Map) DateUtils.addYears(org.apache.commons.lang3.time.DateUtils.addYears) Predicate.not(java.util.function.Predicate.not) StringUtils.removeStart(org.apache.commons.lang3.StringUtils.removeStart) DENY(org.hl7.fhir.r4.model.Consent.ConsentProvisionType.DENY) ConsentPolicyComponent(org.hl7.fhir.r4.model.Consent.ConsentPolicyComponent) Consent(org.hl7.fhir.r4.model.Consent) Period(org.hl7.fhir.r4.model.Period) ItemData(de.difuture.uds.odm2fhir.odm.model.ItemData)

Aggregations

Item (de.difuture.uds.odm2fhir.fhir.mapper.Item)1 LOINC (de.difuture.uds.odm2fhir.fhir.util.CommonCodeSystem.LOINC)1 GERMAN_CONSENT (de.difuture.uds.odm2fhir.fhir.util.CommonStructureDefinition.GERMAN_CONSENT)1 FormData (de.difuture.uds.odm2fhir.odm.model.FormData)1 ItemData (de.difuture.uds.odm2fhir.odm.model.ItemData)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Predicate.not (java.util.function.Predicate.not)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 StringUtils.removeStart (org.apache.commons.lang3.StringUtils.removeStart)1 DateUtils.addYears (org.apache.commons.lang3.time.DateUtils.addYears)1 Consent (org.hl7.fhir.r4.model.Consent)1 ConsentPolicyComponent (org.hl7.fhir.r4.model.Consent.ConsentPolicyComponent)1 DENY (org.hl7.fhir.r4.model.Consent.ConsentProvisionType.DENY)1 PERMIT (org.hl7.fhir.r4.model.Consent.ConsentProvisionType.PERMIT)1 ConsentState (org.hl7.fhir.r4.model.Consent.ConsentState)1 INACTIVE (org.hl7.fhir.r4.model.Consent.ConsentState.INACTIVE)1 REJECTED (org.hl7.fhir.r4.model.Consent.ConsentState.REJECTED)1