Search in sources :

Example 81 with Medication

use of org.hl7.fhir.r4.model.Medication in project fhir-bridge by ehrbase.

the class FindMedicationStatementTransactionIT method findMedicationStatementSearch.

@Test
void findMedicationStatementSearch() throws IOException {
    for (int i = 0; i < 3; i++) {
        create("MedicationStatement/transactions/find-medication-statement-search.json");
    }
    Bundle bundle = search("MedicationStatement?subject.identifier=" + PATIENT_ID + "&status=not-taken");
    Assertions.assertEquals(3, bundle.getTotal());
    bundle.getEntry().forEach(entry -> {
        var medicationStatement = (MedicationStatement) entry.getResource();
        Assertions.assertEquals(PATIENT_ID, medicationStatement.getSubject().getIdentifier().getValue());
        Assertions.assertEquals(MedicationStatement.MedicationStatementStatus.NOTTAKEN, medicationStatement.getStatus());
    });
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) MedicationStatement(org.hl7.fhir.r4.model.MedicationStatement) Test(org.junit.jupiter.api.Test)

Example 82 with Medication

use of org.hl7.fhir.r4.model.Medication in project pathling by aehrc.

the class TestData method newMedication.

/**
 * Returns a FHIR medication to be contained to a medication request for testing purposes.
 */
public static Medication newMedication() {
    final Medication medication = new Medication();
    medication.setId("test-med");
    final MedicationIngredientComponent ingredient = new MedicationIngredientComponent();
    final CodeableConcept item = new CodeableConcept();
    item.addCoding().setSystem("test/ingredient/system").setCode("test-code");
    ingredient.setItem(item);
    medication.addIngredient(ingredient);
    return medication;
}
Also used : MedicationIngredientComponent(org.hl7.fhir.r4.model.Medication.MedicationIngredientComponent)

Example 83 with Medication

use of org.hl7.fhir.r4.model.Medication in project eCRNow by drajer-health.

the class CdaFhirUtilities method getStringForMedicationFromContainedResources.

public static String getStringForMedicationFromContainedResources(List<Resource> resources, String refId) {
    Pair<String, Boolean> retVal = null;
    for (Resource res : resources) {
        logger.debug("res.getId {}", res.getId());
        if (res.getId().contains(refId) && res instanceof Medication) {
            logger.debug("Found a Contained Resource with Id {}", refId);
            Medication cmed = (Medication) res;
            if (cmed.getCode() != null) {
                logger.debug("Found Contained Med  Code");
                retVal = getCodeableConceptDisplayForCodeSystem(cmed.getCode(), CdaGeneratorConstants.FHIR_RXNORM_URL, false);
            }
            if (retVal.getValue0().isEmpty()) {
                logger.debug("Return Val is empty");
                if (cmed.getIngredient() != null) {
                    logger.debug("Found ingredient");
                    List<MedicationIngredientComponent> ings = cmed.getIngredient();
                    for (MedicationIngredientComponent ing : ings) {
                        if (ing.getItem() instanceof CodeableConcept) {
                            logger.debug("Found a CC for Ingredient");
                            CodeableConcept cc = (CodeableConcept) ing.getItem();
                            retVal = getCodeableConceptDisplayForCodeSystem(cc, CdaGeneratorConstants.FHIR_RXNORM_URL, false);
                            break;
                        }
                    }
                }
            }
            if (!retVal.getValue0().isEmpty())
                return retVal.getValue0();
        }
    // Found id
    }
    return CdaGeneratorConstants.UNKNOWN_VALUE;
}
Also used : MedicationIngredientComponent(org.hl7.fhir.r4.model.Medication.MedicationIngredientComponent) Resource(org.hl7.fhir.r4.model.Resource) DomainResource(org.hl7.fhir.r4.model.DomainResource) Medication(org.hl7.fhir.r4.model.Medication) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 84 with Medication

use of org.hl7.fhir.r4.model.Medication in project eCRNow by drajer-health.

