use of org.openmrs.Location in project openmrs-core by openmrs.
the class BaseUnretireHandlerTest method handle_shouldUnsetTheRetiredBit.
/**
* @see BaseUnretireHandler#handle(Retireable,User,Date,String)
*/
@Test
public void handle_shouldUnsetTheRetiredBit() {
UnretireHandler<Retireable> handler = new BaseUnretireHandler();
Retireable retireable = new Location();
// make sure isRetired is set
retireable.setRetired(true);
handler.handle(retireable, null, null, null);
Assert.assertFalse(retireable.getRetired());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class OpenmrsMetadataSaveHandlerTest method handle_shouldTrimWhitespaceFromName.
/**
* @see OpenmrsMetadataSaveHandler#handle(OpenmrsMetadata,User,Date,String)
*/
@Test
public void handle_shouldTrimWhitespaceFromName() {
String NAME = "the location name";
OpenmrsMetadataSaveHandler handler = new OpenmrsMetadataSaveHandler();
Location loc = new Location();
loc.setName(" " + NAME + " ");
handler.handle(loc, null, null, null);
Assert.assertEquals(NAME, loc.getName());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class OpenmrsMetadataSaveHandlerTest method handle_shouldTrimWhitespaceFromDescription.
/**
* @see OpenmrsMetadataSaveHandler#handle(OpenmrsMetadata,User,Date,String)
*/
@Test
public void handle_shouldTrimWhitespaceFromDescription() {
String DESC = "the location desc";
OpenmrsMetadataSaveHandler handler = new OpenmrsMetadataSaveHandler();
Location loc = new Location();
loc.setName("a name");
loc.setDescription(" " + DESC + " ");
handler.handle(loc, null, null, null);
Assert.assertEquals(DESC, loc.getDescription());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class BaseOpenmrsDatatypeTest method serialize_shouldReturnTheUuidOfTheObject.
/**
* @see BaseOpenmrsDatatype#serialize(org.openmrs.OpenmrsObject)
*/
@Test
public void serialize_shouldReturnTheUuidOfTheObject() {
OpenmrsObject location = new Location();
String expectedUuid = "some uuid";
location.setUuid(expectedUuid);
BaseOpenmrsDatatype datatype = new MockLocationDatatype();
Assert.assertEquals(expectedUuid, datatype.serialize(location));
}
use of org.openmrs.Location in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentControllerTest method shouldReturnEncountersForVisit.
@Test
public void shouldReturnEncountersForVisit() throws ParseException {
CoreAppsProperties coreAppsProperties = mock(CoreAppsProperties.class);
when(coreAppsProperties.getPatientDashboardEncounterCount()).thenReturn(100);
UiSessionContext sessionContext = mock(UiSessionContext.class);
User authenticatedUser = new User();
when(sessionContext.getCurrentUser()).thenReturn(authenticatedUser);
AppContextModel appContextModel = new AppContextModel();
when(sessionContext.generateAppContextModel()).thenReturn(appContextModel);
authenticatedUser.addRole(createRoleForUser());
AdministrationService administrationService = mock(AdministrationService.class);
when(administrationService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATETIME_FORMAT)).thenReturn("dd.MMM.yyyy, HH:mm:ss");
AppFrameworkService appFrameworkService = mock(AppFrameworkService.class);
when(appFrameworkService.getExtensionsForCurrentUser(CoreAppsConstants.ENCOUNTER_TEMPLATE_EXTENSION)).thenReturn(generateMockEncounterTemplateExtensions());
EncounterService encounterService = mock(EncounterService.class);
Patient patient = mock(Patient.class);
when(patient.getPatientId()).thenReturn(1);
when(patient.isDead()).thenReturn(false);
Visit visit = new Visit();
Location visitLocation = new Location();
visitLocation.setName("Visit Location");
visit.setVisitId(1);
visit.setLocation(visitLocation);
visit.setStartDatetime(new Date());
visit.setStopDatetime(new Date());
visit.setCreator(authenticatedUser);
visit.setPatient(patient);
Location encounterLocation = new Location();
encounterLocation.setName("Location");
EncounterType encounterType = new EncounterType();
encounterType.setName("Encounter Type");
encounterType.setUuid(encounterTypeUuid);
Provider primaryProvider = new Provider();
primaryProvider.setName("Primary Provider");
EncounterProvider primaryEncounterProvider = new EncounterProvider();
primaryEncounterProvider.setProvider(primaryProvider);
EncounterRole primaryEncounterRole = new EncounterRole();
primaryEncounterRole.setUuid(primaryEncounterRoleUuid);
primaryEncounterProvider.setEncounterRole(primaryEncounterRole);
when(encounterService.getEncounterRoleByUuid(primaryEncounterRoleUuid)).thenReturn(primaryEncounterRole);
Provider secondaryProvider = new Provider();
secondaryProvider.setName("Secondary Provider");
EncounterProvider secondaryEncounterProvider = new EncounterProvider();
secondaryEncounterProvider.setProvider(secondaryProvider);
secondaryEncounterProvider.setEncounterRole(new EncounterRole());
Encounter encounter = new Encounter();
encounter.setEncounterId(7);
encounter.setEncounterDatetime(new Date());
encounter.setLocation(encounterLocation);
encounter.setEncounterType(encounterType);
encounter.setEncounterProviders(new LinkedHashSet<EncounterProvider>());
// add secondary provider so that it is the one that is "arbitrarily" returned first
encounter.getEncounterProviders().add(secondaryEncounterProvider);
encounter.getEncounterProviders().add(primaryEncounterProvider);
encounter.setCreator(authenticatedUser);
encounter.setDateCreated(new Date());
visit.addEncounter(encounter);
UiUtils uiUtils = new TestUiUtils(administrationService);
VisitDetailsFragmentController controller = new VisitDetailsFragmentController();
SimpleObject response = controller.getVisitDetails(mock(EmrApiProperties.class), coreAppsProperties, appFrameworkService, encounterService, visit, null, null, uiUtils, sessionContext);
List<SimpleObject> actualEncounters = (List<SimpleObject>) response.get("encounters");
SimpleObject actualEncounter = actualEncounters.get(0);
assertThat(response.get("startDatetime"), notNullValue());
assertThat(response.get("stopDatetime"), notNullValue());
assertThat((String) response.get("location"), is("Visit Location"));
assertThat(actualEncounters.size(), is(1));
assertThat((Integer) actualEncounter.get("encounterId"), is(7));
assertThat((String) actualEncounter.get("location"), is("Location"));
assertThat((SimpleObject) actualEncounter.get("encounterType"), isSimpleObjectWith("uuid", encounterType.getUuid(), "name", encounterType.getName()));
assertThat(actualEncounter.get("encounterDatetime"), notNullValue());
assertThat(actualEncounter.get("encounterDate"), notNullValue());
assertThat(actualEncounter.get("encounterTime"), notNullValue());
assertTrue((Boolean) actualEncounter.get("canEdit"));
assertThat((String) actualEncounter.get("primaryProvider"), is("Primary Provider"));
List<SimpleObject> actualProviders = (List<SimpleObject>) actualEncounter.get("encounterProviders");
assertThat(actualProviders.size(), is(2));
}
Aggregations