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"));
}
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"));
}
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"));
}
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
}
}
}
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));
}
Aggregations