Search in sources :

Example 1 with UiUtils

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

the class VisitDetailsFragmentControllerTest method shouldReturnEncountersForVisit.

@Test
public void shouldReturnEncountersForVisit() throws ParseException {
    CoreAppsProperties coreAppsProperties = mock(CoreAppsProperties.class);
    when(coreAppsProperties.getPatientDashboardEncounterCount()).thenReturn(100);
    UiSessionContext sessionContext = mock(UiSessionContext.class);
    User authenticatedUser = new User();
    when(sessionContext.getCurrentUser()).thenReturn(authenticatedUser);
    AppContextModel appContextModel = new AppContextModel();
    when(sessionContext.generateAppContextModel()).thenReturn(appContextModel);
    authenticatedUser.addRole(createRoleForUser());
    AdministrationService administrationService = mock(AdministrationService.class);
    when(administrationService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATETIME_FORMAT)).thenReturn("dd.MMM.yyyy, HH:mm:ss");
    AppFrameworkService appFrameworkService = mock(AppFrameworkService.class);
    when(appFrameworkService.getExtensionsForCurrentUser(CoreAppsConstants.ENCOUNTER_TEMPLATE_EXTENSION)).thenReturn(generateMockEncounterTemplateExtensions());
    EncounterService encounterService = mock(EncounterService.class);
    Patient patient = mock(Patient.class);
    when(patient.getPatientId()).thenReturn(1);
    when(patient.isDead()).thenReturn(false);
    Visit visit = new Visit();
    Location visitLocation = new Location();
    visitLocation.setName("Visit Location");
    visit.setVisitId(1);
    visit.setLocation(visitLocation);
    visit.setStartDatetime(new Date());
    visit.setStopDatetime(new Date());
    visit.setCreator(authenticatedUser);
    visit.setPatient(patient);
    Location encounterLocation = new Location();
    encounterLocation.setName("Location");
    EncounterType encounterType = new EncounterType();
    encounterType.setName("Encounter Type");
    encounterType.setUuid(encounterTypeUuid);
    Provider primaryProvider = new Provider();
    primaryProvider.setName("Primary Provider");
    EncounterProvider primaryEncounterProvider = new EncounterProvider();
    primaryEncounterProvider.setProvider(primaryProvider);
    EncounterRole primaryEncounterRole = new EncounterRole();
    primaryEncounterRole.setUuid(primaryEncounterRoleUuid);
    primaryEncounterProvider.setEncounterRole(primaryEncounterRole);
    when(encounterService.getEncounterRoleByUuid(primaryEncounterRoleUuid)).thenReturn(primaryEncounterRole);
    Provider secondaryProvider = new Provider();
    secondaryProvider.setName("Secondary Provider");
    EncounterProvider secondaryEncounterProvider = new EncounterProvider();
    secondaryEncounterProvider.setProvider(secondaryProvider);
    secondaryEncounterProvider.setEncounterRole(new EncounterRole());
    Encounter encounter = new Encounter();
    encounter.setEncounterId(7);
    encounter.setEncounterDatetime(new Date());
    encounter.setLocation(encounterLocation);
    encounter.setEncounterType(encounterType);
    encounter.setEncounterProviders(new LinkedHashSet<EncounterProvider>());
    // add secondary provider so that it is the one that is "arbitrarily" returned first
    encounter.getEncounterProviders().add(secondaryEncounterProvider);
    encounter.getEncounterProviders().add(primaryEncounterProvider);
    encounter.setCreator(authenticatedUser);
    encounter.setDateCreated(new Date());
    visit.addEncounter(encounter);
    UiUtils uiUtils = new TestUiUtils(administrationService);
    VisitDetailsFragmentController controller = new VisitDetailsFragmentController();
    SimpleObject response = controller.getVisitDetails(mock(EmrApiProperties.class), coreAppsProperties, appFrameworkService, encounterService, visit, null, null, uiUtils, sessionContext);
    List<SimpleObject> actualEncounters = (List<SimpleObject>) response.get("encounters");
    SimpleObject actualEncounter = actualEncounters.get(0);
    assertThat(response.get("startDatetime"), notNullValue());
    assertThat(response.get("stopDatetime"), notNullValue());
    assertThat((String) response.get("location"), is("Visit Location"));
    assertThat(actualEncounters.size(), is(1));
    assertThat((Integer) actualEncounter.get("encounterId"), is(7));
    assertThat((String) actualEncounter.get("location"), is("Location"));
    assertThat((SimpleObject) actualEncounter.get("encounterType"), isSimpleObjectWith("uuid", encounterType.getUuid(), "name", encounterType.getName()));
    assertThat(actualEncounter.get("encounterDatetime"), notNullValue());
    assertThat(actualEncounter.get("encounterDate"), notNullValue());
    assertThat(actualEncounter.get("encounterTime"), notNullValue());
    assertTrue((Boolean) actualEncounter.get("canEdit"));
    assertThat((String) actualEncounter.get("primaryProvider"), is("Primary Provider"));
    List<SimpleObject> actualProviders = (List<SimpleObject>) actualEncounter.get("encounterProviders");
    assertThat(actualProviders.size(), is(2));
}
Also used : UiSessionContext(org.openmrs.module.appui.UiSessionContext) EncounterProvider(org.openmrs.EncounterProvider) User(org.openmrs.User) SimpleObject(org.openmrs.ui.framework.SimpleObject) Visit(org.openmrs.Visit) TestUiUtils(org.openmrs.module.appui.TestUiUtils) Patient(org.openmrs.Patient) EmrApiProperties(org.openmrs.module.emrapi.EmrApiProperties) EncounterService(org.openmrs.api.EncounterService) Date(java.util.Date) EncounterProvider(org.openmrs.EncounterProvider) Provider(org.openmrs.Provider) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) AdministrationService(org.openmrs.api.AdministrationService) CoreAppsProperties(org.openmrs.module.coreapps.CoreAppsProperties) EncounterRole(org.openmrs.EncounterRole) Encounter(org.openmrs.Encounter) AppFrameworkService(org.openmrs.module.appframework.service.AppFrameworkService) ArrayList(java.util.ArrayList) List(java.util.List) EncounterType(org.openmrs.EncounterType) Location(org.openmrs.Location) TestUiUtils(org.openmrs.module.appui.TestUiUtils) UiUtils(org.openmrs.ui.framework.UiUtils) Test(org.junit.Test)

