Search in sources :

Example 6 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel 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 7 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnTrueIfLocationHasTag.

@Test
public void shouldReturnTrueIfLocationHasTag() {
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", LocationTags.ADMISSION_LOCATION.name());
    sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
    PowerMockito.mockStatic(ConversionUtil.class);
    when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
    uiSessionContext.setSessionLocation(sessionLocation);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(sessionLocationHasTag(LocationTags.ADMISSION_LOCATION)), appContextModel), is(true));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Location(org.openmrs.Location) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnFalseIfVisitNotWithinPastThirtyDays.

@Test
public void shouldReturnFalseIfVisitNotWithinPastThirtyDays() {
    VisitContextModel visit = mock(VisitContextModel.class);
    when(visit.getStopDatetimeInMilliseconds()).thenReturn(new DateTime(2014, 1, 1, 1, 1).getMillis());
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    Config config = mock(Config.class);
    when(config.isComponentEnabled("visitNote")).thenReturn(false);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(patientVisitWithinPastThirtyDays(config)), appContextModel), is(false));
}
Also used : AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Config(org.openmrs.module.pihcore.config.Config) DateTime(org.joda.time.DateTime) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnFalseIfLocationDoesNotHaveTag.

@Test
public void shouldReturnFalseIfLocationDoesNotHaveTag() {
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", LocationTags.ADMISSION_LOCATION.name());
    sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
    PowerMockito.mockStatic(ConversionUtil.class);
    when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
    uiSessionContext.setSessionLocation(sessionLocation);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(sessionLocationHasTag(LocationTags.ARCHIVES_LOCATION)), appContextModel), is(false));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Location(org.openmrs.Location) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnFalseIfNotProperLocationTagAndUserHasRetroPrivilege.

@Test
public void shouldReturnFalseIfNotProperLocationTagAndUserHasRetroPrivilege() {
    user.addRole(admin);
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", LocationTags.ADMISSION_LOCATION.name());
    sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
    PowerMockito.mockStatic(ConversionUtil.class);
    when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
    VisitContextModel visit = mock(VisitContextModel.class);
    when(visit.getStopDatetimeInMilliseconds()).thenReturn(new DateTime(2014, 1, 1, 1, 1).getMillis());
    uiSessionContext.setSessionLocation(sessionLocation);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    Config config = mock(Config.class);
    when(config.isComponentEnabled("visitNote")).thenReturn(false);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag(LocationTags.CONSULT_NOTE_LOCATION), or(and(userHasPrivilege(Privileges.TASK_EMR_ENTER_CONSULT_NOTE), patientHasActiveVisit()), userHasPrivilege(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE), and(userHasPrivilege(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE_THIS_PROVIDER_ONLY), patientVisitWithinPastThirtyDays(config))))), appContextModel), is(false));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Config(org.openmrs.module.pihcore.config.Config) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AppContextModel (org.openmrs.module.appframework.context.AppContextModel)48 Test (org.junit.Test)39 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)38 Location (org.openmrs.Location)28 SimpleObject (org.openmrs.ui.framework.SimpleObject)27 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)20 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)16 Config (org.openmrs.module.pihcore.config.Config)16 DateTime (org.joda.time.DateTime)8 Extension (org.openmrs.module.appframework.domain.Extension)7 PatientContextModel (org.openmrs.module.coreapps.contextmodel.PatientContextModel)5 Date (java.util.Date)4 Patient (org.openmrs.Patient)4 Redirect (org.openmrs.ui.framework.page.Redirect)3 ArrayList (java.util.ArrayList)2 User (org.openmrs.User)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1