Search in sources :

Example 21 with Specimen

use of org.hl7.fhir.r4.model.Specimen in project org.hl7.fhir.core by hapifhir.

the class TurtleTests method test_specimen_example_isolate.

@Test
public void test_specimen_example_isolate() throws FileNotFoundException, IOException, Exception {
    System.out.println("specimen-example-isolate.ttl");
    new Turtle().parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\specimen-example-isolate.ttl"));
}
Also used : Turtle(org.hl7.fhir.dstu3.utils.formats.Turtle) Test(org.junit.jupiter.api.Test)

Example 22 with Specimen

use of org.hl7.fhir.r4.model.Specimen in project org.hl7.fhir.core by hapifhir.

the class TurtleTests method test_specimen_example_urine.

@Test
public void test_specimen_example_urine() throws FileNotFoundException, IOException, Exception {
    System.out.println("specimen-example-urine.ttl");
    new Turtle().parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\specimen-example-urine.ttl"));
}
Also used : Turtle(org.hl7.fhir.dstu3.utils.formats.Turtle) Test(org.junit.jupiter.api.Test)

Example 23 with Specimen

use of org.hl7.fhir.r4.model.Specimen in project nia-patient-switching-standard-adaptor by NHSDigital.

the class SpecimenMapperTest method testSpecimenIsMappedWithNoOptionalFields.

@Test
public void testSpecimenIsMappedWithNoOptionalFields() {
    RCMRMT030101UK04EhrExtract ehrExtract = unmarshallEhrExtract("specimen_no_optional_fields.xml");
    List<Specimen> specimenList = specimenMapper.mapSpecimen(ehrExtract, List.of(DIAGNOSTIC_REPORT_WITH_SPECIMEN), PATIENT, PRACTICE_CODE);
    Specimen specimen = specimenList.get(0);
    assertThat(specimen.getCollection().getCollected()).isNull();
    assertThat(specimen.hasAccessionIdentifier()).isFalse();
    assertThat(specimen.getType().getText()).isNullOrEmpty();
    checkFixedValues(specimen);
}
Also used : Specimen(org.hl7.fhir.dstu3.model.Specimen) RCMRMT030101UK04EhrExtract(org.hl7.v3.RCMRMT030101UK04EhrExtract) Test(org.junit.jupiter.api.Test)

Example 24 with Specimen

use of org.hl7.fhir.r4.model.Specimen in project nia-patient-switching-standard-adaptor by NHSDigital.

the class SpecimenMapper method createSpecimen.

private Specimen createSpecimen(RCMRMT030101UK04CompoundStatement specimenCompoundStatement, Patient patient, String practiceCode) {
    Specimen specimen = new Specimen();
    final String id = specimenCompoundStatement.getId().get(0).getRoot();
    specimen.setId(id);
    specimen.setMeta(generateMeta(SPECIMEN_META_PROFILE_SUFFIX));
    specimen.addIdentifier(buildIdentifier(id, practiceCode));
    specimen.setSubject(new Reference(patient));
    specimen.setNote(getNote(specimenCompoundStatement));
    getAccessionIdentifier(specimenCompoundStatement).ifPresent(specimen::setAccessionIdentifier);
    getType(specimenCompoundStatement).ifPresent(specimen::setType);
    getCollectedDateTime(specimenCompoundStatement).ifPresent(specimen::setCollection);
    return specimen;
}
Also used : Specimen(org.hl7.fhir.dstu3.model.Specimen) Reference(org.hl7.fhir.dstu3.model.Reference)

Example 25 with Specimen

use of org.hl7.fhir.r4.model.Specimen in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ORUMessageTest method test_oru_multipleOBXofDifferentTypes.

/**
 * ORU messages with an OBR and multiple OBX segments create records only for non TX type OBX
 * The OBX type TX are added to the presentedForm as an attachment for the diagnostic
 * @throws IOException
 */
