/** * @return current location for this user context if any is set * @since 1.9 */ public Location getLocation() { if (locationId == null) { return null; } return Context.getLocationService().getLocation(locationId); }
private Location getDefaultLocationFromSting(Location location, String locationGP, String defaultLocation) { Location result = null; if (location == null && (!StringUtils.hasText(locationGP) || !defaultLocation.equalsIgnoreCase(locationGP))) { result = Context.getLocationService().getLocation(defaultLocation); } return result; }
@Override protected Location getExistingObject() { return locationService.getLocation(EXISTING_ID); } }
@Override protected Location getObjectById(Integer id) { return Context.getLocationService().getLocation(id); }
/** * @see org.openmrs.Attributable#hydrate(java.lang.String) */ @Override public Location hydrate(String locationId) { try { return Context.getLocationService().getLocation(Integer.valueOf(locationId)); } catch (Exception e) { return new Location(); } }
@Test public void getPatientIdentifiers_shouldLimitByResultsByLocation() { Location location = Context.getLocationService().getLocation(3); // there is only one identifier in the test database for location 3 List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<>(), Collections.singletonList(location), new ArrayList<>(), null); Assert.assertEquals(1, patientIdentifiers.size()); Assert.assertEquals("12345K", patientIdentifiers.get(0).getIdentifier()); }
/** * Make sure that purging a location removes the row from the database * * @see LocationService#purgeLocation(Location) */ @Test public void purgeLocation_shouldDeleteLocationSuccessfully() { LocationService ls = Context.getLocationService(); // fetch the encounter to delete from the db Location locationToDelete = ls.getLocation(4); ls.purgeLocation(locationToDelete); // try to refetch the location. should get a null object Location l = ls.getLocation(locationToDelete.getLocationId()); assertNull("We shouldn't find the location after deletion", l); }
/** * @see org.openmrs.api.db.EncounterDAO#getSavedEncounterLocation(org.openmrs.Encounter) */ @Override public Location getSavedEncounterLocation(Encounter encounter) { Session session = sessionFactory.getCurrentSession(); FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.MANUAL); try { SQLQuery sql = session.createSQLQuery("select location_id from encounter where encounter_id = :encounterId"); sql.setInteger("encounterId", encounter.getEncounterId()); return Context.getLocationService().getLocation((Integer) sql.uniqueResult()); } finally { session.setFlushMode(flushMode); } }
/** * @see LocationService#getLocation(String) */ @Test public void getLocation_shouldReturnNullWhenNoLocationMatchGivenLocationName() { Assert.assertNull(Context.getLocationService().getLocation("Princeton Plainsboro")); }
private Location getLocation(PV1 pv1) throws HL7Exception { PL hl7Location = pv1.getAssignedPatientLocation(); Integer locationId = Context.getHL7Service().resolveLocationId(hl7Location); if (locationId == null) { throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedLocation")); } return Context.getLocationService().getLocation(locationId); }
/** * @see LocationService#getLocation(Integer) */ @Test public void getLocation_shouldReturnNullWhenNoLocationMatchGivenLocationId() { Assert.assertNull(Context.getLocationService().getLocation(1337)); }
/** * You should be able to remove a tag from a location. * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldRemoveLocationTagFromLocation() { LocationService ls = Context.getLocationService(); // Loading location with exactly 3 tags from the initialData.xml file Location location = ls.getLocation(1); // Removing a tag location.removeTag(location.getTags().iterator().next()); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); // Saved location should have 2 tag now assertEquals(2, newSavedLocation.getTags().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)); }
/** * @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()); }
/** * @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()); }
@Test(expected = ConceptInUseException.class) public void saveConcept_shouldNotUpdateConceptDataTypeIfConceptIsAttachedToAnObservation() { executeDataSet(INITIAL_CONCEPTS_XML); Concept concept = conceptService.getConcept(2); assertNotNull(concept); ObsService obsService = Context.getObsService(); Obs obs = new Obs(Context.getPersonService().getPerson(1), concept, new Date(), Context.getLocationService() .getLocation(1)); obs.setValueCoded(Context.getConceptService().getConcept(7)); obsService.saveObs(obs, "Creating a new observation with a concept"); ConceptDatatype newDatatype = conceptService.getConceptDatatypeByName("Text"); concept.setDatatype(newDatatype); conceptService.saveConcept(concept); }
private Encounter buildEncounter() { // First, create a new Encounter Encounter enc = new Encounter(); enc.setLocation(Context.getLocationService().getLocation(1)); enc.setEncounterType(Context.getEncounterService().getEncounterType(1)); enc.setEncounterDatetime(new Date()); enc.setPatient(Context.getPatientService().getPatient(3)); enc.addProvider(Context.getEncounterService().getEncounterRole(1), Context.getProviderService().getProvider(1)); return enc; }
/** * @see LocationService#unretireLocation(Location) */ @Test public void unretireLocation_shouldUnretireRetiredLocation() { LocationService ls = Context.getLocationService(); Location loc = ls.getLocation("Test Retired Location"); Assert.assertTrue(loc.getRetired()); Location newLoc = ls.unretireLocation(loc); Assert.assertEquals(loc, newLoc); Assert.assertFalse(loc.getRetired()); Assert.assertNull(loc.getRetiredBy()); Assert.assertNull(loc.getRetireReason()); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnFalseIfInUseForAnotherLocationAndIdUniquenessIsSetToLocation() throws Exception { PatientIdentifier duplicateId = patientService.getPatientIdentifier(1); Assert.assertNotNull(duplicateId.getLocation()); PatientIdentifierType idType = duplicateId.getIdentifierType(); idType.setUniquenessBehavior(UniquenessBehavior.LOCATION); patientService.savePatientIdentifierType(idType); Location idLocation = locationService.getLocation(2); Assert.assertNotSame(idLocation, duplicateId.getLocation());//sanity check PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, idLocation); Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(pi)); }
/** * @see VisitService#saveVisit(Visit) */ @Test public void saveVisit_shouldUpdateAnExistingVisitInTheDatabase() { Visit visit = visitService.getVisit(2); assertNull(visit.getLocation());//this is the field we are editing assertNull(visit.getChangedBy()); assertNull(visit.getDateChanged()); visit.setLocation(Context.getLocationService().getLocation(1)); visit = visitService.saveVisit(visit); Context.flushSession(); assertNotNull(visit.getChangedBy()); assertNotNull(visit.getDateChanged()); assertEquals(Integer.valueOf(1), visit.getLocation().getLocationId()); }