Search in sources :

Example 31 with AllergyIntolerance

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

the class AllergyIntoleranceTranslatorImplTest method toOpenmrsType_shouldTranslateAllergenTypeDrugCorrectly.

@Test
public void toOpenmrsType_shouldTranslateAllergenTypeDrugCorrectly() {
    AllergyIntolerance allergy = new AllergyIntolerance();
    allergy.addCategory(AllergyIntolerance.AllergyIntoleranceCategory.MEDICATION);
    when(categoryTranslator.toOpenmrsType(allergy.getCategory().get(0).getValue())).thenReturn(AllergenType.DRUG);
    allergyIntoleranceTranslator.toOpenmrsType(omrsAllergy, allergy);
    assertThat(omrsAllergy, notNullValue());
    assertThat(omrsAllergy.getAllergen().getAllergenType(), equalTo(AllergenType.DRUG));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Test(org.junit.Test)

Example 32 with AllergyIntolerance

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

the class AllergyIntoleranceTranslatorImplTest method toFhirResource_shouldTranslateAllergyIntoleranceCategoryMedicationCorrectly.

@Test
public void toFhirResource_shouldTranslateAllergyIntoleranceCategoryMedicationCorrectly() {
    Allergen allergen = new Allergen();
    allergen.setAllergenType(AllergenType.DRUG);
    omrsAllergy.setAllergen(allergen);
    when(categoryTranslator.toFhirResource(omrsAllergy.getAllergen().getAllergenType())).thenReturn(AllergyIntolerance.AllergyIntoleranceCategory.MEDICATION);
    AllergyIntolerance allergyIntolerance = allergyIntoleranceTranslator.toFhirResource(omrsAllergy);
    assertThat(allergyIntolerance, notNullValue());
    assertThat(allergyIntolerance.getCategory().get(0).getValue(), equalTo(AllergyIntolerance.AllergyIntoleranceCategory.MEDICATION));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Allergen(org.openmrs.Allergen) Test(org.junit.Test)

Example 33 with AllergyIntolerance

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

the class AllergyIntoleranceResourceProvider method createAllergyIntolerance.

@Create
public MethodOutcome createAllergyIntolerance(@ResourceParam AllergyIntolerance allergyIntolerance) {
    MethodOutcome outcome = new MethodOutcome();
    Optional<IAllergyIntolerance> exists = getTransformer().getLocalObject(allergyIntolerance);
    if (exists.isPresent()) {
        outcome.setCreated(false);
        outcome.setId(new IdType(allergyIntolerance.getId()));
    } else {
        Optional<IAllergyIntolerance> created = getTransformer().createLocalObject(allergyIntolerance);
        if (created.isPresent()) {
            outcome.setCreated(true);
            outcome.setId(new IdType(created.get().getId()));
        } else {
            throw new InternalErrorException("Creation failed");
        }
    }
    return outcome;
}
Also used : IAllergyIntolerance(ch.elexis.core.findings.IAllergyIntolerance) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IdType(org.hl7.fhir.r4.model.IdType) Create(ca.uhn.fhir.rest.annotation.Create)

Example 34 with AllergyIntolerance

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

the class AllergyIntoleranceResourceProvider method findAllergyIntolerance.

@Search()
public List<AllergyIntolerance> findAllergyIntolerance(@RequiredParam(name = AllergyIntolerance.SP_PATIENT) IdType patientId) {
    if (patientId != null && !patientId.isEmpty()) {
        Optional<IPatient> patient = modelService.load(patientId.getIdPart(), IPatient.class);
        if (patient.isPresent()) {
            if (patient.get().isPatient()) {
                List<AllergyIntolerance> ret = new ArrayList<>();
                List<IAllergyIntolerance> findings = findingsService.getPatientsFindings(patientId.getIdPart(), IAllergyIntolerance.class);
                if (findings != null && !findings.isEmpty()) {
                    for (IAllergyIntolerance iFinding : findings) {
                        Optional<AllergyIntolerance> fhirAllergyIntolerance = getTransformer().getFhirObject(iFinding);
                        if (fhirAllergyIntolerance.isPresent()) {
                            ret.add(fhirAllergyIntolerance.get());
                        }
                    }
                }
                return ret;
            }
        }
    }
    return Collections.emptyList();
}
Also used : IAllergyIntolerance(ch.elexis.core.findings.IAllergyIntolerance) IAllergyIntolerance(ch.elexis.core.findings.IAllergyIntolerance) AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) ArrayList(java.util.ArrayList) IPatient(ch.elexis.core.model.IPatient) Search(ca.uhn.fhir.rest.annotation.Search)

Example 35 with AllergyIntolerance

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

the class AllergyIntoleranceFhirResourceProviderTest method initAllergyIntolerance.

@Before
public void initAllergyIntolerance() {
    allergyIntolerance = new AllergyIntolerance();
    allergyIntolerance.setId(ALLERGY_UUID);
    allergyIntolerance.addCategory(AllergyIntolerance.AllergyIntoleranceCategory.FOOD);
    setProvenanceResources(allergyIntolerance);
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)158 AllergyIntolerance (org.hl7.fhir.r4.model.AllergyIntolerance)93 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)53 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)53 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)43 AllergyIntolerance (org.hl7.fhir.dstu3.model.AllergyIntolerance)42 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)29 TokenParam (ca.uhn.fhir.rest.param.TokenParam)29 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)26 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)25 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)25 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)23 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)23 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)23 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)21 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)14 InputStream (java.io.InputStream)12 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)12 Date (java.util.Date)10 IdType (org.hl7.fhir.r4.model.IdType)10