use of org.hl7.fhir.r4.model.Consent.ConsentProvisionType.DENY 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);
}
Aggregations