the class TriggerQueryR4Bundle method createR4Bundle.

public Bundle createR4Bundle(LaunchDetails launchDetails, R4FhirData r4FhirData, Date start, Date end) {
    logger.trace("Initializing FHIR Context for Version:::: {}", launchDetails.getFhirVersion());
    FhirContext context = fhirContextInitializer.getFhirContext(launchDetails.getFhirVersion());
    IGenericClient client = fhirContextInitializer.createClient(context, launchDetails);
    Bundle bundle = r4ResourcesData.getCommonResources(r4FhirData, start, end, launchDetails, client, context);
    // Setting bundle to FHIR Data
    logger.info("------------------------------CodeableConcept Codes------------------------------\n" + "Encounter Codes Size=====> {} \n" + "Conditions Codes Size=====> {} \n" + "Observation Codes Size=====> {}\n" + "Medication Codes Size=====> {}\n" + "ServiceRequests Codes Size=====> {}", r4FhirData.getR4EncounterCodes().size(), r4FhirData.getR4ConditionCodes().size(), r4FhirData.getR4LabResultCodes().size(), r4FhirData.getR4MedicationCodes().size(), r4FhirData.getR4ServiceRequestCodes().size());
    String fileName = ActionRepo.getInstance().getLogFileDirectory() + "/TriggerQueryR4Bundle-" + launchDetails.getLaunchPatientId() + ".json";
    ApplicationUtils.saveDataToFile(context.newJsonParser().encodeResourceToString(bundle), fileName);
    return bundle;
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle)

Example 85 with Medication

use of org.hl7.fhir.r4.model.Medication in project eCRNow by drajer-health.

the class LoadingQueryR4Bundle method createR4Bundle.

