use of org.openmrs.module.coreapps.parser.ParseEncounterToJson in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentController method getVisitDetails.
public SimpleObject getVisitDetails(@SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @InjectBeans CoreAppsProperties coreAppsProperties, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @SpringBean("encounterService") EncounterService encounterService, @RequestParam("visitId") Visit visit, @RequestParam(value = "fromEncounter", required = false) Integer encounterIndex, @RequestParam(value = "encounterCount", required = false) Integer encounterCount, UiUtils uiUtils, UiSessionContext sessionContext) throws ParseException {
if (encounterIndex == null)
encounterIndex = 0;
if (encounterCount == null) {
encounterCount = coreAppsProperties.getPatientDashboardEncounterCount();
}
ParseEncounterToJson parseEncounterToJson = new ParseEncounterToJson(appFrameworkService, uiUtils, encounterService);
SimpleObject simpleObject = SimpleObject.fromObject(visit, uiUtils, "id", "uuid", "location");
User authenticatedUser = sessionContext.getCurrentUser();
boolean canDeleteVisit = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_VISIT);
Date startDatetime = visit.getStartDatetime();
Date stopDatetime = visit.getStopDatetime();
simpleObject.put("startDatetime", uiUtils.format(startDatetime));
if (stopDatetime != null) {
simpleObject.put("stopDatetime", uiUtils.format(stopDatetime));
} else {
simpleObject.put("stopDatetime", null);
}
VisitDomainWrapper visitWrapper = new VisitDomainWrapper(visit, emrApiProperties);
List<SimpleObject> encounters = getEncounterListAsJson(parseEncounterToJson, visitWrapper, authenticatedUser, encounterIndex, encounterCount);
simpleObject.put("encounters", encounters);
simpleObject.put("admitted", visitWrapper.isAdmitted());
simpleObject.put("canDeleteVisit", verifyIfUserHasPermissionToDeleteVisit(visit, authenticatedUser, canDeleteVisit));
AppContextModel contextModel = sessionContext.generateAppContextModel();
contextModel.put("patient", new PatientContextModel(visit.getPatient()));
contextModel.put("visit", new VisitContextModel(new VisitDomainWrapper(visit, emrApiProperties)));
List<Extension> visitActions = appFrameworkService.getExtensionsForCurrentUser("patientDashboard.visitActions", contextModel);
Collections.sort(visitActions);
simpleObject.put("availableVisitActions", convertVisitActionsToSimpleObject(visitActions));
return simpleObject;
}
use of org.openmrs.module.coreapps.parser.ParseEncounterToJson in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentControllerTest method shouldReturnEncounterWithinBoundaries.
@Test
public void shouldReturnEncounterWithinBoundaries() {
ParseEncounterToJson parseEncounterToJson = mock(ParseEncounterToJson.class);
when(parseEncounterToJson.createEncounterJSON(any(User.class), any(Encounter.class))).thenReturn(new SimpleObject());
VisitDomainWrapper visitWrapper = mock(VisitDomainWrapper.class);
when(visitWrapper.getSortedEncounters()).thenReturn(getTestEncounterList(100));
VisitDetailsFragmentController controller = new VisitDetailsFragmentController();
List<SimpleObject> encounters;
encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 0, 50);
assertThat(encounters.size(), is(50));
encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 50, 50);
assertThat(encounters.size(), is(50));
encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 0, 200);
assertThat(encounters.size(), is(100));
encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 99, 25);
assertThat(encounters.size(), is(1));
encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 100, 25);
assertThat(encounters.isEmpty(), is(true));
}
Aggregations