Search in sources :

Example 21 with Medication

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

the class MedicationTranslatorImplTest method toFhirResource_shouldTranslateDrugIngredientToMedicationIngredient.

@Test
public void toFhirResource_shouldTranslateDrugIngredientToMedicationIngredient() {
    DrugIngredient ingredient = new DrugIngredient();
    Concept concept = new Concept();
    concept.setUuid(INGREDIENT_CONCEPT_UUID);
    ingredient.setIngredient(concept);
    drug.setIngredients(Collections.singleton((ingredient)));
    CodeableConcept codeableConcept = new CodeableConcept().addCoding(new Coding("", INGREDIENT_CONCEPT_UUID, ""));
    when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept);
    Medication medication = medicationTranslator.toFhirResource(drug);
    assertThat(medication, notNullValue());
    assertThat(medication.getIngredient().size(), greaterThanOrEqualTo(1));
    assertThat(medication.getIngredient().get(0).getItemCodeableConcept().getCoding().size(), greaterThanOrEqualTo(1));
    assertThat(medication.getIngredient().get(0).getItemCodeableConcept().getCoding().get(0).getCode(), equalTo(INGREDIENT_CONCEPT_UUID));
    assertThat(medication.getIngredient().get(0).getItemCodeableConcept().getText(), nullValue());
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) Coding(org.hl7.fhir.r4.model.Coding) Medication(org.hl7.fhir.r4.model.Medication) DrugIngredient(org.openmrs.DrugIngredient) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 22 with Medication

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

the class MedicationTranslatorImplTest method toFhirResource_shouldTranslateOpenMrsDateChangedToLastUpdatedDate.

@Test
public void toFhirResource_shouldTranslateOpenMrsDateChangedToLastUpdatedDate() {
    drug.setDateChanged(new Date());
    org.hl7.fhir.r4.model.Medication medication = medicationTranslator.toFhirResource(drug);
    assertThat(medication, notNullValue());
    assertThat(medication.getMeta().getLastUpdated(), DateMatchers.sameDay(new Date()));
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) Date(java.util.Date) Test(org.junit.Test)

Example 23 with Medication

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

the class MedicationTranslatorImplTest method toOpenmrsType_shouldTranslateMedicationIngredientsToDrugIngredients.

@Test
public void toOpenmrsType_shouldTranslateMedicationIngredientsToDrugIngredients() {
    CodeableConcept code = new CodeableConcept().addCoding(new Coding("", INGREDIENT_CONCEPT_UUID, ""));
    Medication medication = new Medication();
    Medication.MedicationIngredientComponent ingredient = new Medication.MedicationIngredientComponent();
    medication.addIngredient(ingredient.setItem(code));
    Concept ingredientConcept = new Concept();
    ingredientConcept.setUuid(INGREDIENT_CONCEPT_UUID);
    when(conceptTranslator.toOpenmrsType(code)).thenReturn(ingredientConcept);
    medicationTranslator.toOpenmrsType(drug, medication);
    assertThat(drug, notNullValue());
    assertThat(drug.getIngredients().size(), greaterThanOrEqualTo(1));
    assertThat(drug.getIngredients().iterator().next().getIngredient().getUuid(), equalTo(INGREDIENT_CONCEPT_UUID));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) Coding(org.hl7.fhir.r4.model.Coding) Medication(org.hl7.fhir.r4.model.Medication) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 24 with Medication

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

the class MedicationTranslatorImplTest method toFhirResource_shouldTranslateDosageConceptToMedicationForm.

@Test
public void toFhirResource_shouldTranslateDosageConceptToMedicationForm() {
    CodeableConcept code = new CodeableConcept().addCoding(new Coding("", DOSAGE_FORM_CONCEPT_UUID, ""));
    Concept dosageConcept = new Concept();
    dosageConcept.setUuid(DOSAGE_FORM_CONCEPT_UUID);
    when(conceptTranslator.toFhirResource(dosageConcept)).thenReturn(code);
    Medication medication = medicationTranslator.toFhirResource(drug);
    assertThat(medication, notNullValue());
    assertThat(medication.getForm().getCoding().size(), greaterThanOrEqualTo(1));
    assertThat(medication.getForm().getCoding().get(0).getCode(), equalTo(DOSAGE_FORM_CONCEPT_UUID));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) Coding(org.hl7.fhir.r4.model.Coding) Medication(org.hl7.fhir.r4.model.Medication) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 25 with Medication

use of org.hl7.fhir.r4.model.Medication in project elexis-server by elexis.

the class MedicationRequestTest method updateMedicationRequest.

@Test
public void updateMedicationRequest() {
    // load existing order
    Bundle results = client.search().forResource(MedicationRequest.class).where(MedicationRequest.PATIENT.hasId(patient.getId())).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    List<BundleEntryComponent> entries = results.getEntry();
    assertFalse(entries.isEmpty());
    Optional<MedicationRequest> activeOrder = getActiveOrderWithDosage(entries);
    assertTrue(activeOrder.isPresent());
    MedicationRequest updateOrder = activeOrder.get();
    updateOrder.getDosageInstruction().get(0).setText("test");
    List<Extension> entryTypes = updateOrder.getExtensionsByUrl("www.elexis.info/extensions/prescription/entrytype");
    assertEquals(EntryType.FIXED_MEDICATION.name(), ((CodeType) entryTypes.get(0).getValue()).getValue());
    entryTypes.get(0).setValue(new CodeType(EntryType.SYMPTOMATIC_MEDICATION.name()));
    // update the medication
    MethodOutcome outcome = client.update().resource(updateOrder).execute();
    // read and validate change
    MedicationRequest oldOrder = client.read().resource(MedicationRequest.class).withId(activeOrder.get().getId()).execute();
    assertNotNull(oldOrder);
    MedicationRequest newOrder = client.read().resource(MedicationRequest.class).withId(outcome.getId()).execute();
    assertNotNull(newOrder);
    assertEquals(MedicationRequestStatus.COMPLETED, oldOrder.getStatus());
    assertEquals(MedicationRequestStatus.ACTIVE, newOrder.getStatus());
    assertEquals("test", newOrder.getDosageInstruction().get(0).getText());
    entryTypes = newOrder.getExtensionsByUrl("www.elexis.info/extensions/prescription/entrytype");
    assertEquals(EntryType.SYMPTOMATIC_MEDICATION.name(), ((CodeType) entryTypes.get(0).getValue()).getValue());
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) CodeType(org.hl7.fhir.r4.model.CodeType) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Test(org.junit.Test)

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