Search in sources :

Example 11 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnFalseIfImproperLocationTagEventThoughUserHasConsultPrivilegeAndActiveVisit.

@Test
public void shouldReturnFalseIfImproperLocationTagEventThoughUserHasConsultPrivilegeAndActiveVisit() {
    user.addRole(doctor);
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", LocationTags.CHECKIN_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(null);
    when(visit.isActive()).thenReturn(true);
    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) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnTrueIfProperLocationTagAndUserHasConsultPrivilegeAndActiveVisit.

@Test
public void shouldReturnTrueIfProperLocationTagAndUserHasConsultPrivilegeAndActiveVisit() {
    user.addRole(doctor);
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", LocationTags.CONSULT_NOTE_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(null);
    when(visit.isActive()).thenReturn(true);
    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(true));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Config(org.openmrs.module.pihcore.config.Config) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnFalseIfProperLocationTagAndUserHasConsultPrivilegeButNoActiveVisit.

@Test
public void shouldReturnFalseIfProperLocationTagAndUserHasConsultPrivilegeButNoActiveVisit() {
    user.addRole(doctor);
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", LocationTags.CONSULT_NOTE_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(null);
    when(visit.isActive()).thenReturn(false);
    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) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnTrueIfVisitWithinPastThirtyDays.

@Test
public void shouldReturnTrueIfVisitWithinPastThirtyDays() {
    VisitContextModel visit = mock(VisitContextModel.class);
    when(visit.getStopDatetimeInMilliseconds()).thenReturn(new Date().getTime());
    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(true));
}
Also used : AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Config(org.openmrs.module.pihcore.config.Config) Date(java.util.Date) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnTrueIfProperLocationTagAndUserHasRetroPrivilegeThisProviderOnlyAndVisitInLastThirtyDays.

@Test
public void shouldReturnTrueIfProperLocationTagAndUserHasRetroPrivilegeThisProviderOnlyAndVisitInLastThirtyDays() {
    // doctor has last thirty days privilege
    user.addRole(doctor);
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", LocationTags.CONSULT_NOTE_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().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(true));
}
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)20 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)20 Test (org.junit.Test)16 Config (org.openmrs.module.pihcore.config.Config)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 Location (org.openmrs.Location)15 SimpleObject (org.openmrs.ui.framework.SimpleObject)13 DateTime (org.joda.time.DateTime)8 PatientContextModel (org.openmrs.module.coreapps.contextmodel.PatientContextModel)4 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)4 Date (java.util.Date)3 Extension (org.openmrs.module.appframework.domain.Extension)3 Redirect (org.openmrs.ui.framework.page.Redirect)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Patient (org.openmrs.Patient)1 User (org.openmrs.User)1 AppDescriptor (org.openmrs.module.appframework.domain.AppDescriptor)1 ParseEncounterToJson (org.openmrs.module.coreapps.parser.ParseEncounterToJson)1 PatientDomainWrapper (org.openmrs.module.emrapi.patient.PatientDomainWrapper)1