Search in sources :

Example 21 with MedicationRequest

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

the class Hl7IdentifierFHIRConversionTest method medicationRequestIdentifierTest3.

@Test
void medicationRequestIdentifierTest3() throws IOException {
    // Test: Visit number from MSH-7, extID from RXE-2
    String medicationRequest = "MSH|^~\\&|PROSLOV|MYHOSPITAL|WHIA|IBM|20170215080000||OMP^O09|MSGID005520|T|2.6|||AL|NE|764|ASCII||||||^4086::132:2A57:3C28^IPv6\r" + "PID|1||000054321^^^MRN\r" + "PV1||I||||||||SUR||||||||S||A|||||||||||||||||||SF|K||||20170215080000\r" + "ORC|NW||CD2017071101^RX|||E|10^BID^D4^^^R||20170215080000\r" + "RXO|^DOCUSATE SODIUM 100 MG CAPSULE|100||mg|||||G||10||5|\r";
    MedicationRequest medReq = ResourceUtils.getMedicationRequest(ftv, medicationRequest);
    // Expect 3 identifiers
    assertThat(medReq.hasIdentifier()).isTrue();
    assertThat(medReq.getIdentifier()).hasSize(3);
    List<Identifier> identifiers = medReq.getIdentifier();
    // Match the id's to position; we can't depend on an order.
    int posVN = getIdentifierPositionByValue("20170215080000", identifiers);
    assertThat(posVN).isNotSameAs(-1);
    int posExtId = getIdentifierPositionByValue("DOCUSATE SODIUM 100 MG CAPSULE", identifiers);
    assertThat(posExtId).isNotSameAs(-1);
    int posRX = getIdentifierPositionByValue("CD2017071101", identifiers);
    assertThat(posRX).isNotSameAs(-1);
    // Identifier 1: Visit number
    Identifier identifier = medReq.getIdentifier().get(posVN);
    String value = identifier.getValue();
    String system = identifier.getSystem();
    // MSH-7
    assertThat(value).isEqualTo("20170215080000");
    assertThat(system).isNull();
    CodeableConcept type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Identifier 2: extID based on RXO-1.2
    identifier = medReq.getIdentifier().get(posExtId);
    value = identifier.getValue();
    system = identifier.getSystem();
    // RXO-1.2
    assertThat(value).isEqualTo("DOCUSATE SODIUM 100 MG CAPSULE");
    assertThat(system).isEqualTo("urn:id:extID");
    // Identifier 3: RX
    identifier = medReq.getIdentifier().get(posRX);
    value = identifier.getValue();
    system = identifier.getSystem();
    // ORC.3.1
    assertThat(value).isEqualTo("CD2017071101");
    // ORC-3.2 any whitespace gets replaced with underscores
    assertThat(system).isEqualTo("urn:id:RX");
    type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "FILL", "Filler Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Identifier(org.hl7.fhir.r4.model.Identifier) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 22 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveMedicationRequest.

private MedicationRequest resolveMedicationRequest(ActivityDefinition activityDefinition, String patientId) throws ActivityDefinitionApplyException {
    // intent, medication, and subject are required
    MedicationRequest medicationRequest = new MedicationRequest();
    medicationRequest.setIntent(MedicationRequest.MedicationRequestIntent.ORDER);
    medicationRequest.setSubject(new Reference(patientId));
    if (activityDefinition.hasProduct()) {
        medicationRequest.setMedication(activityDefinition.getProduct());
    } else {
        throw new ActivityDefinitionApplyException("Missing required product property");
    }
    if (activityDefinition.hasDosage()) {
        medicationRequest.setDosageInstruction(activityDefinition.getDosage());
    }
    if (activityDefinition.hasBodySite()) {
        throw new ActivityDefinitionApplyException("BodySite does not map to " + activityDefinition.getKind());
    }
    if (activityDefinition.hasCode()) {
        throw new ActivityDefinitionApplyException("Code does not map to " + activityDefinition.getKind());
    }
    if (activityDefinition.hasQuantity()) {
        throw new ActivityDefinitionApplyException("Quantity does not map to " + activityDefinition.getKind());
    }
    return medicationRequest;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) Reference(org.hl7.fhir.dstu3.model.Reference)

Example 23 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveActivityDefinition.

// For library use
public Resource resolveActivityDefinition(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId, RequestDetails theRequest) throws FHIRException {
    Resource result = newResource(activityDefinition.getKind().toCode());
    switch(result.fhirType()) {
        case "ServiceRequest":
            result = resolveServiceRequest(activityDefinition, patientId, practitionerId, organizationId);
            break;
        case "MedicationRequest":
            result = resolveMedicationRequest(activityDefinition, patientId);
            break;
        case "SupplyRequest":
            result = resolveSupplyRequest(activityDefinition, practitionerId, organizationId);
            break;
        case "Procedure":
            result = resolveProcedure(activityDefinition, patientId);
            break;
        case "DiagnosticReport":
            result = resolveDiagnosticReport(activityDefinition, patientId);
            break;
        case "Communication":
            result = resolveCommunication(activityDefinition, patientId);
            break;
        case "CommunicationRequest":
            result = resolveCommunicationRequest(activityDefinition, patientId);
            break;
        case "Task":
            result = resolveTask(activityDefinition, patientId);
            break;
    }
    for (ActivityDefinition.ActivityDefinitionDynamicValueComponent dynamicValue : activityDefinition.getDynamicValue()) {
        // ActivityDefinition apply operation does not fail.
        try {
            if (dynamicValue.getExpression() != null) {
                // Special case for setting a Patient reference
                if ("Patient".equals(dynamicValue.getExpression().getExpression())) {
                    this.modelResolver.setValue(result, dynamicValue.getPath(), new Reference(patientId));
                } else {
                    /*
						 * TODO: Passing the activityDefinition as context here because that's what will
						 * have the libraries, but perhaps the "context" here should be the result
						 * resource?
						 */
                    Object value = expressionEvaluation.evaluateInContext(activityDefinition, dynamicValue.getExpression().getExpression(), patientId, theRequest);
                    if (value != null) {
                        logger.debug("dynamicValue value: {}", value);
                        if (value instanceof Boolean) {
                            value = new BooleanType((Boolean) value);
                        } else if (value instanceof DateTime) {
                            value = Date.from(((DateTime) value).getDateTime().toInstant());
                        } else if (value instanceof String) {
                            value = new StringType((String) value);
                        }
                        this.modelResolver.setValue(result, dynamicValue.getPath(), value);
                    } else {
                        logger.warn("WARNING: ActivityDefinition has null value for path: {}", dynamicValue.getPath());
                    }
                }
            }
        } catch (Exception e) {
            logger.error("ERROR: ActivityDefinition dynamicValue {} could not be applied and threw exception {}", dynamicValue.getPath(), e.toString());
            logger.error(e.toString());
        }
    }
    return result;
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) Reference(org.hl7.fhir.r4.model.Reference) Resource(org.hl7.fhir.r4.model.Resource) BooleanType(org.hl7.fhir.r4.model.BooleanType) DateTime(org.opencds.cqf.cql.engine.runtime.DateTime) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ActivityDefinition(org.hl7.fhir.r4.model.ActivityDefinition)

Example 24 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class FhirMedicationRequestServiceImplTest method searchForMedicationRequest_shouldReturnCollectionOfMedicationRequestByEncounter.

@Test
public void searchForMedicationRequest_shouldReturnCollectionOfMedicationRequestByEncounter() {
    ReferenceAndListParam encounter = new ReferenceAndListParam();
    encounter.addValue(new ReferenceOrListParam().add(new ReferenceParam().setValue("jdjdj-kdkdkkd-kddd").setChain(Encounter.SP_IDENTIFIER)));
    List<DrugOrder> drugOrders = new ArrayList<>();
    drugOrders.add(drugOrder);
    medicationRequest.setId(MEDICATION_REQUEST_UUID);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounter);
    when(dao.getSearchResults(any(), any())).thenReturn(drugOrders);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_REQUEST_UUID));
    when(medicationRequestTranslator.toFhirResource(drugOrder)).thenReturn(medicationRequest);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, medicationRequestTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = medicationRequestService.searchForMedicationRequests(null, encounter, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, Matchers.notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : DrugOrder(org.openmrs.DrugOrder) ArrayList(java.util.ArrayList) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 25 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestSearchQueryTest method searchForMedicationRequests_shouldSearchForMedicationRequestsByMultiplePatientUuidOr.

@Test
public void searchForMedicationRequests_shouldSearchForMedicationRequestsByMultiplePatientUuidOr() {
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam patient = new ReferenceParam();
    patient.setValue(PATIENT_UUID);
    ReferenceParam badPatient = new ReferenceParam();
    badPatient.setValue(WRONG_UUID);
    referenceParam.addValue(new ReferenceOrListParam().add(patient).add(badPatient));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam);
    IBundleProvider results = search(theParams);
    List<MedicationRequest> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(MEDICATION_REQUEST_UUID))));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)128 Test (org.junit.Test)128 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)78 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)58 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)48 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)44 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)44 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)44 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)36 Test (org.junit.jupiter.api.Test)35 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)33 Resource (org.hl7.fhir.r4.model.Resource)31 MedicationRequest (org.hl7.fhir.dstu3.model.MedicationRequest)26 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)23 TokenParam (ca.uhn.fhir.rest.param.TokenParam)23 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)23 ArrayList (java.util.ArrayList)19 Include (ca.uhn.fhir.model.api.Include)15 HashSet (java.util.HashSet)15