Search in sources :

Example 1 with ParseEncounterToJson

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;
}
Also used : Extension(org.openmrs.module.appframework.domain.Extension) ParseEncounterToJson(org.openmrs.module.coreapps.parser.ParseEncounterToJson) User(org.openmrs.User) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel)

Example 2 with ParseEncounterToJson

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));
}
Also used : ParseEncounterToJson(org.openmrs.module.coreapps.parser.ParseEncounterToJson) User(org.openmrs.User) SimpleObject(org.openmrs.ui.framework.SimpleObject) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Test(org.junit.Test)

Aggregations

User (org.openmrs.User)2 ParseEncounterToJson (org.openmrs.module.coreapps.parser.ParseEncounterToJson)2 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 Date (java.util.Date)1 Test (org.junit.Test)1 Encounter (org.openmrs.Encounter)1 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)1 Extension (org.openmrs.module.appframework.domain.Extension)1 PatientContextModel (org.openmrs.module.coreapps.contextmodel.PatientContextModel)1 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)1