Search in sources :

Example 1 with Consent

use of org.hl7.fhir.r4.model.Consent in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskReferenceResourcesLoader method processServiceRequestReferences.

private void processServiceRequestReferences(IGenericClient ehrClient, TaskReferencesHolder taskReferencesHolder, String identifierSystem, Bundle bundle) {
    ServiceRequestReferenceResolver referenceResolver = new ServiceRequestReferenceResolver(taskReferencesHolder.getServiceRequest(), identifierSystem);
    // Load local references in one transaction
    referenceResolver.setLocalResources(resourceLoader.getResourcesBySystem(openCpClient, identifierSystem, referenceResolver.getLocalReferences()));
    // Load EHR references in one transaction
    referenceResolver.setExternalResources(resourceLoader.getResources(ehrClient, referenceResolver.getExternalReferences()));
    Map<String, Consumer<IIdType>> referenceConsumers = new HashMap<>();
    referenceConsumers.put(Patient.class.getSimpleName(), new PatientReferenceConsumer(taskReferencesHolder.getPatient().getIdElement().getIdPart()));
    for (Reference serviceRequestRef : referenceResolver.getConsentsRef()) {
        IIdType serviceRequestEl = serviceRequestRef.getReferenceElement();
        Consent consent = referenceResolver.getConsent(serviceRequestEl);
        // Update links only for new conditions
        if (referenceResolver.createConsent(serviceRequestEl)) {
            updateResourceRefs(consent, ehrClient.getServerBase(), referenceConsumers);
            // Create CP Condition resource
            bundle.addEntry(FhirUtil.createPostEntry(consent));
        }
        // Link CP ServiceRequest reference with Consent
        serviceRequestEl.setParts(null, serviceRequestEl.getResourceType(), consent.getIdElement().getIdPart(), null);
        serviceRequestRef.setReferenceElement(serviceRequestEl);
    }
    Map<String, Condition> processedConditions = new HashMap<>();
    for (Reference serviceRequestRef : referenceResolver.getConditionsRefs()) {
        IIdType serviceRequestEl = serviceRequestRef.getReferenceElement();
        Condition condition = referenceResolver.getCondition(serviceRequestEl);
        // Update links only for new conditions
        if (referenceResolver.createCondition(serviceRequestEl)) {
            updateResourceRefs(condition, ehrClient.getServerBase(), referenceConsumers);
            // Create CP Condition resource
            bundle.addEntry(FhirUtil.createPostEntry(condition));
        }
        // Link CP ServiceRequest reference with Condition
        serviceRequestEl.setParts(null, serviceRequestEl.getResourceType(), condition.getIdElement().getIdPart(), null);
        serviceRequestRef.setReferenceElement(serviceRequestEl);
        processedConditions.put(condition.getIdentifierFirstRep().getValue(), condition);
    }
    referenceConsumers.put(Condition.class.getSimpleName(), new ConditionReferenceConsumer(ehrClient.getServerBase(), processedConditions));
    for (Reference serviceRequestRef : referenceResolver.getGoalsRefs()) {
        IIdType serviceRequestEl = serviceRequestRef.getReferenceElement();
        Goal goal = referenceResolver.getGoal(serviceRequestEl);
        // Update links only for new goals
        if (referenceResolver.createGoal(serviceRequestEl)) {
            updateResourceRefs(goal, ehrClient.getServerBase(), referenceConsumers);
            // Create CP Goal resource
            bundle.addEntry(FhirUtil.createPostEntry(goal));
        }
        // Link CP ServiceRequest reference with Gaol
        serviceRequestEl.setParts(null, serviceRequestEl.getResourceType(), goal.getIdElement().getIdPart(), null);
        serviceRequestRef.setReferenceElement(serviceRequestEl);
    }
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) HashMap(java.util.HashMap) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.hl7.fhir.r4.model.Patient) Goal(org.hl7.fhir.r4.model.Goal) Consumer(java.util.function.Consumer) Consent(org.hl7.fhir.r4.model.Consent) IIdType(org.hl7.fhir.instance.model.api.IIdType)

Example 2 with Consent

use of org.hl7.fhir.r4.model.Consent in project Gravity-SDOH-Exchange-RI by FHIR.

the class ConsentService method retrieveAttachmentInfo.

