/** * @see PatientService#getAllergies(Patient) */ @Test public void getAllergyByUuid_shouldGetAllergyByUuid() { Allergy allergy = allergyService.getAllergyByUuid("21543629-7d8c-11e1-909d-c80aa9edcf4e"); Assert.assertNotNull(allergy); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ @Override public Allergy getByUniqueId(String uuid) { return Context.getPatientService().getAllergyByUuid(uuid); }
@Override public Allergy newObject() { return Context.getPatientService().getAllergyByUuid(RestTestConstants2_0.ALLERGY_UUID); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) */ @Override public Allergy save(Allergy newAllergy) { List<AllergyReaction> reactions = newAllergy.getReactions(); for (AllergyReaction reaction : reactions) { if (reaction.getAllergy() == null) { reaction.setAllergy(newAllergy); } } Context.getPatientService().saveAllergy(newAllergy); return Context.getPatientService().getAllergyByUuid(newAllergy.getUuid()); }
/** * Delete Allergy */ @Test public void shouldDeleteUniqueAllergy() throws Exception { Allergy allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Assert.assertFalse(allergy.isVoided()); // attempt to delete allergy handle(newDeleteRequest(getURI() + "/" + getUuid(), new Parameter("reason", "unit test"))); allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Assert.assertTrue(allergy.isVoided()); Assert.assertEquals("unit test", allergy.getVoidReason()); }
/** * Set No Known Allergies incorrectly using empty post body achieved with PUT with empty post * body when list of allergies is empty throw ResourceDoesNotSupportOperationException because * List of Allergies is not empty */ @Test(expected = ResourceDoesNotSupportOperationException.class) public void shouldThrowExceptionWhenSettingNoKnownAllergiesIfAllergiesNotEmpty() throws Exception { Allergy allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Patient patient = allergy.getPatient(); Allergies allergies = Context.getPatientService().getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); String json = "{}"; // attempt to set no known allergies with PUT handle(newPutRequest(getURI(), json)); }
/** * Delete all Allergies */ @Test public void shouldDeleteAllAllergies() throws Exception { Allergy allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Allergies allergies = Context.getPatientService().getAllergies(allergy.getPatient()); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertFalse(allergy.isVoided()); // attempt to delete all allergies handle(newDeleteRequest(getURI(), new Parameter("reason", "unit test"))); allergy = Context.getPatientService().getAllergyByUuid(getUuid()); allergies = Context.getPatientService().getAllergies(allergy.getPatient()); Assert.assertTrue(allergy.isVoided()); Assert.assertEquals("unit test", allergy.getVoidReason()); Assert.assertEquals(Allergies.UNKNOWN, allergies.getAllergyStatus()); }
@Test public void shouldGetAllergyByUuid() throws Exception { Allergy allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Patient patient = allergy.getPatient(); // attempt to get allergy by uuid SimpleObject savedAllergy = deserialize(handle(newGetRequest(getURI() + "/" + getUuid()))); Assert.assertEquals(allergy.getComment(), Util.getByPath(savedAllergy, "comment")); Assert.assertEquals(allergy.getSeverity().getUuid(), Util.getByPath(savedAllergy, "severity/uuid")); Assert.assertEquals(allergy.getAllergen().getCodedAllergen().getUuid(), Util.getByPath(savedAllergy, "allergen/codedAllergen/uuid")); Assert.assertEquals(allergy.getAllergen().getAllergenType().toString(), Util.getByPath(savedAllergy, "allergen/allergenType")); }
/** * Set No Known Allergies correctly using empty post body and List of Allergies is empty * achieved with PUT with empty post body when list of allergies is empty */ @Test public void shouldSetNoKnownAllergiesIfAllergiesEmpty() throws Exception { Allergy allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Patient patient = allergy.getPatient(); Allergies allergies = Context.getPatientService().getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); // delete existing allergies handle(newDeleteRequest(getURI(), new Parameter("reason", "unit test"))); allergies = Context.getPatientService().getAllergies(allergy.getPatient()); Assert.assertEquals(Allergies.UNKNOWN, allergies.getAllergyStatus()); String json = "{}"; // attempt to set no known allergies with PUT handle(newPutRequest(getURI(), json)); allergies = Context.getPatientService().getAllergies(patient); Assert.assertEquals(Allergies.NO_KNOWN_ALLERGIES, allergies.getAllergyStatus()); }
/** * Save Allergy with Allergy Reactions */ @Test public void shouldSaveAllergyWithReactions() throws Exception { Allergy allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Patient patient = allergy.getPatient(); Allergies allergies = Context.getPatientService().getAllergies(patient); Assert.assertEquals(allergies.size(), 4); // update allergy with reactions String json = "{ \"reactions\" : " + "[" + "{" + " \"allergy\" : { \"uuid\" : \"" + allergy.getUuid() + "\"}," + " \"reaction\" : { \"uuid\" : \"35d3346a-6769-4d52-823f-b4b234bac3e3\" }" + "}," + "{" + " \"allergy\" : { \"uuid\" : \"" + allergy.getUuid() + "\"}," + " \"reaction\" : { \"uuid\" : \"5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\" }," + " \"reactionNonCoded\" : \"test non coded reaction\"" + "}" + "]" + "}"; SimpleObject savedAllergy = deserialize(handle(newPostRequest(getURI() + "/" + allergy.getUuid(), json))); Assert.assertEquals("35d3346a-6769-4d52-823f-b4b234bac3e3", Util.getByPath(savedAllergy, "reactions[0]/reaction/uuid")); Assert.assertEquals("5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", Util.getByPath(savedAllergy, "reactions[1]/reaction/uuid")); Assert.assertEquals("test non coded reaction", Util.getByPath(savedAllergy, "reactions[1]/reactionNonCoded")); // assert that a allergy has been updated allergies = Context.getPatientService().getAllergies(patient); Assert.assertEquals(allergies.size(), 4); }
Allergy allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Patient patient = allergy.getPatient(); Allergies allergies = Context.getPatientService().getAllergies(patient);
Allergy allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Patient patient = allergy.getPatient(); Allergies allergies = Context.getPatientService().getAllergies(patient);
Allergy allergy = Context.getPatientService().getAllergyByUuid(getUuid()); Patient patient = allergy.getPatient(); Allergies allergies = Context.getPatientService().getAllergies(patient);