Search in sources :

Example 61 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParseEncounterToJsonTest method userShouldEditEncounterWhenHasPrivilegeButDidNotParticipatedInTheEncounter.

@Test
public void userShouldEditEncounterWhenHasPrivilegeButDidNotParticipatedInTheEncounter() {
    User user = new User();
    user.addRole(createRoleForUser());
    Encounter encounter = createEncounter();
    encounter.setCreator(new User());
    SimpleObject encounterJSON = parseEncounterToJson.createEncounterJSON(user, encounter);
    assertTrue((Boolean) encounterJSON.get("canEdit"));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 62 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParseEncounterToJsonTest method userShouldNotEditAnEncounterWhenDoesNotHaveThePrivilegeAndDidNotParticipatedInTheEncounter.

@Test
public void userShouldNotEditAnEncounterWhenDoesNotHaveThePrivilegeAndDidNotParticipatedInTheEncounter() {
    User user = new User();
    Encounter encounter = createEncounter();
    encounter.setCreator(new User());
    SimpleObject encounterJSON = parseEncounterToJson.createEncounterJSON(user, encounter);
    assertFalse((Boolean) encounterJSON.get("canEdit"));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 63 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParseEncounterToJsonTest method userShouldEditEncounterWhenHasPrivilegeAndParticipatedInTheEncounter.

@Test
public void userShouldEditEncounterWhenHasPrivilegeAndParticipatedInTheEncounter() {
    mockStatic(Context.class);
    when(Context.getAuthenticatedUser()).thenReturn(new User());
    User user = new User();
    user.addRole(createRoleForUser());
    user.setPerson(new Person());
    Encounter encounter = createEncounter();
    encounter.addProvider(new EncounterRole(5), createProvider(user));
    encounter.setCreator(new User());
    SimpleObject encounterJSON = parseEncounterToJson.createEncounterJSON(user, encounter);
    assertTrue((Boolean) encounterJSON.get("canEdit"));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 64 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-pihcore by PIH.

the class RequestMonitoringFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    long startTime = System.currentTimeMillis();
    chain.doFilter(request, response);
    long endTime = System.currentTimeMillis();
    long totalTime = endTime - startTime;
    if (enabled && request instanceof HttpServletRequest) {
        try {
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            HttpSession session = httpRequest.getSession();
            ISO8601DateFormat dateFormat = new ISO8601DateFormat();
            SimpleObject logLine = new SimpleObject();
            logLine.put("timestamp", dateFormat.format(new Date(startTime)));
            logLine.put("sessionId", session.getId());
            logLine.put("user", session.getAttribute("username"));
            logLine.put("loadTime", totalTime);
            logLine.put("method", httpRequest.getMethod());
            logLine.put("requestPath", httpRequest.getRequestURI());
            logLine.put("queryParams", formatRequestParams(httpRequest));
            logger.info(logLine.toJson());
        } catch (Exception e) {
        // Do nothing, we don't want this filter to cause any adverse behavior
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleObject(org.openmrs.ui.framework.SimpleObject) HttpSession(javax.servlet.http.HttpSession) ISO8601DateFormat(org.apache.log4j.helpers.ISO8601DateFormat) Date(java.util.Date) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 65 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-pihcore by PIH.

the class RequireUtilTest method shouldReturnTrueIfProperLocationTagAndUserHasRetroPrivilege.

@Test
public void shouldReturnTrueIfProperLocationTagAndUserHasRetroPrivilege() {
    user.addRole(admin);
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", "Consult Note Location");
    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("Consult Note Location"), or(and(userHasPrivilege(PihEmrConfigConstants.PRIVILEGE_TASK_EMR_ENTER_CONSULT_NOTE), patientHasActiveVisit()), userHasPrivilege(PihEmrConfigConstants.PRIVILEGE_TASK_EMR_RETRO_CLINICAL_NOTE), and(userHasPrivilege(PihEmrConfigConstants.PRIVILEGE_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

SimpleObject (org.openmrs.ui.framework.SimpleObject)67 Test (org.junit.Test)37 Location (org.openmrs.Location)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)26 ArrayList (java.util.ArrayList)18 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)17 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)13 Config (org.openmrs.module.pihcore.config.Config)12 DateTime (org.joda.time.DateTime)11 Date (java.util.Date)9 Encounter (org.openmrs.Encounter)9 Concept (org.openmrs.Concept)6 Patient (org.openmrs.Patient)6 Obs (org.openmrs.Obs)5 Visit (org.openmrs.Visit)5 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)3 ConceptSearchResult (org.openmrs.ConceptSearchResult)3 Form (org.openmrs.Form)3