Search in sources :

Example 1 with AttachmentDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.AttachmentDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class PersonalCharacteristicsService method retrieveDerivedFrom.

public AttachmentDto retrieveDerivedFrom(String id) {
    Observation obs = observationRepository.getWithDocumentReference(id);
    if (obs == null) {
        throw new ResourceNotFoundException(new IdType(Observation.class.getSimpleName(), id));
    }
    IBaseResource ref = obs.getDerivedFromFirstRep().getResource();
    if (ref == null || !(ref instanceof DocumentReference)) {
        throw new IllegalStateException("Observation with id " + id + " does not have a derived-from field set to a Document Reference resource.");
    }
    DocumentReference docRef = (DocumentReference) ref;
    Attachment attachment = docRef.getContentFirstRep().getAttachment();
    if (attachment == null) {
        throw new IllegalStateException("DocumentReference with id " + docRef.getIdElement().getIdPart() + " does not have an attachment.");
    }
    return AttachmentDto.builder().content(attachment.getData()).contentType(attachment.getContentType()).title(attachment.getTitle()).build();
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) Attachment(org.hl7.fhir.r4.model.Attachment) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) IdType(org.hl7.fhir.r4.model.IdType)

Example 2 with AttachmentDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.AttachmentDto 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)

Aggregations

ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 Attachment (org.hl7.fhir.r4.model.Attachment)2 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 Consent (org.hl7.fhir.r4.model.Consent)1 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)1 IdType (org.hl7.fhir.r4.model.IdType)1 Observation (org.hl7.fhir.r4.model.Observation)1