@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()); } }
@Override protected Patient getObjectByUuid(String uuid) { return Context.getPatientService().getPatientByUuid(uuid); } }
@Override protected PatientIdentifierType getObjectByUuid(String uuid) { return Context.getPatientService().getPatientIdentifierTypeByUuid(uuid); } }
@Test public void getPatients_shouldFindIdentifierIgnoringCase() { Patient patient = patientService.getPatient(2); PatientIdentifier patientIdentifier = new PatientIdentifier("AS_567", patientService.getPatientIdentifierType(5), locationService.getLocation(1)); patient.addIdentifier(patientIdentifier); patientService.savePatient(patient); updateSearchIndex(); List<Patient> patients = patientService.getPatients("as_567"); assertThat(patients, contains(patient)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnFalseWhenPatientIdentifierContainsAPatientAndNoOtherPatientHasThisId() throws Exception { PatientIdentifierType pit = patientService.getPatientIdentifierType(1); PatientIdentifier patientIdentifier = new PatientIdentifier("Nobody could possibly have this identifier", pit, null); patientIdentifier.setPatient(patientService.getPatient(2)); Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier)); }
/** * @see PatientService#voidPatient(Patient,String) */ @Test public void voidPatient_shouldVoidPerson() throws Exception { //given Patient patient = patientService.getPatient(2); //when patientService.voidPatient(patient, "reason"); //then Assert.assertTrue(patient.getPersonVoided()); }
@Test public void savePatient_shouldUpdateTheDateChangedAndChangedByOnUpdateOfThePersonAddress() throws Exception { Patient patient = patientService.getPatient(2); PersonAddress address = patient.getAddresses().iterator().next(); address.setAddress1("Modified Address"); patientService.savePatient(patient); Context.evictFromSession(patient); patient = patientService.getPatient(2); PersonAddress personAddress = patient.getAddresses().iterator().next(); assertNotNull(personAddress.getDateChanged()); assertNotNull(personAddress.getChangedBy()); }
/** * @see PatientService#getPatient(Integer) */ @Test public void getPatient_shouldFetchPatientWithGivenPatientId() throws Exception { Patient patient = Context.getPatientService().getPatient(2); Assert.assertNotNull(patient); Assert.assertTrue(patient.getClass().isAssignableFrom(Patient.class)); }
/** * @see PatientService#getCountOfPatients(String) */ @Test public void getCountOfPatients_shouldReturnTheRightCountOfPatientsWithAMatchingIdentifierWithNoDigits() throws Exception { final String identifier = "XYZ"; Patient patient = patientService.getPatient(2); Assert.assertEquals(0, patientService.getCountOfPatients(identifier).intValue()); PatientIdentifier pId = new PatientIdentifier(identifier, patientService.getPatientIdentifierType(5), locationService.getLocation(1)); patient.addIdentifier(pId); patientService.savePatient(patient); updateSearchIndex(); Assert.assertEquals(1, patientService.getCountOfPatients(identifier).intValue()); }
PatientIdentifierType pit = Context.getPatientService().getPatientIdentifierTypeByName( assigningAuthority); if (pit == null) { Patient p = Context.getPatientService().getPatient(pid); if (p != null) { return p; continue; // skip identifiers with unknown type List<PatientIdentifier> matchingIds = Context.getPatientService().getPatientIdentifiers(hl7PersonId, Collections.singletonList(pit), null, null, null); if (matchingIds == null || matchingIds.isEmpty()) { log.debug("CX contains ID '" + hl7PersonId + "' without assigning authority -- assuming patient.patient_id"); return Context.getPatientService().getPatient(Integer.parseInt(hl7PersonId));
/** * @see PatientService#getPatients(String, String, java.util.List, boolean) */ @Test public void getPatients_shouldSupportSimpleRegex() throws Exception { Context.getAdministrationService().saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_REGEX, "^0*@SEARCH@([A-Z]+-[0-9])?$")); PatientIdentifier identifier = new PatientIdentifier("1234-4", new PatientIdentifierType(1), new Location(1)); identifier.setCreator(new User(1)); identifier.setDateCreated(new Date()); Patient patient = Context.getPatientService().getPatient(2); patient.addIdentifier(identifier); Context.getPatientService().savePatient(patient); updateSearchIndex(); assertEquals(1, Context.getPatientService().getPatients("1234-4").size()); }
@Test public void getPatients_shouldFindOnlySearchablePersonAttributes() { PersonAttributeType attributeType = personService.getPersonAttributeTypeByName("Birthplace"); attributeType.setSearchable(false); personService.savePersonAttributeType(attributeType); List<Patient> patients = patientService.getPatients("London"); assertThat(patients, is(empty())); attributeType = personService.getPersonAttributeTypeByName("Birthplace"); attributeType.setSearchable(true); personService.savePersonAttributeType(attributeType); patients = patientService.getPatients("London"); Patient patient = patientService.getPatient(2); assertThat(patients, contains(patient)); }
/** * @see PatientService#getCountOfPatients(String) */ @Test public void getCountOfPatients_shouldReturnTheRightCountWhenAPatientHasMultipleMatchingPersonNames() throws Exception { // TODO H2 cannot execute the generated SQL because it requires all // fetched columns to be included in the group by clause Patient patient = patientService.getPatient(2); // sanity check Assert.assertTrue(patient.getPersonName().getGivenName().startsWith("Horati")); // add a name that will match the search phrase patient.addName(new PersonName("Horatio", "Test", "name")); Context.getPatientService().savePatient(patient); Assert.assertEquals(1, Context.getPatientService().getCountOfPatients("Hor").intValue()); }
PatientIdentifierType idType = patientService.getPatientIdentifierTypeByName("Old Identification Number"); personAttribute.setValue(attributes.get(attribute)); patient.addAttribute(personAttribute); patientService.savePatient(patient); patientService.getPatients("Aaaaa"); //get Lucene up to speed... List<Patient> results = patientService.getPatients("Al"); time = System.currentTimeMillis() - time; System.out.println("Starts with search for 'Al' name returned " + results.size() + " in " + time + " ms"); results = patientService.getPatients("Al", 0, 15); time = System.currentTimeMillis() - time; System.out.println("Starts with search for 'Al' name limited to 15 results returned in " + time + " ms"); results = patientService.getPatients("Al Dem"); time = System.currentTimeMillis() - time; System.out.println("Starts with search for 'Al Dem' name returned " + results.size() + " in " + time + " ms"); results = patientService.getPatients("Al Dem", 0, 15); time = System.currentTimeMillis() - time; System.out.println("Starts with search for 'Al Dem' name limited to 15 results returned in " + time + " ms"); results = patientService.getPatients("Jack"); time = System.currentTimeMillis() - time; System.out.println("Starts with search for 'Jack' name returned " + results.size() + " in " + time + " ms"); results = patientService.getPatients("Jack", 0, 15);
/** * @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#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldVoidNonPreferredPersonObject() throws Exception { Patient notPreferred = patientService.getPatient(2); voidOrders(Collections.singleton(notPreferred)); Context.getPatientService().mergePatients(patientService.getPatient(6), notPreferred); Assert.assertTrue(Context.getPersonService().getPerson(2).getVoided()); }
/** * @see PatientService#getPatientIdentifierTypeByName(String) */ @Test public void getPatientIdentifierTypeByName_shouldReturnNullWhenPatientIdentifierTypeWithGivenNameDoesNotExist() throws Exception { PatientIdentifierType identifierType = Context.getPatientService().getPatientIdentifierTypeByName( "Invalid Identifier Example"); Assert.assertNull(identifierType); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ @Override public PatientIdentifierType getByUniqueId(String uniqueId) { PatientIdentifierType type = service().getPatientIdentifierTypeByUuid(uniqueId); if (type == null) type = service().getPatientIdentifierTypeByName(uniqueId); return type; }
/** * @see org.openmrs.api.PatientService#getPatients(java.lang.String, java.lang.String, * java.util.List, boolean) */ @Override // TODO - search for usage with non-empty list of patient identifier types @Transactional(readOnly = true) public List<Patient> getPatients(String name, String identifier, List<PatientIdentifierType> identifierTypes, boolean matchIdentifierExactly) throws APIException { return Context.getPatientService().getPatients(name, identifier, identifierTypes, matchIdentifierExactly, 0, null); }
/** * @see org.openmrs.api.PatientService#getAllPatients() */ @Override @Transactional(readOnly = true) public List<Patient> getAllPatients() throws APIException { return Context.getPatientService().getAllPatients(false); }