// 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
void test_oru_multipleOBXofDifferentTypes() throws IOException {
    String json = ftv.convert(new File("src/test/resources/ORU-multiline-short.hl7"), OPTIONS_PRETTYPRINT);
    assertThat(json).isNotBlank();
    LOGGER.debug("FHIR json result:\n" + json);
    // Verify conversion
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    Assertions.assertSame(BundleType.COLLECTION, b.getType(), "Bundle type not expected");
    List<BundleEntryComponent> e = b.getEntry();
    // Verify that the right resources have been created
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patientResource).hasSize(1);
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    assertThat(encounterResource).hasSize(1);
    List<Resource> organizationResource = ResourceUtils.getResourceList(e, ResourceType.Organization);
    // We expect an organization created from an Encounter.serviceProvider reference
    assertThat(organizationResource).hasSize(1);
    List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    assertThat(practitionerResource).hasSize(4);
    List<Resource> messageHeader = ResourceUtils.getResourceList(e, ResourceType.MessageHeader);
    assertThat(messageHeader).hasSize(1);
    // Verify Diagnostic Report is created as expected
    List<Resource> reportResource = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    assertThat(reportResource).hasSize(1);
    List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    assertThat(servReqResource).hasSize(1);
    // Verify there are no extra resources created
    assertThat(e).hasSize(10);
    // Verify no observations are created
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    // TODO: When NTE is implemented, then update this to one.
    assertThat(obsResource).isEmpty();
    // /////////////////////////////////////////
    // Now confirm content of the diagnosticReport because we don't have separate tests for DiagnosticReport
    // /////////////////////////////////////////
    DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(reportResource.get(0), context);
    // Verify status from OBR.25
    assertThat(diag.getStatus().toCode()).isEqualTo("final");
    // Verify category from OBR.24
    assertThat(diag.getCategory()).hasSize(1);
    DatatypeUtils.checkCommonCodeableConceptAssertions(diag.getCategoryFirstRep(), "CT", "CAT Scan", "http://terminology.hl7.org/CodeSystem/v2-0074", "CT");
    // Verify code from OBR.4; This tests scenario of the code not being in the default loinc system.
    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("ECHO CARDIOGRAM COMPLETE");
    assertThat(coding.hasCode()).isTrue();
    assertThat(coding.getCode()).hasToString("1487");
    assertThat(coding.hasSystem()).isFalse();
    // Verify encounter reference
    assertThat(diag.getEncounter().isEmpty()).isFalse();
    // 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("2020-08-02T12:44:55+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
    List<Reference> spmRef = diag.getSpecimen();
    assertThat(spmRef).isEmpty();
    // Verify result reference
    List<Reference> obsRef = diag.getResult();
    assertThat(obsRef).isEmpty();
    // Verify attachment to diagnostic report
    List<Attachment> attachments = diag.getPresentedForm();
    Assertions.assertEquals(1, attachments.size(), "Unexpected number of attachments");
    Attachment a = attachments.get(0);
    Assertions.assertTrue(a.getContentType().equalsIgnoreCase("text/plain"), "Incorrect content type");
    Assertions.assertTrue(a.getLanguage().equalsIgnoreCase("en"), "Incorrect language");
    // Verify data attachment after decoding
    String decoded = new String(Base64.getDecoder().decode(a.getDataElement().getValueAsString()));
    System.out.println("Decoded: '" + decoded + "'");
    Assertions.assertEquals("\n[PII] Emergency Department\nED Encounter Arrival Date: [ADDRESS] [PERSONALNAME]:", decoded, "Incorrect data");
    Assertions.assertTrue(a.getTitle().equalsIgnoreCase("ECHO CARDIOGRAM COMPLETE"), "Incorrect title");
    // Verify creation data is persisted correctly - 2020-08-02T12:44:55+08:00
    Calendar c = Calendar.getInstance();
    // needed to completely clear out calendar object
    c.clear();
    c.set(2020, 7, 2, 12, 44, 55);
    c.setTimeZone(TimeZone.getTimeZone(ZoneId.of("+08:00")));
    Date d = c.getTime();
    Assertions.assertEquals(d, a.getCreation(), "Incorrect creation date");
    // //////////////////////////////////
    for (Resource res : obsResource) {
        // Verify encounter reference exists
        Observation obs = (Observation) res;
        assertThat(obs.getEncounter().isEmpty()).isFalse();
        assertThat(obs.getEncounter().getReference().substring(0, 10)).isEqualTo("Encounter/");
        // Verify subject reference to Patient exists
        assertThat(obs.getSubject().isEmpty()).isFalse();
        assertThat(obs.getSubject().getReference().substring(0, 8)).isEqualTo("Patient/");
    }
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Bundle(org.hl7.fhir.r4.model.Bundle) Reference(org.hl7.fhir.r4.model.Reference) Calendar(java.util.Calendar) 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) Date(java.util.Date) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)19 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)11 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)11 Resource (org.hl7.fhir.r4.model.Resource)11 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)9 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)9 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)8 Coding (org.hl7.fhir.r4.model.Coding)8 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)8 Reference (org.hl7.fhir.r4.model.Reference)8 Attachment (org.hl7.fhir.r4.model.Attachment)7 Bundle (org.hl7.fhir.r4.model.Bundle)6 Observation (org.hl7.fhir.r4.model.Observation)6 Specimen (org.hl7.fhir.dstu3.model.Specimen)4 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)4 ResourceModel (io.github.linuxforhealth.api.ResourceModel)3 RCMRMT030101UK04EhrExtract (org.hl7.v3.RCMRMT030101UK04EhrExtract)3 FHIRContext (io.github.linuxforhealth.fhir.FHIRContext)2 File (java.io.File)2 FhirPath (au.csiro.pathling.fhirpath.FhirPath)1