Example 2 with UiUtils

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

the class CoreAppsActivator method contextRefreshed.

/**
 * @see ModuleActivator#contextRefreshed()
 */
public void contextRefreshed() {
    ConceptService conceptService = Context.getConceptService();
    EmrApiProperties emrApiProperties = Context.getRegisteredComponent("emrApiProperties", EmrApiProperties.class);
    DispositionService dispositionService = Context.getRegisteredComponent("dispositionService", DispositionService.class);
    AdtService adtService = Context.getRegisteredComponent("adtService", AdtService.class);
    UiUtils uiUtils = Context.getRegisteredComponent("uiUtils", BasicUiUtils.class);
    if (ModuleFactory.isModuleStarted("htmlformentry")) {
        HtmlFormEntryService htmlFormEntryService = Context.getService(HtmlFormEntryService.class);
        EncounterDiagnosesTagHandler encounterDiagnosesTagHandler = CoreAppsActivator.setupEncounterDiagnosesTagHandler(conceptService, adtService, emrApiProperties, uiUtils);
        htmlFormEntryService.addHandler(CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DIAGNOSES_TAG_NAME, encounterDiagnosesTagHandler);
        EncounterDispositionTagHandler encounterDispositionTagHandler = CoreAppsActivator.setupEncounterDispositionTagHandler(emrApiProperties, dispositionService, adtService);
        htmlFormEntryService.addHandler(CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DISPOSITION_TAG_NAME, encounterDispositionTagHandler);
        htmlFormEntryService.addHandler(CoreAppsConstants.HTMLFORMENTRY_CODED_OR_FREE_TEXT_OBS_TAG_NAME, new CodedOrFreeTextObsTagHandler());
    }
    log.info("Core Apps Module refreshed");
}
Also used : DispositionService(org.openmrs.module.emrapi.disposition.DispositionService) AdtService(org.openmrs.module.emrapi.adt.AdtService) HtmlFormEntryService(org.openmrs.module.htmlformentry.HtmlFormEntryService) EmrApiProperties(org.openmrs.module.emrapi.EmrApiProperties) EncounterDiagnosesTagHandler(org.openmrs.module.coreapps.htmlformentry.EncounterDiagnosesTagHandler) ConceptService(org.openmrs.api.ConceptService) EncounterDispositionTagHandler(org.openmrs.module.coreapps.htmlformentry.EncounterDispositionTagHandler) CodedOrFreeTextObsTagHandler(org.openmrs.module.coreapps.htmlformentry.CodedOrFreeTextObsTagHandler) BasicUiUtils(org.openmrs.ui.framework.BasicUiUtils) UiUtils(org.openmrs.ui.framework.UiUtils)

