Search in sources :

Example 1 with DrugIngredient

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());
}
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 2 with DrugIngredient

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());
}
Also used : DrugIngredient(org.openmrs.DrugIngredient) BaseContextSensitiveTest(org.openmrs.test.jupiter.BaseContextSensitiveTest) Test(org.junit.jupiter.api.Test)

Example 3 with DrugIngredient

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));
}
Also used : Drug(org.openmrs.Drug) Concept(org.openmrs.Concept) DrugIngredient(org.openmrs.DrugIngredient) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 4 with DrugIngredient

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MedicationTranslator(org.openmrs.module.fhir2.api.translators.MedicationTranslator) Setter(lombok.Setter) ConceptTranslator(org.openmrs.module.fhir2.api.translators.ConceptTranslator) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Drug(org.openmrs.Drug) DrugIngredient(org.openmrs.DrugIngredient) Medication(org.hl7.fhir.r4.model.Medication) Component(org.springframework.stereotype.Component) AccessLevel(lombok.AccessLevel) StringType(org.hl7.fhir.r4.model.StringType) Optional(java.util.Optional) Extension(org.hl7.fhir.r4.model.Extension) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Nonnull(javax.annotation.Nonnull) LinkedHashSet(java.util.LinkedHashSet) Medication(org.hl7.fhir.r4.model.Medication) DrugIngredient(org.openmrs.DrugIngredient)

Example 5 with DrugIngredient

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;
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) DrugIngredient(org.openmrs.DrugIngredient)

Aggregations

DrugIngredient (org.openmrs.DrugIngredient)7 Medication (org.hl7.fhir.r4.model.Medication)3 Test (org.junit.Test)2 Concept (org.openmrs.Concept)2 Drug (org.openmrs.Drug)2 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 Optional (java.util.Optional)1 Nonnull (javax.annotation.Nonnull)1 AccessLevel (lombok.AccessLevel)1 Setter (lombok.Setter)1 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)1 Coding (org.hl7.fhir.r4.model.Coding)1 Extension (org.hl7.fhir.r4.model.Extension)1 StringType (org.hl7.fhir.r4.model.StringType)1 Test (org.junit.jupiter.api.Test)1 FhirConstants (org.openmrs.module.fhir2.FhirConstants)1 ConceptTranslator (org.openmrs.module.fhir2.api.translators.ConceptTranslator)1 MedicationTranslator (org.openmrs.module.fhir2.api.translators.MedicationTranslator)1 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)1