/** * @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#getPatients(java.lang.String) */ @Override @Transactional(readOnly = true) public List<Patient> getPatients(String query) throws APIException { return Context.getPatientService().getPatients(query, 0, null); }
/** * @see org.openmrs.api.EncounterService#getEncountersByPatientIdentifier(java.lang.String) */ @Override @Transactional(readOnly = true) public List<Encounter> getEncountersByPatientIdentifier(String identifier) throws APIException { if (identifier == null) { throw new IllegalArgumentException("The 'identifier' parameter is required and cannot be null"); } List<Encounter> encs = new ArrayList<>(); for (Patient p : Context.getPatientService().getPatients(identifier, null, null, false)) { encs.addAll(Context.getEncounterService().getEncountersByPatientId(p.getPatientId())); } return Context.getEncounterService().filterEncountersByViewPermissions(encs, null); }
List<Patient> patients = ps.getPatients(searchString); List<Person> persons = new ArrayList<>(patients);
/** * @see PatientService#getPatients(String,String,List,boolean) */ @Test public void getPatients_shouldReturnEmptyListIfNameAndIdentifierIsEmpty() throws Exception { //given //when List<Patient> patients = patientService.getPatients("", "", null, false); //then Assert.assertTrue(patients.isEmpty()); }
@Test public void getPatients_shouldReturnOnlyPatients() { Person person = personService.getPerson(501); assertThat(person.getIsPatient(), is(false)); List<Patient> patients = patientService.getPatients(person.getGivenName()); assertThat(patients, is(empty())); }
@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)); }
types.add(new PatientIdentifierType(1)); List<Patient> patients = patientService.getPatients("4567", null, types, false); assertEquals(1, patients.size()); patients = patientService.getPatients("4567", null, null, false); assertTrue(patients.isEmpty()); patients = patientService.getPatients("4567", null, null, false, -2, -2); assertTrue(patients.isEmpty()); patients = patientService.getPatients("1234", null, null, false); assertEquals(1, patients.size()); patients = patientService.getPatients("00000001234", null, null, false); assertEquals(1, patients.size()); patients = patientService.getPatients("123", null, types, false); assertEquals(1, patients.size()); patients = patientService.getPatients("123", null, types, true); assertEquals(0, patients.size()); patients = patientService.getPatients("123", null, types, false); assertEquals(1, patients.size()); patients = patientService.getPatients("1234", null, types, false); assertEquals(0, patients.size()); patients = patientService.getPatients(null, "1234", types, false); assertEquals(0, patients.size());
/** * @see PatientService#getPatients(String) */ @Test public void getPatients_shouldForceSearchStringToBeGreaterThanMinsearchcharactersGlobalProperty() throws Exception { // make sure we can get patients with the default of 3 assertEquals(1, Context.getPatientService().getPatients("Colle").size()); Context.clearSession(); Context.getAdministrationService().saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MIN_SEARCH_CHARACTERS, "4")); assertEquals(0, Context.getPatientService().getPatients("Col").size()); }
/** * Gets the first patient, then sees if it can get that patient by its identifier as well * * @throws Exception */ @Test public void shouldGetPatientsByIdentifier() throws Exception { executeDataSet(CREATE_PATIENT_XML); updateSearchIndex(); // get the first patient Collection<Patient> johnPatients = patientService.getPatients("John", null, null, false); assertNotNull("There should be a patient named 'John'", johnPatients); assertFalse("There should be a patient named 'John'", johnPatients.isEmpty()); Patient firstJohnPatient = johnPatients.iterator().next(); // get a list of patients with this identifier, make sure the john // patient is actually there String identifier = firstJohnPatient.getPatientIdentifier().getIdentifier(); assertNotNull("Uh oh, the patient doesn't have an identifier", identifier); List<Patient> patients = patientService.getPatients(identifier, null, null, false); assertTrue("Odd. The firstJohnPatient isn't in the list of patients for this identifier", patients.contains(firstJohnPatient)); }
/** * @see PatientService#getPatients(String,Integer,Integer) */ @Test public void getPatients_shouldFindAPatientsWithAMatchingIdentifierWithNoDigits() throws Exception { final String identifier = "XYZ"; Patient patient = patientService.getPatient(2); Assert.assertEquals(0, patientService.getPatients(identifier, null, null).size()); PatientIdentifier pId = new PatientIdentifier(identifier, patientService.getPatientIdentifierType(5), locationService.getLocation(1)); patient.addIdentifier(pId); patientService.savePatient(patient); updateSearchIndex(); Assert.assertEquals(1, patientService.getPatients(identifier).size()); }
@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)); }
@Test public void getPatients_shouldReturnEmptyListWhenNoMatchIsFound() throws Exception { initializeInMemoryDatabase(); executeDataSet(CREATE_PATIENT_XML); authenticate(); List<Patient> patientList = patientService.getPatients(null, "???", null, false); assertNotNull("an empty list should be returned instead of a null object", patientList); assertEquals(0, patientList.size()); }
updateSearchIndex(); Collection<Patient> patients = patientService.getPatients("John", null, null, false);
/** * @see PatientService#getPatients(String) */ @Test public void getPatients_shouldAllowSearchStringToBeOneAccordingToMinsearchcharactersGlobalProperty() throws Exception { initializeInMemoryDatabase(); executeDataSet(FIND_PATIENTS_XML); updateSearchIndex(); // make sure the default of "2" kicks in and blocks any results assertEquals(0, Context.getPatientService().getPatients("J").size()); Context.clearSession(); Context.getAdministrationService().saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MIN_SEARCH_CHARACTERS, "1")); // there is a patient will middle name "F", so this should generate a hit. assertEquals(1, Context.getPatientService().getPatients("F").size()); }
@SkipBaseSetup @Test public void getPatients_shouldNotReturnVoidedPatients() throws Exception { initializeInMemoryDatabase(); executeDataSet(FIND_PATIENTS_XML); authenticate(); // verify patient is voided assertTrue(patientService.getPatient(3).getVoided()); // ask for list of patients with this name, expect none back because // patient is voided List<Patient> patients = patientService.getPatients("I am voided", null, null, false); assertEquals(patients.size(), 0); }
/** * @see PatientService#getPatients(String,String,List<QPatientIdentifierType ;>,null) */ @Test public void getPatients_shouldSearchFamilyName2WithName() throws Exception { executeDataSet("org/openmrs/api/include/PersonServiceTest-extranames.xml"); updateSearchIndex(); List<Patient> patients = patientService.getPatients("Johnson", null, null, false); Assert.assertEquals(3, patients.size()); Assert.assertTrue(TestUtil.containsId(patients, 2)); Assert.assertTrue(TestUtil.containsId(patients, 4)); Assert.assertTrue(TestUtil.containsId(patients, 5)); }
updateSearchIndex(); List<Patient> patients = patientService.getPatients("Jea", null, null, false); patients = patientService.getPatients("Claud", null, null, false);
/** * @see PatientService#getPatients(String, String, java.util.List, boolean) */ @Test public void getPatients_shouldSupportPatternUsingLastDigitAsCheckDigit() throws Exception { Context.getAdministrationService().saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_PATTERN, "@SEARCH@,0@SEARCH@,@SEARCH-1@-@CHECKDIGIT@,0@SEARCH-1@-@CHECKDIGIT@")); // "^(0*@SEARCH-1@-@CHECKDIGIT@)$")); 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("12344").size()); assertEquals(1, Context.getPatientService().getPatients("1234-4").size()); }
/** * @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()); }