Search in sources :

Example 36 with AppContextModel

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

the class RequireUtilTest method shouldReturnFalseIfVisitNotActive.

@Test
public void shouldReturnFalseIfVisitNotActive() {
    VisitDomainWrapper visit = mock(VisitDomainWrapper.class);
    when(visit.isActive()).thenReturn(false);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(patientHasActiveVisit()), appContextModel), is(false));
}
Also used : AppContextModel(org.openmrs.module.appframework.context.AppContextModel) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-mirebalais 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", 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(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(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)

Example 38 with AppContextModel

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

the class RequireUtilTest method shouldReturnTrueIfLocationHasTagAndVisitActive.

@Test
public void shouldReturnTrueIfLocationHasTagAndVisitActive() {
    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);
    VisitDomainWrapper visit = mock(VisitDomainWrapper.class);
    when(visit.isActive()).thenReturn(true);
    uiSessionContext.setSessionLocation(sessionLocation);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag(LocationTags.ADMISSION_LOCATION), patientHasActiveVisit())), appContextModel), is(true));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Location(org.openmrs.Location) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with AppContextModel

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

the class MergePatientsPageController method post.

public String post(UiUtils ui, HttpServletRequest request, PageModel pageModel, @RequestParam("patient1") Patient patient1, @RequestParam("patient2") Patient patient2, @RequestParam("preferred") Patient preferred, @RequestParam(value = "isUnknownPatient", defaultValue = "false") boolean isUnknownPatient, @InjectBeans PatientDomainWrapper preferredWrapper, @InjectBeans PatientDomainWrapper notPreferredWrapper, @RequestParam("app") AppDescriptor app, @SpringBean("appframeworkTemplateFactory") TemplateFactory templateFactory, UiSessionContext sessionContext, @SpringBean("adtService") AdtService adtService) {
    Patient notPreferred = patient1.equals(preferred) ? patient2 : patient1;
    preferredWrapper.setPatient(preferred);
    notPreferredWrapper.setPatient(notPreferred);
    if (preferredWrapper.isUnknownPatient() && !notPreferredWrapper.isUnknownPatient()) {
        request.getSession().setAttribute("emr.errorMessage", ui.message("coreapps.mergePatients.unknownPatient.error"));
        preferredWrapper.setPatient(patient1);
        notPreferredWrapper.setPatient(patient2);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("app", "coreapps.mergePatients");
        params.put("patient1", preferred);
        params.put("patient2", notPreferred);
        params.put("isUnknownPatient", isUnknownPatient);
        return "redirect:" + ui.pageLink("coreapps", "datamanagement/mergePatients", params);
    }
    adtService.mergePatients(preferred, notPreferred);
    request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, "coreapps.mergePatients.success");
    request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
    String provider = "coreapps";
    String fragment = "patientdashboard/patientDashboard";
    String returnUrl = null;
    if (app.getConfig() != null && app.getConfig().get("dashboardUrl") != null) {
        returnUrl = app.getConfig().get("dashboardUrl").getTextValue();
    }
    if (StringUtils.isNotBlank(returnUrl)) {
        AppContextModel contextModel = sessionContext.generateAppContextModel();
        contextModel.put("patientId", preferred.getId());
        returnUrl = templateFactory.handlebars(returnUrl, contextModel);
    } else {
        returnUrl = ui.pageLink(provider, fragment, SimpleObject.create("patientId", preferred.getId()));
    }
    return "redirect:" + returnUrl;
}
Also used : AppContextModel(org.openmrs.module.appframework.context.AppContextModel) HashMap(java.util.HashMap) Patient(org.openmrs.Patient) SimpleObject(org.openmrs.ui.framework.SimpleObject)

Example 40 with AppContextModel

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

the class PatientHeaderFragmentController method controller.

public void controller(FragmentConfiguration config, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, @SpringBean("baseIdentifierSourceService") IdentifierSourceService identifierSourceService, @FragmentParam(required = false, value = "appContextModel") AppContextModel appContextModel, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @FragmentParam("patient") Object patient, @InjectBeans PatientDomainWrapper wrapper, @SpringBean("adtService") AdtService adtService, UiSessionContext sessionContext, UiUtils uiUtils, FragmentModel model) {
    if (patient instanceof Patient) {
        wrapper.setPatient((Patient) patient);
    } else {
        wrapper = (PatientDomainWrapper) patient;
    }
    config.addAttribute("patient", wrapper);
    config.addAttribute("patientNames", getNames(wrapper.getPersonName()));
    if (appContextModel == null) {
        AppContextModel contextModel = sessionContext.generateAppContextModel();
        contextModel.put("patient", new PatientContextModel(wrapper.getPatient()));
        model.addAttribute("appContextModel", contextModel);
    }
    List<Extension> firstLineFragments = appFrameworkService.getExtensionsForCurrentUser("patientHeader.firstLineFragments");
    Collections.sort(firstLineFragments);
    model.addAttribute("firstLineFragments", firstLineFragments);
    List<Extension> secondLineFragments = appFrameworkService.getExtensionsForCurrentUser("patientHeader.secondLineFragments");
    Collections.sort(secondLineFragments);
    model.addAttribute("secondLineFragments", secondLineFragments);
    List<ExtraPatientIdentifierType> extraPatientIdentifierTypes = new ArrayList<ExtraPatientIdentifierType>();
    for (PatientIdentifierType type : emrApiProperties.getExtraPatientIdentifierTypes()) {
        List<AutoGenerationOption> options = identifierSourceService.getAutoGenerationOptions(type);
        // TODO note that this may allow use to edit a identifier that should not be editable, or vice versa, in the rare case where there are multiple autogeneration
        // TODO options for a single identifier type (which is possible if you have multiple locations) and the manual entry boolean is different between those two generators
        extraPatientIdentifierTypes.add(new ExtraPatientIdentifierType(type, options.size() > 0 ? options.get(0).isManualEntryEnabled() : true));
    }
    config.addAttribute("extraPatientIdentifierTypes", extraPatientIdentifierTypes);
    config.addAttribute("extraPatientIdentifiersMappedByType", wrapper.getExtraIdentifiersMappedByType(sessionContext.getSessionLocation()));
    config.addAttribute("dashboardUrl", coreAppsProperties.getDashboardUrl());
}
Also used : Extension(org.openmrs.module.appframework.domain.Extension) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) AutoGenerationOption(org.openmrs.module.idgen.AutoGenerationOption) PatientIdentifierType(org.openmrs.PatientIdentifierType)

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