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());
}
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()));
}
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));
}
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));
}
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());
}
Aggregations