/** * @see AllergyValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldRejectADuplicateAllergen() { PowerMockito.mockStatic(Context.class); MessageSourceService ms = mock(MessageSourceService.class); when(Context.getMessageSourceService()).thenReturn(ms); Allergies allergies = new Allergies(); Concept aspirin = createMockConcept(); Allergen allergen1 = new Allergen(AllergenType.DRUG, aspirin, null); allergies.add(new Allergy(null, allergen1, null, null, null)); when(ps.getAllergies(any(Patient.class))).thenReturn(allergies); Allergen duplicateAllergen = new Allergen(AllergenType.FOOD, aspirin, null); Allergy allergy = new Allergy(mock(Patient.class), duplicateAllergen, null, null, null); Errors errors = new BindException(allergy, "allergy"); validator.validate(allergy, errors); assertTrue(errors.hasFieldErrors("allergen")); assertThat(errors.getFieldError("allergen").getCode(), is("allergyapi.message.duplicateAllergen")); }
/** * @see AllergyValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldRejectADuplicateNonCodedAllergen() { PowerMockito.mockStatic(Context.class); MessageSourceService ms = mock(MessageSourceService.class); when(Context.getMessageSourceService()).thenReturn(ms); Allergies allergies = new Allergies(); Concept nonCodedConcept = createMockConcept(getOtherNonCodedConceptUuid()); final String freeText = "some text"; Allergen allergen1 = new Allergen(AllergenType.DRUG, nonCodedConcept, freeText); allergies.add(new Allergy(null, allergen1, null, null, null)); when(ps.getAllergies(any(Patient.class))).thenReturn(allergies); Allergen duplicateAllergen = new Allergen(AllergenType.FOOD, nonCodedConcept, freeText); Allergy allergy = new Allergy(mock(Patient.class), duplicateAllergen, null, null, null); Errors errors = new BindException(allergy, "allergy"); validator.validate(allergy, errors); assertTrue(errors.hasFieldErrors("allergen")); assertThat(errors.getFieldError("allergen").getCode(), is("allergyapi.message.duplicateAllergen")); }
Allergies existingAllergies = patientService.getAllergies(allergy.getPatient()); if (existingAllergies.containsAllergen(allergy)) { String key = "ui.i18n.Concept.name." + allergen.getCodedAllergen().getUuid();
/** * @see AllergyValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassForAValidAllergy() { Allergies allergies = new Allergies(); Concept aspirin = new Concept(); Allergen allergen1 = new Allergen(AllergenType.DRUG, aspirin, null); allergies.add(new Allergy(null, allergen1, null, null, null)); when(ps.getAllergies(any(Patient.class))).thenReturn(allergies); Allergen anotherAllergen = new Allergen(AllergenType.DRUG, new Concept(), null); Allergy allergy = new Allergy(mock(Patient.class), anotherAllergen, null, null, null); Errors errors = new BindException(allergy, "allergy"); validator.validate(allergy, errors); assertFalse(errors.hasErrors()); } }
/** * @see PatientService#getAllergies(Patient) */ @Test public void getAllergies_shouldGetTheAllergyListAndStatus() { //get a patient with some allergies Patient patient = allergyService.getPatient(2); Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); //should properly load reactions Assert.assertEquals(2, allergies.get(0).getReactions().size()); Assert.assertEquals(2, allergies.get(1).getReactions().size()); Assert.assertEquals(0, allergies.get(2).getReactions().size()); Assert.assertEquals(0, allergies.get(3).getReactions().size()); //get a patient without allergies patient = allergyService.getPatient(6); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.UNKNOWN, allergies.getAllergyStatus()); Assert.assertEquals(0, allergies.size()); }
/** * @see PatientService#setAllergies(Patient,Allergies) */ @Test public void setAllergies_shouldVoidAllAllergiesAndSetStatusToUnknownIfAllAllergiesAreRemoved() { //get a patient with some allergies Patient patient = allergyService.getPatient(2); Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); //remove all allergies while (allergies.size() > 0) { allergies.remove(0); } allergyService.setAllergies(patient, allergies); //all allergies should be voided and status set to unknown allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.UNKNOWN, allergies.getAllergyStatus()); Assert.assertEquals(0, allergies.size()); }
/** * @see PatientService#setAllergies(Patient,Allergies) */ @Test public void setAllergies_shouldSetStatusToNoKnownAllergiesForPatientWithoutAllergies() { //get a patient without any allergies Patient patient = allergyService.getPatient(7); Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.UNKNOWN, allergies.getAllergyStatus()); Assert.assertEquals(0, allergies.size()); //confirm that patient has no known allergies allergies = new Allergies(); allergies.confirmNoKnownAllergies(); allergyService.setAllergies(patient, allergies); //now the patient should have the no known allergies status allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.NO_KNOWN_ALLERGIES, allergies.getAllergyStatus()); Assert.assertEquals(0, allergies.size()); }
@Test public void setAllergies_shouldSetTheNonCodedConceptForNonCodedAllergenIfNotSpecified() { Patient patient = allergyService.getPatient(2); Allergen allergen = new Allergen(AllergenType.DRUG, null, "Some allergy name"); Allergy allergy = new Allergy(patient, allergen, null, null, null); Allergies allergies = allergyService.getAllergies(patient); allergies.add(allergy); allergyService.setAllergies(patient, allergies); Assert.assertFalse(allergy.getAllergen().isCoded()); } }
/** * @see PatientService#setAllergies(Patient,Allergies) */ @Test public void setAllergies_shouldVoidAllAllergiesAndSetStatusToNoKnownAllergiesIfAllAllergiesAreRemovedAndStatusSetAsSuch() { //get a patient with some allergies Patient patient = allergyService.getPatient(2); Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); //remove all allergies while (allergies.size() > 0) { allergies.remove(0); } //set the status to no known allergies allergies.confirmNoKnownAllergies(); allergyService.setAllergies(patient, allergies); //all allergies should be voided and status set to no known allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.NO_KNOWN_ALLERGIES, allergies.getAllergyStatus()); Assert.assertEquals(0, allergies.size()); }
Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size());
Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(3, allergies.size());
/** * @see PatientService#setAllergies(Patient,Allergies) */ @Test public void setAllergies_shouldSaveTheAllergyListAndStatus() { //get a patient without any allergies Patient patient = allergyService.getPatient(7); Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.UNKNOWN, allergies.getAllergyStatus()); Assert.assertEquals(0, allergies.size()); //save some allergies for this patient Allergen allergen = new Allergen(AllergenType.DRUG, new Concept(3), null); Concept severity = new Concept(4); Allergy allergy = new Allergy(patient, allergen, severity, "some comment", new ArrayList<>()); AllergyReaction reaction = new AllergyReaction(allergy, new Concept(21), null); allergy.addReaction(reaction); allergies = new Allergies(); allergies.add(allergy); allergyService.setAllergies(patient, allergies); //now the patient should have allergies and the correct allergy status allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(1, allergies.size()); Assert.assertEquals(1, allergies.get(0).getReactions().size()); }
Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size());
Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size());
Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size());
Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size());
Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size());
Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size());
Allergies allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size()); allergies = allergyService.getAllergies(patient); Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus()); Assert.assertEquals(4, allergies.size());
/** * 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)); }