public AttachmentDto retrieveAttachmentInfo(String id) {
    Optional<Consent> foundConsent = consentRepository.find(id);
    if (!foundConsent.isPresent()) {
        throw new ResourceNotFoundException(String.format("Consent with id '%s' was not found.", id));
    }
    Consent consent = foundConsent.get();
    Attachment attachment = consent.getSourceAttachment();
    return AttachmentDto.builder().content(attachment.getData()).contentType(attachment.getContentType()).title(attachment.getTitle()).build();
}
Also used : Consent(org.hl7.fhir.r4.model.Consent) Attachment(org.hl7.fhir.r4.model.Attachment) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)

Example 3 with Consent

use of org.hl7.fhir.r4.model.Consent 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 4 with Consent

use of org.hl7.fhir.r4.model.Consent in project Gravity-SDOH-Exchange-RI by FHIR.

the class ConsentService method listBaseConsentsInfo.

public List<BaseConsentDto> listBaseConsentsInfo() {
    Bundle bundle = consentRepository.findAllByPatient(SmartOnFhirContext.get().getPatient());
    List<Consent> consentResources = FhirUtil.getFromBundle(bundle, Consent.class);
    return consentResources.stream().map(consent -> new BaseConsentDto(consent.getIdElement().getIdPart(), consent.getSourceAttachment().getTitle())).collect(Collectors.toList());
}
Also used : BaseConsentDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.BaseConsentDto) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Consent(org.hl7.fhir.r4.model.Consent) Autowired(org.springframework.beans.factory.annotation.Autowired) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) AttachmentDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.AttachmentDto) Reference(org.hl7.fhir.r4.model.Reference) Attachment(org.hl7.fhir.r4.model.Attachment) Service(org.springframework.stereotype.Service) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Patient(org.hl7.fhir.r4.model.Patient) UserDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.UserDto) ConsentToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.ConsentToDtoConverter) ConsentRepository(org.hl7.gravity.refimpl.sdohexchange.dao.impl.ConsentRepository) ConsentDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ConsentDto) Collectors(java.util.stream.Collectors) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) ConsentCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.ConsentCreateException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ConsentPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ConsentPrepareBundleFactory) CreateConsentFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.resource.CreateConsentFactory) SmartOnFhirContext(com.healthlx.smartonfhir.core.SmartOnFhirContext) MultipartFile(org.springframework.web.multipart.MultipartFile) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Consent(org.hl7.fhir.r4.model.Consent) Bundle(org.hl7.fhir.r4.model.Bundle) BaseConsentDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.BaseConsentDto)

Example 5 with Consent

use of org.hl7.fhir.r4.model.Consent in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskBundleFactory method createConsent.

protected Consent createConsent() {
    Consent consent = new Consent();
    consent.getMeta().addProfile(SDOHProfiles.CONSENT);
    consent.setId(IdType.newRandomUuid());
    consent.setStatus(Consent.ConsentState.ACTIVE);
    consent.setDateTimeElement(DateTimeType.now());
    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(getPatientReference());
    ConsentPolicy consentPolicy = ConsentPolicy.HIPAAAUTH;
    consent.getPolicyRule().addCoding(new Coding(consentPolicy.getSystem(), consentPolicy.toCode(), consentPolicy.getDisplay()));
    V3RoleClass roleClass = V3RoleClass.PAT;
    consent.getProvision().addActor().setReference(getPatientReference()).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()));
    return consent;
}
Also used : ConsentScope(org.hl7.fhir.r4.model.codesystems.ConsentScope) 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) ConsentAction(org.hl7.fhir.r4.model.codesystems.ConsentAction) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

Consent (org.hl7.fhir.r4.model.Consent)15 Consent (org.hl7.fhir.dstu3.model.Consent)8 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)8 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)7 Test (org.junit.jupiter.api.Test)7 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 List (java.util.List)5 Bundle (org.hl7.fhir.r4.model.Bundle)5 Reference (org.hl7.fhir.r4.model.Reference)5 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)4 ConsentEntity (gov.cms.dpc.common.consent.entities.ConsentEntity)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 IIdType (org.hl7.fhir.instance.model.api.IIdType)4 ConsentCreateException (org.hl7.gravity.refimpl.sdohexchange.exception.ConsentCreateException)4 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3 SmartOnFhirContext (com.healthlx.smartonfhir.core.SmartOnFhirContext)2 DPCIdentifierSystem (gov.cms.dpc.fhir.DPCIdentifierSystem)2 FHIR (gov.cms.dpc.fhir.annotations.FHIR)2 UnitOfWork (io.dropwizard.hibernate.UnitOfWork)2