Search in sources :

Example 61 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ORUMessageTest method test_oru_patient_diagReport.

// DiagnosticReports are only created from ORU messages so the test of DiagnosticReport content is included in this test module.
// Suppress warnings about too many assertions in a test.  Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
@Test
// Test the minimum scenario where the least possible segments and resource info are provided in the message
void test_oru_patient_diagReport() throws IOException {
    String hl7message = "MSH|^~\\\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|ORU^R01|MSGID000005|T|2.6\r" + "PID||45483|45483||SMITH^SUZIE^||20160813|M|||123 MAIN STREET^^SCHENECTADY^NY^12345||(123)456-7890|||||^^^T||||||||||||\r" + "OBR|1||986^IA PHIMS Stage^2.16.840.1.114222.4.3.3.5.1.2^ISO|1051-2^New Born Screening^LN|||20151009173644|||||||||||||002|||||F|||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^|||||\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Verify correct resources created
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patientResource).hasSize(1);
    List<Resource> diagnosticReport = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    assertThat(diagnosticReport).hasSize(1);
    List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    assertThat(servReqResource).hasSize(1);
    // Expecting only the above resources, no extras!
    assertThat(e).hasSize(3);
    // /////////////////////////////////////////
    // Now confirm content of the diagnosticReport because we don't have separate tests for DiagnosticReport
    // /////////////////////////////////////////
    DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(diagnosticReport.get(0), context);
    // Verify status from OBR.25
    assertThat(diag.getStatus().toCode()).isEqualTo("final");
    // Verify category from OBR.24
    assertThat(diag.getCategory()).isEmpty();
    // Verify code from OBR.4
    assertThat(diag.hasCode()).isTrue();
    List<Coding> codings = diag.getCode().getCoding();
    assertThat(codings).hasSize(1);
    Coding coding = codings.get(0);
    assertThat(coding.hasDisplay()).isTrue();
    assertThat(coding.getDisplay()).hasToString("New Born Screening");
    assertThat(coding.hasCode()).isTrue();
    assertThat(coding.getCode()).hasToString("1051-2");
    assertThat(coding.hasSystem()).isTrue();
    assertThat(coding.getSystem()).hasToString("http://loinc.org");
    // Verify encounter reference
    assertThat(diag.getEncounter().isEmpty()).isTrue();
    // Verify subject reference
    assertThat(diag.getSubject().isEmpty()).isFalse();
    // Verify effectiveDateTime from OBR.7 and OBR.8
    // This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
    assertThat(diag.getEffectiveDateTimeType().asStringValue()).isEqualTo("2015-10-09T17:36:44+08:00");
    // Verify issued from OBR.22
    assertThat(diag.getIssued()).isNull();
    // Verify resultsInterpreter from OBR.32
    assertThat(diag.getResultsInterpreter()).isEmpty();
    // Verify basedOn is ref to the ServiceRequest created for ORC or OBR
    assertThat(diag.getBasedOn()).hasSize(1);
    assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
    // Verify specimen reference
    assertThat(diag.getSpecimen()).isEmpty();
    // Verify result reference
    assertThat(diag.getResult()).isEmpty();
    // Verify presentedForm from OBX of type TX - In this case no attachments created since there are no OBX with type TX
    List<Attachment> attachments = diag.getPresentedForm();
    Assertions.assertEquals(0, attachments.size(), "Unexpected number of attachments");
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) Attachment(org.hl7.fhir.r4.model.Attachment) Test(org.junit.jupiter.api.Test)

Example 62 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project fhir-bridge by ehrbase.

the class DocumentReferenceProcessor method process.

@Override
public void process(Exchange exchange) throws Exception {
    DocumentReference documentReference = exchange.getIn().getMandatoryBody(DocumentReference.class);
    Attachment attachment = documentReference.getContentFirstRep().getAttachment();
    ObjectWriteResponse response = minioService.uploadObject(new ByteArrayInputStream(attachment.getData()), attachment.getContentType());
    if (!attachment.hasSize()) {
        attachment.setSize(attachment.getData().length);
    }
    attachment.setUrl(minioService.getObjectUrl(response.object()));
    attachment.setData(null);
    exchange.getMessage().setHeader(CamelConstants.MINIO_OBJECT, response.object());
    MethodOutcome outcome = new MethodOutcome().setResource(documentReference);
    exchange.setProperty(CamelConstants.OUTCOME, outcome);
}
Also used : ObjectWriteResponse(io.minio.ObjectWriteResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) Attachment(org.hl7.fhir.r4.model.Attachment) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) DocumentReference(org.hl7.fhir.r4.model.DocumentReference)

Example 63 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project fhir-bridge by ehrbase.

the class DocumentReferenceToHipDocumentConverter method getMultimedia.