public Bundle createR4Bundle(LaunchDetails launchDetails, R4FhirData r4FhirData, Date start, Date end) {
    logger.trace("Initializing FHIR Context for Version:::: {}", launchDetails.getFhirVersion());
    FhirContext context = fhirContextInitializer.getFhirContext(launchDetails.getFhirVersion());
    IGenericClient client = fhirContextInitializer.createClient(context, launchDetails);
    Bundle bundle = r4ResourcesData.getCommonResources(r4FhirData, start, end, launchDetails, client, context);
    Encounter encounter = (Encounter) r4ResourcesData.getResourceFromBundle(bundle, Encounter.class);
    r4ResourcesData.loadPractitionersLocationAndOrganization(context, client, launchDetails, r4FhirData, encounter, bundle, start, end);
    r4ResourcesData.loadMedicationsData(context, client, launchDetails, r4FhirData, encounter, bundle, start, end);
    // Get Pregnancy Observations
    try {
        List<Observation> observationList = r4ResourcesData.getPregnancyObservationData(context, client, launchDetails, r4FhirData, encounter, start, end);
        r4FhirData.setPregnancyObs(observationList);
        for (Observation observation : observationList) {
            BundleEntryComponent observationsEntry = new BundleEntryComponent().setResource(observation);
            bundle.addEntry(observationsEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting Pregnancy Observation Data", e);
    }
    // Get Travel Observations
    try {
        List<Observation> observationList = r4ResourcesData.getTravelObservationData(context, client, launchDetails, r4FhirData, encounter, start, end);
        r4FhirData.setTravelObs(observationList);
        for (Observation observation : observationList) {
            BundleEntryComponent observationsEntry = new BundleEntryComponent().setResource(observation);
            bundle.addEntry(observationsEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting Travel Observation Data", e);
    }
    // Get Social History Observations (Occupation)
    try {
        List<Observation> observationList = r4ResourcesData.getSocialHistoryObservationDataOccupation(context, client, launchDetails, r4FhirData, encounter, start, end);
        r4FhirData.setOccupationObs(observationList);
        for (Observation observation : observationList) {
            BundleEntryComponent observationsEntry = new BundleEntryComponent().setResource(observation);
            bundle.addEntry(observationsEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting Social History Observation(Occupation) Data", e);
    }
    // Get Pregnancy Conditions
    try {
        List<Condition> conditionList = r4ResourcesData.getPregnancyConditions(context, client, launchDetails, r4FhirData, encounter, start, end);
        r4FhirData.setPregnancyConditions(conditionList);
        for (Condition condition : conditionList) {
            BundleEntryComponent conditionEntry = new BundleEntryComponent().setResource(condition);
            bundle.addEntry(conditionEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting Pregnancy Conditions", e);
    }
    try {
        List<MedicationStatement> medStatementsList = r4ResourcesData.getMedicationStatementData(context, client, launchDetails, r4FhirData, encounter, start, end);
        r4FhirData.setMedications(medStatementsList);
        for (MedicationStatement medStatement : medStatementsList) {
            BundleEntryComponent medStatementEntry = new BundleEntryComponent().setResource(medStatement);
            bundle.addEntry(medStatementEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting the MedicationStatement Data", e);
    }
    // Add to the bundle
    try {
        List<Immunization> immunizationsList = r4ResourcesData.getImmunizationData(context, client, launchDetails, r4FhirData, encounter, start, end);
        r4FhirData.setImmunizations(immunizationsList);
        for (Immunization immunization : immunizationsList) {
            BundleEntryComponent immunizationEntry = new BundleEntryComponent().setResource(immunization);
            bundle.addEntry(immunizationEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting the Immunization Data", e);
    }
    // Add to the bundle
    try {
        List<DiagnosticReport> diagnosticReportList = r4ResourcesData.getDiagnosticReportData(context, client, launchDetails, r4FhirData, encounter, start, end);
        r4FhirData.setDiagReports(diagnosticReportList);
        for (DiagnosticReport diagnosticReport : diagnosticReportList) {
            BundleEntryComponent diagnosticReportEntry = new BundleEntryComponent().setResource(diagnosticReport);
            bundle.addEntry(diagnosticReportEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting the DiagnosticReport Data", e);
    }
    // Setting bundle to FHIR Data
    logger.info("------------------------------CodeableConcept Codes------------------------------\n" + "Encounter Codes Size=====> {} \n" + "Conditions Codes Size=====> {} \n" + "Observation Codes Size=====> {}\n" + "Medication Codes Size=====> {}\n" + "Immunization Codes Size=====> {}\n" + "DiagnosticReport Codes Size=====> {}\n" + "ServiceRequests Codes Size=====> {}", r4FhirData.getR4EncounterCodes().size(), r4FhirData.getR4ConditionCodes().size(), r4FhirData.getR4LabResultCodes().size(), r4FhirData.getR4MedicationCodes().size(), r4FhirData.getR4ImmunizationCodes().size(), r4FhirData.getR4DiagnosticReportCodes().size(), r4FhirData.getR4ServiceRequestCodes().size());
    String fileName = ActionRepo.getInstance().getLogFileDirectory() + "/LoadingQueryR4Bundle-" + launchDetails.getLaunchPatientId() + ".json";
    ApplicationUtils.saveDataToFile(context.newJsonParser().encodeResourceToString(bundle), fileName);
    return bundle;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) FhirContext(ca.uhn.fhir.context.FhirContext) Immunization(org.hl7.fhir.r4.model.Immunization) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter) MedicationStatement(org.hl7.fhir.r4.model.MedicationStatement)

Aggregations

Test (org.junit.Test)112 Medication (org.hl7.fhir.r4.model.Medication)62 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)43 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)34 Medication (org.hl7.fhir.dstu3.model.Medication)33 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)30 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)24 TokenParam (ca.uhn.fhir.rest.param.TokenParam)24 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)20 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)20 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)19 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)18 InputStream (java.io.InputStream)17 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)16 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)14 Coding (org.hl7.fhir.r4.model.Coding)14 Date (java.util.Date)13 ArrayList (java.util.ArrayList)12 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)11