Search in sources :

Example 1 with ConsentCreateException

use of org.hl7.gravity.refimpl.sdohexchange.exception.ConsentCreateException in project Gravity-SDOH-Exchange-RI by FHIR.

the class ConsentService method retrieveOrganization.

private Reference retrieveOrganization(UserDto userDto) {
    Bundle bundle = new ConsentPrepareBundleFactory(userDto.getId()).createPrepareBundle();
    Bundle consentResponseBundle = ehrClient.transaction().withBundle(bundle).execute();
    Bundle consentBundle = FhirUtil.getFirstFromBundle(consentResponseBundle, Bundle.class);
    PractitionerRole practitionerRole = FhirUtil.getFirstFromBundle(consentBundle, PractitionerRole.class);
    Reference organization = practitionerRole.getOrganization();
    if (organization == null) {
        throw new ConsentCreateException("No Organization found for Consent creation.");
    }
    return organization;
}
Also used : ConsentCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.ConsentCreateException) Bundle(org.hl7.fhir.r4.model.Bundle) Reference(org.hl7.fhir.r4.model.Reference) ConsentPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ConsentPrepareBundleFactory) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole)

Example 2 with ConsentCreateException

use of org.hl7.gravity.refimpl.sdohexchange.exception.ConsentCreateException in project Gravity-SDOH-Exchange-RI by FHIR.

the class CreateConsentFactory method createConsent.

public Consent createConsent() {
    Consent consent = new Consent();
    consent.getSourceAttachment().setTitle(name);
    try {
        consent.getSourceAttachment().setData(attachment.getBytes());
    } catch (IOException e) {
        throw new ConsentCreateException("Consent attachment cannot be read.");
    }
    consent.getSourceAttachment().setContentType(MediaType.APPLICATION_PDF_VALUE);
    consent.setId(IdType.newRandomUuid());
    consent.setStatus(Consent.ConsentState.ACTIVE);
    consent.setDateTimeElement(DateTimeType.now());
    consent.getMeta().addProfile(SDOHProfiles.CONSENT);
    ConsentScope consentScope = ConsentScope.PATIENTPRIVACY;
    consent.getScope().addCoding(new Coding(consentScope.getSystem(), consentScope.toCode(), consentScope.getDisplay()));
    V3ActCode actCode = V3ActCode.IDSCL;
    consent.addCategory(new CodeableConcept().addCoding(new Coding(actCode.getSystem(), actCode.toCode(), actCode.getDisplay())));
    consent.setPatient(patient);
    ConsentPolicy consentPolicy = ConsentPolicy.HIPAAAUTH;
    consent.getPolicyRule().addCoding(new Coding(consentPolicy.getSystem(), consentPolicy.toCode(), consentPolicy.getDisplay()));
    V3RoleClass roleClass = V3RoleClass.PAT;
    consent.getProvision().addActor().setReference(patient).getRole().addCoding(new Coding(roleClass.getSystem(), roleClass.toCode(), roleClass.getDisplay()));
    ConsentAction consentAction = ConsentAction.DISCLOSE;
    consent.getProvision().addAction().getCoding().add(new Coding(consentAction.getSystem(), consentAction.toCode(), consentAction.getDisplay()));
    consent.getOrganization().add(organization);
    return consent;
}
Also used : ConsentScope(org.hl7.fhir.r4.model.codesystems.ConsentScope) ConsentCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.ConsentCreateException) V3ActCode(org.hl7.fhir.r4.model.codesystems.V3ActCode) Consent(org.hl7.fhir.r4.model.Consent) Coding(org.hl7.fhir.r4.model.Coding) V3RoleClass(org.hl7.fhir.r4.model.codesystems.V3RoleClass) ConsentPolicy(org.hl7.fhir.r4.model.codesystems.ConsentPolicy) IOException(java.io.IOException) ConsentAction(org.hl7.fhir.r4.model.codesystems.ConsentAction) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

ConsentCreateException (org.hl7.gravity.refimpl.sdohexchange.exception.ConsentCreateException)2 IOException (java.io.IOException)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)1 Coding (org.hl7.fhir.r4.model.Coding)1 Consent (org.hl7.fhir.r4.model.Consent)1 PractitionerRole (org.hl7.fhir.r4.model.PractitionerRole)1 Reference (org.hl7.fhir.r4.model.Reference)1 ConsentAction (org.hl7.fhir.r4.model.codesystems.ConsentAction)1 ConsentPolicy (org.hl7.fhir.r4.model.codesystems.ConsentPolicy)1 ConsentScope (org.hl7.fhir.r4.model.codesystems.ConsentScope)1 V3ActCode (org.hl7.fhir.r4.model.codesystems.V3ActCode)1 V3RoleClass (org.hl7.fhir.r4.model.codesystems.V3RoleClass)1 ConsentPrepareBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ConsentPrepareBundleFactory)1