private MediendateiCluster getMultimedia(DocumentReference documentReference) {
    Attachment attachment = documentReference.getContentFirstRep().getAttachment();
    DvMultimedia multimedia = new DvMultimedia();
    multimedia.setUri(new DvURI(attachment.getUrl()));
    multimedia.setMediaType(new CodePhrase(new TerminologyId("IANA_media-types"), attachment.getContentType()));
    multimedia.setSize(attachment.getSize());
    MediendateiCluster result = new MediendateiCluster();
    result.setMediendateiInhalt(multimedia);
    result.setMediendateiInhaltValue(attachment.getTitle());
    result.setBeschreibungValue(documentReference.getDescription());
    getCreation(attachment).ifPresent(result::setErstelltValue);
    return result;
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Attachment(org.hl7.fhir.r4.model.Attachment) DvMultimedia(com.nedap.archie.rm.datavalues.encapsulated.DvMultimedia) MediendateiCluster(org.ehrbase.fhirbridge.ehr.opt.hipdocumentcomposition.definition.MediendateiCluster) DvURI(com.nedap.archie.rm.datavalues.DvURI)

Example 64 with Attachment

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

the class PersonalCharacteristicsInfoHolderToDtoConverter method convert.

@Override
public PersonalCharacteristicDto convert(T infoHolder) {
    Observation obs = infoHolder.getObservation();
    PersonalCharacteristicDto dto = new PersonalCharacteristicDto(obs.getIdElement().getIdPart());
    List<String> errors = new ArrayList<>();
    // Type
    Validated.withError(dto, () -> dto.setType(CharacteristicCode.fromCode(obs.getCode().getCodingFirstRep().getCode())));
    try {
        // Method + detail
        CodeableConcept method = obs.getMethod();
        Validated.withError(dto, () -> dto.setMethod(CharacteristicMethod.fromCode(method.getCodingFirstRep().getCode())));
        dto.setMethodDetail(method.getText());
        // Value + detail
        if (obs.getValue() instanceof CodeableConcept) {
            CodeableConcept value = (CodeableConcept) obs.getValue();
            dto.setValue(new CodingDto(value.getCodingFirstRep().getCode(), value.getCodingFirstRep().getDisplay()));
            dto.setValueDetail(value.getText());
        } else if (obs.hasComponent() && CharacteristicCode.ETHNICITY.equals(dto.getType())) {
            convertEthnicity(obs, dto);
        } else if (obs.hasComponent() && CharacteristicCode.RACE.equals(dto.getType())) {
            convertRace(obs, dto);
        }
    } catch (FHIRException exc) {
        dto.getErrors().add(exc.getMessage());
    }
    // Description. Will make sense only for the race and ethnicity
    dto.setDescription(obs.getComponent().stream().filter(c -> CharacteristicCode.SYSTEM.equals(c.getCode().getCodingFirstRep().getSystem()) && c.hasValueStringType()).map(cc -> cc.getValueStringType().getValue()).findFirst().orElse(null));
    // Performer
    Practitioner performer = infoHolder.getPerformer();
    dto.setPerformer(new ReferenceDto(performer.getIdElement().getIdPart(), performer.getNameFirstRep().getNameAsSingleString()));
    // Has Attachment
    if (CharacteristicCode.SEX_GENDER.equals(dto.getType()) && obs.hasDerivedFrom()) {
        dto.setHasAttachment(true);
    }
    return dto;
}
Also used : CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Converter(org.springframework.core.convert.converter.Converter) EthnicityCode(org.hl7.gravity.refimpl.sdohexchange.codes.EthnicityCode) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) CharacteristicCode(org.hl7.gravity.refimpl.sdohexchange.codes.CharacteristicCode) PersonalCharacteristicsInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.characteristic.PersonalCharacteristicsInfoBundleExtractor.PersonalCharacteristicsInfoHolder) RaceCode(org.hl7.gravity.refimpl.sdohexchange.codes.RaceCode) Collectors(java.util.stream.Collectors) Validated(org.hl7.gravity.refimpl.sdohexchange.dto.Validated) ArrayList(java.util.ArrayList) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) List(java.util.List) PersonalCharacteristicDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.characteristic.PersonalCharacteristicDto) DetailedRaceCode(org.hl7.gravity.refimpl.sdohexchange.codes.DetailedRaceCode) Coding(org.hl7.fhir.r4.model.Coding) CharacteristicMethod(org.hl7.gravity.refimpl.sdohexchange.codes.CharacteristicMethod) FHIRException(org.hl7.fhir.exceptions.FHIRException) Observation(org.hl7.fhir.r4.model.Observation) DetailedEthnicityCode(org.hl7.gravity.refimpl.sdohexchange.codes.DetailedEthnicityCode) Practitioner(org.hl7.fhir.r4.model.Practitioner) Practitioner(org.hl7.fhir.r4.model.Practitioner) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) PersonalCharacteristicDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.characteristic.PersonalCharacteristicDto) Observation(org.hl7.fhir.r4.model.Observation) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 65 with Attachment

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

the class ConsentService method createConsent.

public ConsentDto createConsent(String name, MultipartFile attachment, UserDto userDto) {
    Reference patient = FhirUtil.toReference(Patient.class, SmartOnFhirContext.get().getPatient());
    Reference organization = retrieveOrganization(userDto);
    Consent consent = new CreateConsentFactory(name, patient, attachment, organization).createConsent();
    MethodOutcome methodOutcome = ehrClient.create().resource(consent).execute();
    Consent savedConsent = (Consent) methodOutcome.getResource();
    return new ConsentToDtoConverter().convert(savedConsent);
}
Also used : Consent(org.hl7.fhir.r4.model.Consent) CreateConsentFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.resource.CreateConsentFactory) Reference(org.hl7.fhir.r4.model.Reference) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) ConsentToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.ConsentToDtoConverter)

Aggregations

Attachment (org.hl7.fhir.r4.model.Attachment)33 Reference (org.hl7.fhir.r4.model.Reference)17 ArrayList (java.util.ArrayList)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Coding (org.hl7.fhir.r4.model.Coding)11 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)10 List (java.util.List)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)9 Observation (org.hl7.fhir.r4.model.Observation)9 Test (org.junit.jupiter.api.Test)9 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 Resource (org.hl7.fhir.r4.model.Resource)8 FhirContext (ca.uhn.fhir.context.FhirContext)5 HashMap (java.util.HashMap)5 Base64 (org.apache.commons.codec.binary.Base64)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 Extension (org.hl7.fhir.r4.model.Extension)5 Library (org.hl7.fhir.r4.model.Library)5