use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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);
}
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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();
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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());
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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;
}
Aggregations