use of org.openmrs.DrugIngredient 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.openmrs.DrugIngredient in project openmrs-core by openmrs.
the class ConceptServiceTest method getDrugIngredientByUuid_shouldFindObjectGivenValidUuid.
/**
* @see {@link ConceptService#getDrugIngredientByUuid(String)}
*/
@Test
public void getDrugIngredientByUuid_shouldFindObjectGivenValidUuid() {
String uuid = "6519d653-393d-4118-9c83-a3715b82d4dc";
DrugIngredient ingredient = Context.getConceptService().getDrugIngredientByUuid(uuid);
assertEquals(88, (int) ingredient.getIngredient().getConceptId());
}
use of org.openmrs.DrugIngredient in project openmrs-module-fhir2 by openmrs.
the class FhirMedicationDaoImplTest method saveMedication_shouldSaveNewMedication.
@Test
public void saveMedication_shouldSaveNewMedication() {
Drug drug = new Drug();
drug.setUuid(NEW_MEDICATION_UUID);
Concept concept = fhirConceptDao.get(NEW_CONCEPT_UUID);
drug.setConcept(concept);
DrugIngredient ingredient = new DrugIngredient();
ingredient.setUuid(INGREDIENT_UUID);
ingredient.setIngredient(concept);
drug.setIngredients(Collections.singleton(ingredient));
Drug result = medicationDao.createOrUpdate(drug);
assertThat(result, notNullValue());
assertThat(result.getUuid(), equalTo(NEW_MEDICATION_UUID));
assertThat(result.getIngredients().size(), greaterThanOrEqualTo(1));
assertThat(result.getIngredients().iterator().next().getUuid(), equalTo(INGREDIENT_UUID));
}
use of org.openmrs.DrugIngredient in project openmrs-module-fhir2 by openmrs.
the class MedicationTranslatorImpl method toOpenmrsType.
@Override
public Drug toOpenmrsType(@Nonnull Drug existingDrug, @Nonnull Medication medication) {
if (existingDrug == null || medication == null) {
return null;
}
if (medication.getId() != null) {
existingDrug.setUuid(medication.getId());
}
if (medication.hasCode()) {
existingDrug.setConcept(conceptTranslator.toOpenmrsType(medication.getCode()));
}
if (medication.hasForm()) {
existingDrug.setConcept(conceptTranslator.toOpenmrsType(medication.getForm()));
}
Collection<DrugIngredient> ingredients = new LinkedHashSet<>();
if (medication.hasIngredient()) {
for (Medication.MedicationIngredientComponent ingredient : medication.getIngredient()) {
DrugIngredient omrsIngredient = new DrugIngredient();
omrsIngredient.setDrug(existingDrug);
omrsIngredient.setIngredient(conceptTranslator.toOpenmrsType(ingredient.getItemCodeableConcept()));
ingredients.add(omrsIngredient);
}
existingDrug.setIngredients(ingredients);
}
getOpenmrsMedicineExtension(medication).ifPresent(ext -> ext.getExtension().forEach(e -> addMedicineComponent(existingDrug, e.getUrl(), ((StringType) e.getValue()).getValue())));
return existingDrug;
}
use of org.openmrs.DrugIngredient in project openmrs-module-fhir2 by openmrs.
the class MedicationTranslatorImpl method toFhirResource.
@Override
public Medication toFhirResource(@Nonnull Drug drug) {
if (drug == null) {
return null;
}
Medication medication = new Medication();
medication.setId(drug.getUuid());
medication.setCode(conceptTranslator.toFhirResource(drug.getConcept()));
medication.setForm(conceptTranslator.toFhirResource(drug.getDosageForm()));
if (drug.getIngredients() != null) {
for (DrugIngredient val : drug.getIngredients()) {
Medication.MedicationIngredientComponent ingredient = new Medication.MedicationIngredientComponent();
medication.addIngredient(ingredient.setItem(conceptTranslator.toFhirResource(val.getIngredient())));
}
}
medication.getMeta().setLastUpdated(drug.getDateChanged());
medication.setStatus(Medication.MedicationStatus.ACTIVE);
if (drug.getMaximumDailyDose() != null) {
addMedicineExtension(medication, "maximumDailyDose", drug.getMaximumDailyDose().toString());
}
if (drug.getMinimumDailyDose() != null) {
addMedicineExtension(medication, "minimumDailyDose", drug.getMinimumDailyDose().toString());
}
if (drug.getStrength() != null) {
addMedicineExtension(medication, "strength", drug.getStrength());
}
return medication;
}
Aggregations