Search in sources :

Example 61 with AllergyIntolerance

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

the class AllergyIntoleranceFhirR3ResourceProviderWebTest method deleteAllergyIntolerance_shouldDeleteAllergyIntolerance.

@Test
public void deleteAllergyIntolerance_shouldDeleteAllergyIntolerance() throws Exception {
    org.hl7.fhir.r4.model.AllergyIntolerance allergyIntolerance = new org.hl7.fhir.r4.model.AllergyIntolerance();
    allergyIntolerance.setId(ALLERGY_UUID);
    when(allergyService.delete(any(String.class))).thenReturn(allergyIntolerance);
    MockHttpServletResponse response = delete("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 62 with AllergyIntolerance

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

the class AllergyIntoleranceFhirResourceProviderWebTest method shouldGetAllergyIntoleranceHistoryById.

@Test
public void shouldGetAllergyIntoleranceHistoryById() throws IOException, ServletException {
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    provenance.setRecorded(new Date());
    provenance.setActivity(new CodeableConcept().addCoding(new Coding().setCode("CREATE").setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION).setDisplay("create")));
    provenance.addAgent(new Provenance.ProvenanceAgentComponent().setType(new CodeableConcept().addCoding(new Coding().setCode(FhirConstants.AUT).setDisplay(FhirConstants.AUTHOR).setSystem(FhirConstants.FHIR_TERMINOLOGY_PROVENANCE_PARTICIPANT_TYPE))).addRole(new CodeableConcept().addCoding(new Coding().setCode("").setDisplay("").setSystem(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE))));
    AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
    allergyIntolerance.setId(ALLERGY_UUID);
    allergyIntolerance.addContained(provenance);
    when(allergyService.get(ALLERGY_UUID)).thenReturn(allergyIntolerance);
    MockHttpServletResponse response = getAllergyIntoleranceHistoryRequest();
    Bundle results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.hasEntry(), is(true));
    assertThat(results.getEntry().get(0).getResource(), notNullValue());
    assertThat(results.getEntry().get(0).getResource().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Coding(org.hl7.fhir.r4.model.Coding) Bundle(org.hl7.fhir.r4.model.Bundle) Date(java.util.Date) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) IdType(org.hl7.fhir.r4.model.IdType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) BaseFhirResourceProviderWebTest(org.openmrs.module.fhir2.providers.BaseFhirResourceProviderWebTest) Test(org.junit.Test)

Example 63 with AllergyIntolerance

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

the class AllergyIntoleranceFhirResourceProviderWebTest method updateAllergyIntolerance_shouldThrowErrorForNonexistentMedication.

@Test
public void updateAllergyIntolerance_shouldThrowErrorForNonexistentMedication() throws Exception {
    String createAllergyJson;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_WITH_WRONGID_ALLERGY_PATH)) {
        Objects.requireNonNull(is);
        createAllergyJson = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    when(allergyService.update(eq(WRONG_ALLERGY_UUID), any(AllergyIntolerance.class))).thenThrow(new MethodNotAllowedException("AllergyIntolerance " + WRONG_ALLERGY_UUID + " does not exist"));
    MockHttpServletResponse response = put("/AllergyIntolerance/" + WRONG_ALLERGY_UUID).jsonContent(createAllergyJson).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isMethodNotAllowed());
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) MethodNotAllowedException(ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BaseFhirResourceProviderWebTest(org.openmrs.module.fhir2.providers.BaseFhirResourceProviderWebTest) Test(org.junit.Test)

Example 64 with AllergyIntolerance

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

the class AllergyIntoleranceFhirResourceProviderWebTest method getAllergyIntoleranceHistoryById_shouldReturnBundleWithEmptyEntriesIfResourceContainedIsEmpty.

@Test
public void getAllergyIntoleranceHistoryById_shouldReturnBundleWithEmptyEntriesIfResourceContainedIsEmpty() throws Exception {
    AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
    allergyIntolerance.setId(ALLERGY_UUID);
    allergyIntolerance.setContained(new ArrayList<>());
    when(allergyService.get(ALLERGY_UUID)).thenReturn(allergyIntolerance);
    MockHttpServletResponse response = getAllergyIntoleranceHistoryRequest();
    Bundle results = readBundleResponse(response);
    assertThat(results.hasEntry(), is(false));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BaseFhirResourceProviderWebTest(org.openmrs.module.fhir2.providers.BaseFhirResourceProviderWebTest) Test(org.junit.Test)

Example 65 with AllergyIntolerance

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

the class AllergyIntoleranceFhirResourceProviderWebTest method setup.

@Before
@Override
public void setup() throws ServletException {
    allergyProvider = new AllergyIntoleranceFhirResourceProvider();
    allergyProvider.setFhirAllergyIntoleranceService(allergyService);
    allergyIntolerance = new AllergyIntolerance();
    allergyIntolerance.setId(ALLERGY_UUID);
    super.setup();
}
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