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()));
}
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()));
}
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());
}
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));
}
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();
}
Aggregations