Search in sources :

Example 61 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ImmunizationFHIRConversionTest method testImmunizationUsePATOBJ.

@Test
void testImmunizationUsePATOBJ() throws IOException {
    // Test should only return RXA.10, ORC.12  is empty
    // If RXA.20 is RE but RXA.18 is blank then we use PATOBJ from v3ActReason
    String hl7VUXmessageRep = "MSH|^~\\&|EHR|12345^SiteName|MIIS|99990|20140701041038||VXU^V04^VXU_V04|MSG.Valid_01|P|2.6|||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "ORC|RE||197027||PA|||||^Clerk^Myron|||||||RI2050\r" + "RXA|||20130531||48^HIB PRP-T^CVX|0.5|ML^^UCUM||||||||||||00^refusal|RE\r" + "OBX|1|CWE|30963-3^ VACCINE FUNDING SOURCE^LN|1|V02^VFC eligible Medicaid/MedicaidManaged Care^HL70064\r";
    Immunization immunization = ResourceUtils.getImmunization(ftv, hl7VUXmessageRep);
    assertThat(immunization.hasReasonCode()).isTrue();
    assertThat(immunization.getReasonCodeFirstRep().getCodingFirstRep().getCode()).isEqualTo("00");
    assertThat(immunization.getReasonCodeFirstRep().getCodingFirstRep().getDisplay()).isEqualTo("refusal");
    assertThat(immunization.getReasonCodeFirstRep().getCodingFirstRep().getSystem()).isNull();
    assertThat(immunization.getReasonCodeFirstRep().getText()).isEqualTo("refusal");
    assertThat(immunization.getStatus().getDisplay()).isEqualTo("not-done");
    assertThat(immunization.hasStatusReason()).isTrue();
    // If RXA.20 is RE but RXA.18 is blank then we use PATOBJ from v3ActReason
    assertThat(immunization.getStatusReason().getCodingFirstRep().getCode()).isEqualTo("PATOBJ");
    assertThat(immunization.getStatusReason().getCodingFirstRep().getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v3-ActReason");
    assertThat(immunization.getStatusReason().getCodingFirstRep().getDisplay()).isEqualTo("Patient Refusal");
    // dose Quantity with a known system
    assertThat(immunization.hasDoseQuantity()).isTrue();
    assertThat(immunization.getDoseQuantity().getValue()).hasToString("0.5");
    assertThat(immunization.getDoseQuantity().getUnit()).isEqualTo("ML");
    assertThat(immunization.getDoseQuantity().getSystem()).isEqualTo("http://unitsofmeasure.org");
    // If OBX.3 is 30963-3 the OBX.5 is for funding source
    DatatypeUtils.checkCommonCodeableConceptAssertions(immunization.getFundingSource(), "V02", "VFC eligible Medicaid/MedicaidManaged Care", "https://phinvads.cdc.gov/vads/ViewCodeSystem.action?id=2.16.840.1.113883.12.64#", "VFC eligible Medicaid/MedicaidManaged Care");
    assertThat(immunization.hasProgramEligibility()).isFalse();
    assertThat(immunization.hasReaction()).isFalse();
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) Test(org.junit.jupiter.api.Test)

Example 62 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ImmunizationFHIRConversionTest method testImmunizationReturnOnlyRXA10.

@Test
void testImmunizationReturnOnlyRXA10() throws IOException {
    // Test should only return RXA.10, ORC.12  is empty
    // ORC.9 (Backup for RXA.22) has recorded date
    // RXA.18 is not empty which signals that the status is not-done. ORC.5 is here to show precedence
    // Since status is "not-done" we show the Status reason (RXA.18)
    String hl7VUXmessageRep = "MSH|^~\\&|EHR|12345^SiteName|MIIS|99990|20140701041038||VXU^V04^VXU_V04|MSG.Valid_01|P|2.6|||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "ORC|RE||197027||CP||||20120901041038|^Clerk^Myron|||||||\r" + "RXA|||20130531||48^HIB PRP-T^CVX|0.5|ML^^^|||^Sticker^Nurse||||||||00^Patient refusal^NIP002|||\r" + "OBX|1|CWE|64994-7^vaccine fund pgm elig cat^LN|1|V02^VFC eligible Medicaid/MedicaidManaged Care^HL70064\r";
    Immunization immunization = ResourceUtils.getImmunization(ftv, hl7VUXmessageRep);
    assertThat(immunization.getPerformer()).hasSize(1);
    DatatypeUtils.checkCommonCodingAssertions(immunization.getPerformer().get(0).getFunction().getCodingFirstRep(), "AP", "Administering Provider", "http://terminology.hl7.org/CodeSystem/v2-0443", // RXA.10
    null);
    assertThat(immunization.getPerformer().get(0).getFunction().hasText()).isFalse();
    // RXA.18 is not empty which signals that the status is not-done. ORC.5 is here to show precedence
    assertThat(immunization.getStatus().getDisplay()).isEqualTo("not-done");
    // if status is "not-done" we show the Status reason
    assertThat(immunization.hasStatusReason()).isTrue();
    assertThat(immunization.getStatusReason().getCodingFirstRep().getCode()).isEqualTo("00");
    assertThat(immunization.getStatusReason().getCodingFirstRep().getSystem()).isEqualTo("urn:id:NIP002");
    assertThat(immunization.getStatusReason().getCodingFirstRep().getDisplay()).isEqualTo("Patient refusal");
    // ORC.9
    assertThat(immunization.hasRecorded()).isTrue();
    // ORC.9
    assertThat(immunization.getRecordedElement().toString()).contains("2012-09-01");
    // dose Quantity without a system
    assertThat(immunization.hasDoseQuantity()).isTrue();
    assertThat(immunization.getDoseQuantity().getValue()).hasToString("0.5");
    assertThat(immunization.getDoseQuantity().getUnit()).isEqualTo("ML");
    assertThat(immunization.getDoseQuantity().getSystem()).isNull();
    assertThat(immunization.getDoseQuantity().getCode()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(immunization.getProgramEligibilityFirstRep(), "V02", "VFC eligible Medicaid/MedicaidManaged Care", "https://phinvads.cdc.gov/vads/ViewCodeSystem.action?id=2.16.840.1.113883.12.64#", "VFC eligible Medicaid/MedicaidManaged Care");
    assertThat(immunization.hasFundingSource()).isFalse();
    assertThat(immunization.hasReaction()).isFalse();
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) Test(org.junit.jupiter.api.Test)

Example 63 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7OrderRequestFHIRConversionTest method testBroadORCPlusOBRFields2.

@Test
void testBroadORCPlusOBRFields2() {
    String hl7message = "MSH|^~\\&|||||20180924152907|34001|ORU^R01^ORU_R01|213|T|2.6|||||||||||\n" + // PID.18 is empty, MSH.7 will be used as identifier visit number
    "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + // PV1.19  is empty, MSH.7 will be used as identifier visit number
    "PV1|1|E|||||||||||||||||||||||||||||||||||||||||||\n" + // ORC.5 with purposely bad code to see that 'unknown' is result
    "ORC|RE|248648498^|248648498^||ZZ||||20120628071200||||||||||||||||||||||\n" + "OBR|1|248648498^|248648498^|83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C|||||||L||||||||||||||F||^^^20120606120606|||||||||||||||||||||||\n";
    String json = ftv.convert(hl7message, PatientUtils.OPTIONS);
    assertThat(json).isNotBlank();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle bundle = (Bundle) bundleResource;
    List<BundleEntryComponent> e = bundle.getEntry();
    List<Resource> serviceRequestList = e.stream().filter(v -> ResourceType.ServiceRequest == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    // Important that we have exactly one service request (no duplication).  OBR creates it as a reference.
    assertThat(serviceRequestList).hasSize(1);
    ServiceRequest serviceRequest = ResourceUtils.getResourceServiceRequest(serviceRequestList.get(0), context);
    assertThat(serviceRequest.hasStatus()).isTrue();
    assertThat(serviceRequest.hasIdentifier()).isTrue();
    assertThat(serviceRequest.getIdentifier()).hasSize(3);
    // Identifier 1: visit number should be set by in this test by tertiary MSH.7
    // See notes about identifier testing in previous tests
    Identifier identifier = serviceRequest.getIdentifier().get(0);
    String value = identifier.getValue();
    String system = identifier.getSystem();
    // MSH.7 as a string, not as a date
    assertThat(value).isEqualTo("20180924152907");
    assertThat(system).isNull();
    CodeableConcept type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // OBR.27[0].4 should create an ServiceRequest.occurrenceDateTime date
    assertThat(serviceRequest.hasOccurrenceDateTimeType()).isTrue();
    assertThat(serviceRequest.getOccurrenceDateTimeType().toString()).containsPattern("2012-06-06T12:06:06");
    // // ORC.5 creates the serviceRequest.status() purposely an unknown code
    assertThat(serviceRequest.hasStatus()).isTrue();
    assertThat(serviceRequest.getStatusElement().getCode()).isEqualTo("unknown");
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 64 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project hl7v2-fhir-converter by LinuxForHealth.

the class FHIRConverterTest method testCodingSystems.

@Test
/*
     * This tests some of coding systems of interest or potential problems
     */
void testCodingSystems() throws FHIRException {
    String hl7VUXmessageRep = "MSH|^~\\&|MYEHR2.5|RI88140101|KIDSNET_IFL|RIHEALTH|201305330||VXU^V04^VXU_V04|20130531RI881401010105|P|2.6|||AL|NE|764|ASCII||||||^4086::132:2A57:3C28^IPv6\r" + "EVN|A01|20130617154644||01\r" + "PID|1||12345678^^^MYEMR^MR||TestPatient^John|||M|\r" + "ORC|RE||197027|||||||^Clerk^Myron||MD67895^Pediatric^MARY^^^^MD^^RIA|||||RI2050\r" + // Test MVX
    "RXA|0|1|20130528|20130529|48^HIB PRP-T^CVX|0.5|ML^^ISO+||00^new immunization record^NIP001|^Sticker^Nurse|^^^RI2050||||33k2a|20131210|PMC^sanofi^MVX|||CP|A\r" + // Test HL70162 & HL70163
    "RXR|C28161^IM^NCIT^IM^INTRAMUSCULAR^HL70162|RT^right thigh^HL70163\r";
    String json = ftv.convert(hl7VUXmessageRep, OPTIONS);
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);
    assertThat(b.getId()).isNotNull();
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> obsResource = e.stream().filter(v -> ResourceType.Immunization == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(obsResource).hasSize(1);
    Immunization immunization = (Immunization) obsResource.get(0);
    // Check that organization identifier (MVX) has a system
    Organization org = (Organization) immunization.getManufacturer().getResource();
    List<Identifier> li = org.getIdentifier();
    Identifier ident = li.get(0);
    assertThat(ident.hasSystem()).isTrue();
    assertThat(ident.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/MVX");
    assertThat(ident.hasValue()).isTrue();
    assertThat(ident.getValue()).isEqualTo("PMC");
    // Check that route (HL70162) has a system
    CodeableConcept route = immunization.getRoute();
    assertThat(route.hasCoding()).isTrue();
    List<Coding> codings = route.getCoding();
    assertThat(codings.size()).isEqualTo(2);
    Coding coding = codings.get(0);
    // If the first one is not the one we want look at the second one.
    if (coding.getCode().contains("C28161")) {
        coding = codings.get(1);
    }
    assertThat(coding.hasSystem()).isTrue();
    assertThat(coding.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0162");
    // Check that site (HL70163) has a system
    CodeableConcept site = immunization.getSite();
    coding = site.getCodingFirstRep();
    assertThat(coding.hasSystem()).isTrue();
    assertThat(coding.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0163");
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Immunization(org.hl7.fhir.r4.model.Immunization) Organization(org.hl7.fhir.r4.model.Organization) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 65 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project health-patterns by LinuxForHealth.

the class TerminologyService method translateResource.

/**
 * Translates the given single FHIR resource represented as a {@link JsonNode}.
 *
 * @param resource the FHIR resource to translate
 * @returns true if there was something to translate, false otherwise
 * @throws DeIdentifierException if there is an error in the de-identification REST API or parsing the JSON
 * @throws IllegalArgumentException if the given JSON does not have a 'resource' object
 */
private boolean translateResource(JsonNode resource) {
    boolean translatedSomething = false;
    String resourceType = getResourceType(resource);
    boolean isTranslatable = StringUtils.equalsAny(resourceType, TRANSLATABLE_FHIR_TYPES);
    if (!isTranslatable) {
        return translatedSomething;
    }
    ArrayNode extensions = (ArrayNode) resource.get(EXTENSION_OBJECT);
    if (extensions == null) {
        return translatedSomething;
    }
    for (int i = 0; i < extensions.size(); i++) {
        JsonNode extension = extensions.get(i);
        JsonNode urlJson = extension.get(URL_OBJECT);
        JsonNode valueCodeJson = extension.get(VALUE_CODE_OBJECT);
        if (urlJson == null || valueCodeJson == null) {
            // In order to do a translation we need both the url and the valueCode
            continue;
        }
        // The resource's extension URL is the URL for the StructureDefinition, so we resolve a ValueSet if known
        String structureDefinitionURL = urlJson.asText();
        String valueSetURL = valueSetForStructureDefinition.get(structureDefinitionURL);
        // and if known we check the FHIR Server's known ConceptMaps to see if there is a corresponding one
        // http://4603f72b-us-south.lb.appdomain.cloud/fhir-server/api/v4/ConceptMap?_format=json&source-uri=http://hl7.org/fhir/us/core/ValueSet/birthsex
        Bundle bundle = fhirClient.search().forResource(ConceptMap.class).where(ConceptMap.SOURCE_URI.hasId(valueSetURL)).returnBundle(Bundle.class).execute();
        String conceptMapId;
        if (!bundle.getEntry().isEmpty()) {
            Resource conceptMap = bundle.getEntry().get(0).getResource();
            if (bundle.getEntry().size() > 1) {
                System.err.println("Found multiple ConceptMaps that will map " + valueSetURL + " for this StructureDefinition, will use the first one " + conceptMap.getId());
            } else {
                System.out.println("Found ConceptMap for " + valueSetURL + ": " + conceptMap.getId() + " !!");
            }
            conceptMapId = conceptMap.getIdElement().getIdPart();
        } else {
            System.out.println("Did not find ConceptMap for " + valueSetURL + "!!");
            continue;
        }
        // "POST ${FHIR_URL}/${conceptMapID}/$translate?code=${code}&system=${valueSet}&_format=json
        String valueCode = valueCodeJson.asText();
        String url = String.format("%s/ConceptMap/%s/$translate?code=%s&system=%s&_format=json", fhirClient.getServerBase(), conceptMapId, valueCode, valueSetURL);
        Parameters translationResponse = fhirClient.fetchResourceFromUrl(Parameters.class, url);
        // This is what comes back from the server
        // {
        // "resourceType": "Parameters",
        // "parameter": [
        // {
        // "name": "result",
        // "valueBoolean": true
        // },
        // {
        // "name": "match",
        // "part": [
        // {
        // "name": "equivalence",
        // "valueCode": "equivalent"
        // },
        // {
        // "name": "concept",
        // "valueCoding": {
        // "system": "http://ibm.com/fhir/cdm/ValueSet/sex-assigned-at-birth",
        // "code": "male",
        // "display": "Male"
        // }
        // }
        // ]
        // }
        // ]
        // }
        Coding translatedCode = null;
        List<ParametersParameterComponent> parameters = translationResponse.getParameter();
        for (ParametersParameterComponent parameter : parameters) {
            if (parameter.getName().equals(MATCH_VALUE)) {
                List<ParametersParameterComponent> parts = parameter.getPart();
                for (ParametersParameterComponent part : parts) {
                    if (part.getName().equals(CONCEPT_VALUE)) {
                        try {
                            translatedCode = (Coding) part.getValue();
                        } catch (ClassCastException e) {
                            String jsonResponse = fhirClient.getFhirContext().newJsonParser().encodeResourceToString(translationResponse);
                            System.err.println("Found a ConceptMap that will map " + valueSetURL + " for this StructureDefinition, but the FHIR server returned an unknown $translate response (expected a 'valueCoding' part): " + jsonResponse);
                        }
                    }
                }
            }
        }
        if (translatedCode == null) {
            String jsonResponse = fhirClient.getFhirContext().newJsonParser().encodeResourceToString(translationResponse);
            System.err.println("Found a ConceptMap that will map " + valueSetURL + " for this StructureDefinition, but the FHIR server returned an unknown $translate response: " + jsonResponse);
            continue;
        }
        System.out.printf("Found ConceptMap %s which translates (valueCode, system) = (%s, %s) for StructureDefinition %s to (valueCode, system) = (%s, %s) %n", conceptMapId, valueCode, valueSetURL, structureDefinitionURL, translatedCode.getCode(), translatedCode.getSystem());
        String translatedStructuredData = valueSetForStructureDefinition.get(translatedCode.getSystem());
        if (translatedStructuredData == null) {
            System.err.printf("Cannot find the mapping from ValueSet '%s' to its corresponding StructureData for this translation, make sure the corresponding mappings configuration file has it.%n", translatedCode.getSystem());
            continue;
        }
        ((ObjectNode) extension).set(URL_OBJECT, JsonNodeFactory.instance.textNode(translatedStructuredData));
        ((ObjectNode) extension).set(VALUE_CODE_OBJECT, JsonNodeFactory.instance.textNode(translatedCode.getCode()));
        translatedSomething = true;
    }
    return translatedSomething;
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) JsonNode(com.fasterxml.jackson.databind.JsonNode) Coding(org.hl7.fhir.r4.model.Coding) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Aggregations

Test (org.junit.jupiter.api.Test)92 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)75 ArrayList (java.util.ArrayList)70 Coding (org.hl7.fhir.r4.model.Coding)70 Identifier (org.hl7.fhir.r4.model.Identifier)62 FHIRException (org.hl7.fhir.exceptions.FHIRException)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)45 Resource (org.hl7.fhir.r4.model.Resource)45 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 Test (org.junit.Test)37 Coding (org.hl7.fhir.dstu3.model.Coding)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 HashMap (java.util.HashMap)30 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)28 List (java.util.List)27 IOException (java.io.IOException)26 Bundle (org.hl7.fhir.r4.model.Bundle)26 Patient (org.hl7.fhir.r4.model.Patient)25 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)24 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21