Example 3 with UiUtils

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

the class EncounterDiagnosesTagHandler method getSubstitution.

@Override
protected String getSubstitution(FormEntrySession session, FormSubmissionController controller, Map<String, String> attributes) throws BadFormDesignException {
    EncounterDiagnosesElement element = new EncounterDiagnosesElement();
    // pull from the session if available, otherwise fall back to basic ui utils
    element.setUiUtils(session.getAttribute("uiUtils") != null ? (UiUtils) session.getAttribute("uiUtils") : uiUtils);
    element.setRequired("true".equals(attributes.get("required")));
    element.setSelectedDiagnosesTarget(attributes.get("selectedDiagnosesTarget"));
    element.setEmrApiProperties(emrApiProperties);
    element.setConceptService(conceptService);
    element.setAdtService(adtService);
    /**
     *  Handle the attribute to specify loading any prior diagnoses from the most recent encounter with a specific disposition
     * (use case: prepopulating the diagonses on an admission note with the diagnoses from the consult recommending admission,
     *  ie., on our admission note: <encounterDiagnoses required="true" selectedDiagnosesTarget="#encounter-diagnoses-target" includePriorDiagnosesFromMostRecentEncounterWithDispositionOfType="ADMIT"/>)
     */
    if (attributes.containsKey(CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DIAGNOSES_TAG_INCLUDE_PRIOR_DIAGNOSES_ATTRIBUTE_NAME)) {
        try {
            element.setDispositionTypeForPriorDiagnoses(DispositionType.valueOf(attributes.get(CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DIAGNOSES_TAG_INCLUDE_PRIOR_DIAGNOSES_ATTRIBUTE_NAME).toUpperCase()));
        } catch (IllegalArgumentException ex) {
            throw new BadFormDesignException("Encounter Diagnoses Tag: invalid value of " + attributes.get(CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DIAGNOSES_TAG_INCLUDE_PRIOR_DIAGNOSES_ATTRIBUTE_NAME) + " for attribute " + CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DIAGNOSES_TAG_INCLUDE_PRIOR_DIAGNOSES_ATTRIBUTE_NAME);
        }
    }
    controller.addAction(element);
    return element.generateHtml(session.getContext());
}
Also used : BadFormDesignException(org.openmrs.module.htmlformentry.BadFormDesignException) UiUtils(org.openmrs.ui.framework.UiUtils)

Example 4 with UiUtils

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

the class VisitDatesFragmentControllerTest method shouldSetToastMessageOnSetDuration.

@Test
public void shouldSetToastMessageOnSetDuration() throws Exception {
    UiUtils ui = mock(UiUtils.class);
    when(ui.message("coreapps.editVisitDate.visitSavedMessage")).thenReturn("message");
    Visit visit = new Visit(1);
    visit.setPatient(new Patient(1));
    visit.setStartDatetime(new Date());
    visit.setStopDatetime(new Date());
    controller.setDuration(visitService, visit, new Date(), new Date(), request, ui);
    verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, "message");
    verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Date(java.util.Date) UiUtils(org.openmrs.ui.framework.UiUtils) Test(org.junit.Test)

Aggregations

UiUtils (org.openmrs.ui.framework.UiUtils)4 Date (java.util.Date)2 Test (org.junit.Test)2 Patient (org.openmrs.Patient)2 Visit (org.openmrs.Visit)2 EmrApiProperties (org.openmrs.module.emrapi.EmrApiProperties)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Encounter (org.openmrs.Encounter)1 EncounterProvider (org.openmrs.EncounterProvider)1 EncounterRole (org.openmrs.EncounterRole)1 EncounterType (org.openmrs.EncounterType)1 Location (org.openmrs.Location)1 Provider (org.openmrs.Provider)1 User (org.openmrs.User)1 AdministrationService (org.openmrs.api.AdministrationService)1 ConceptService (org.openmrs.api.ConceptService)1 EncounterService (org.openmrs.api.EncounterService)1 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)1 AppFrameworkService (org.openmrs.module.appframework.service.AppFrameworkService)1