Search in sources :

Example 11 with AllergyIntolerance

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

the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldSearchForAllergiesByPatientUUID.

@Test
public void searchForAllergies_shouldSearchForAllergiesByPatientUUID() {
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam allergyParam = new ReferenceParam();
    allergyParam.setValue(PATIENT_UUID);
    allergyParam.setChain(null);
    referenceParam.addValue(new ReferenceOrListParam().add(allergyParam));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getPatient().getReferenceElement().getIdPart(), equalTo(PATIENT_UUID));
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 12 with AllergyIntolerance

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

the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldHandleComplexQuery.

@Test
public void searchForAllergies_shouldHandleComplexQuery() {
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam allergyParam = new ReferenceParam();
    allergyParam.setValue(PATIENT_UUID);
    allergyParam.setChain(null);
    referenceParam.addValue(new ReferenceOrListParam().add(allergyParam));
    TokenAndListParam status = new TokenAndListParam();
    status.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(STATUS)));
    TokenAndListParam category = new TokenAndListParam();
    category.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CATEGORY_ENVIRONMENT)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam).addParameter(FhirConstants.BOOLEAN_SEARCH_HANDLER, status).addParameter(FhirConstants.CATEGORY_SEARCH_HANDLER, category);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getClinicalStatus().getCodingFirstRep().getCode(), equalTo(STATUS));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getCategory().get(0).getValue(), equalTo(AllergyIntolerance.AllergyIntoleranceCategory.ENVIRONMENT));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getPatient().getReferenceElement().getIdPart(), equalTo(PATIENT_UUID));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 13 with AllergyIntolerance

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

the class AllergyIntoleranceTranslatorImplTest method toFhirResource_shouldTranslateDateCreatedToRecordedDate.

@Test
public void toFhirResource_shouldTranslateDateCreatedToRecordedDate() {
    omrsAllergy.setDateCreated(new Date());
    AllergyIntolerance allergyIntolerance = allergyIntoleranceTranslator.toFhirResource(omrsAllergy);
    assertThat(allergyIntolerance, notNullValue());
    assertThat(allergyIntolerance.getRecordedDate(), DateMatchers.sameDay(new Date()));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Date(java.util.Date) Test(org.junit.Test)

Example 14 with AllergyIntolerance

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

the class AllergyIntoleranceTranslatorImplTest method toOpenmrsType_shouldTranslateAllergenTypeEnvironmentCorrectly.

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

Example 15 with AllergyIntolerance

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

the class AllergyIntoleranceTranslatorImplTest method toFhirResource_shouldReturnNullNonCodedAllergenIfCodeTextIsNull.

@Test
public void toFhirResource_shouldReturnNullNonCodedAllergenIfCodeTextIsNull() {
    omrsAllergy.setAllergen(new Allergen(AllergenType.FOOD, null, null));
    AllergyIntolerance allergy = allergyIntoleranceTranslator.toFhirResource(omrsAllergy);
    assertThat(allergy.getCode(), notNullValue());
    assertThat(allergy.getCode().getText(), nullValue());
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Allergen(org.openmrs.Allergen) Test(org.junit.Test)

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