use of org.openmrs.LocationTag in project openmrs-module-mirebalais by PIH.
the class PaperRecordServiceIT method shouldCreateTwoDifferentDossierNumbers.
@Test
@DirtiesContext
public void shouldCreateTwoDifferentDossierNumbers() throws Exception {
authenticate();
PatientIdentifierType patientIdentifierType = Context.getPatientService().getPatientIdentifierTypeByUuid("e66645eb-03a8-4991-b4ce-e87318e37566");
when(paperRecordProperties.getPaperRecordIdentifierType()).thenReturn(patientIdentifierType);
Location location = new Location(15);
LocationTag locationTag = new LocationTag(15);
locationTag.setName("tag");
location.addTag(locationTag);
when(paperRecordProperties.getMedicalRecordLocationLocationTag()).thenReturn(locationTag);
PaperRecord paperRecord1 = ((PaperRecordServiceImpl) paperRecordService).createPaperRecord(new Patient(), location);
assertTrue(paperRecord1.getPatientIdentifier().getIdentifier().matches("A\\d{6}"));
PaperRecord paperRecord2 = ((PaperRecordServiceImpl) paperRecordService).createPaperRecord(new Patient(), location);
assertTrue(paperRecord2.getPatientIdentifier().getIdentifier().matches("A\\d{6}"));
assertThat(paperRecord1.getPatientIdentifier().getIdentifier(), not(paperRecord2.getPatientIdentifier().getIdentifier()));
}
use of org.openmrs.LocationTag in project openmrs-module-pihcore by PIH.
the class LocationTagSetup method setLocationTagsFor.
private static void setLocationTagsFor(LocationService service, LocationTagDescriptor locationTag, Collection<LocationDescriptor> locationsThatGetTag) {
LocationTag tag = service.getLocationTagByUuid(locationTag.uuid());
for (Location candidate : service.getAllLocations()) {
boolean expected = false;
if (locationsThatGetTag != null) {
for (LocationDescriptor d : locationsThatGetTag) {
if (d != null && d.uuid().equals(candidate.getUuid())) {
expected = true;
}
}
}
boolean actual = candidate.hasTag(tag.getName());
if (actual && !expected) {
candidate.removeTag(tag);
service.saveLocation(candidate);
} else if (!actual && expected) {
candidate.addTag(tag);
service.saveLocation(candidate);
}
}
}
use of org.openmrs.LocationTag in project openmrs-module-pihcore by PIH.
the class PihCloseStaleVisitsTask method execute.
public void execute() {
AdtService adtService = Context.getService(AdtService.class);
VisitService visitService = Context.getVisitService();
LocationService locationService = Context.getLocationService();
LocationTag visitLocationTag = locationService.getLocationTagByName(EmrApiConstants.LOCATION_TAG_SUPPORTS_VISITS);
List<Location> locations = locationService.getLocationsByTag(visitLocationTag);
List<Visit> openVisits = visitService.getVisits(null, null, locations, null, null, null, null, null, null, false, false);
for (Visit visit : openVisits) {
if ((isOldEDVisit(adtService.wrap(visit), ED_VISIT_EXPIRE_VERY_OLD_TIME_IN_HOURS)) || (adtService.shouldBeClosed(visit) && !isActiveEDVisit(adtService.wrap(visit), ED_VISIT_EXPIRE_TIME_IN_HOURS)) || wasDischargedAndNotAdmitted(adtService.wrap(visit), HUM_VISIT_EXPIRE_TIME_IN_HOURS)) {
try {
adtService.closeAndSaveVisit(visit);
} catch (Exception ex) {
log.warn("Failed to close inactive visit " + visit, ex);
}
}
}
}
use of org.openmrs.LocationTag in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocationTag_shouldSetAuditInfoIfAnyItemInTheLocationTagIsEdited.
/**
* should set audit info if any item in the location tag is edited
*
* @see LocationService#saveLocationTag(LocationTag)
*/
@Test
public void saveLocationTag_shouldSetAuditInfoIfAnyItemInTheLocationTagIsEdited() {
LocationService ls = Context.getLocationService();
LocationTag tag = ls.getLocationTag(1);
Assert.assertNull(tag.getDateChanged());
Assert.assertNull(tag.getChangedBy());
tag.setName("testing");
tag.setDescription("desc");
LocationTag editedTag = Context.getLocationService().saveLocationTag(tag);
Context.flushSession();
Assert.assertNotNull(editedTag.getDateChanged());
Assert.assertNotNull(editedTag.getChangedBy());
}
use of org.openmrs.LocationTag in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocation_shouldAddLocationTagToLocation.
/**
* You should be able to add a tag to a location.
*
* @see LocationService#saveLocation(Location)
*/
@Test
public void saveLocation_shouldAddLocationTagToLocation() {
LocationService ls = Context.getLocationService();
// First, create a new Location
Location location = new Location();
location.setName("name");
location.setDescription("is a location");
ls.saveLocation(location);
// Create a tag
LocationTag tag = new LocationTag();
tag.setName("tag name");
ls.saveLocationTag(tag);
// Add tag to location
location.addTag(tag);
ls.saveLocation(location);
Location newSavedLocation = ls.getLocation(location.getLocationId());
// Saved parent location should have tags
assertNotNull("newSavedLocation.tags must be not null", newSavedLocation.getTags());
// Saved parent location should have exactly 1 tag
assertEquals(1, newSavedLocation.getTags().size());
// Tag must be the previously added object
assertTrue("Tag must be the previously added tag", newSavedLocation.getTags().iterator().next().equals(tag));
}
Aggregations