Search in sources :

Example 1 with ResourceFactory

use of org.openmrs.ui.framework.resource.ResourceFactory in project openmrs-module-mirebalais by PIH.

the class CustomAppUtilTest method shouldFindResourceAtCountryLevel.

@Test
public void shouldFindResourceAtCountryLevel() {
    File file = mock(File.class);
    ResourceFactory resourceFactory = mock(ResourceFactory.class);
    when(resourceFactory.getResource("pihcore", "htmlforms/checkin.xml")).thenReturn(file);
    when(resourceFactory.getResource("pihcore", "htmlforms/other/checkin.xml")).thenReturn(file);
    Config config = mock(Config.class);
    when(config.getCountry()).thenReturn(ConfigDescriptor.Country.OTHER);
    when(config.getSite()).thenReturn(ConfigDescriptor.Site.OTHER);
    String resourcePath = CustomAppLoaderUtil.determineResourcePath(config, "pihcore", "htmlforms", "checkin.xml");
    assertThat(resourcePath, is("pihcore:htmlforms/other/checkin.xml"));
}
Also used : Config(org.openmrs.module.pihcore.config.Config) ResourceFactory(org.openmrs.ui.framework.resource.ResourceFactory) File(java.io.File) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with ResourceFactory

use of org.openmrs.ui.framework.resource.ResourceFactory in project openmrs-module-mirebalais by PIH.

the class HtmlFormSetup method setupHtmlForms.

// set up html forms--this must happen *after* MDS packages are installed, so that forms defined in code/github
// take precedent over any in MDS packages; therefore we still do this in the Mirebalais module, not PIH Core
public static void setupHtmlForms(Config config) throws Exception {
    try {
        ResourceFactory resourceFactory = ResourceFactory.getInstance();
        FormService formService = Context.getFormService();
        HtmlFormEntryService htmlFormEntryService = Context.getService(HtmlFormEntryService.class);
        // forms installed across all implementations
        List<String> htmlforms = new ArrayList(Arrays.asList("pihcore:htmlforms/admissionNote.xml", "pihcore:htmlforms/patientRegistration.xml", "pihcore:htmlforms/patientRegistration-rs.xml", "pihcore:htmlforms/surgicalPostOpNote.xml", "pihcore:htmlforms/vitals.xml", "pihcore:htmlforms/transferNote.xml", "pihcore:htmlforms/dischargeNote.xml", "pihcore:htmlforms/outpatientConsult.xml", "pihcore:htmlforms/edNote.xml", "pihcore:htmlforms/deathCertificate.xml", "pihcore:htmlforms/oncologyConsult.xml", "pihcore:htmlforms/mentalHealth.xml", "pihcore:htmlforms/section-chief-complaint.xml", "pihcore:htmlforms/section-history.xml", "pihcore:htmlforms/section-exam.xml", "pihcore:htmlforms/section-dx.xml", "pihcore:htmlforms/section-peds-feeding.xml", "pihcore:htmlforms/section-peds-supplements.xml", "pihcore:htmlforms/section-plan.xml", "pihcore:htmlforms/section-ncd.xml", "pihcore:htmlforms/section-lab-order.xml", "pihcore:htmlforms/section-family-planning.xml", "pihcore:htmlforms/socio-econ.xml", "pihcore:htmlforms/primary-care-adult-initial.xml", "pihcore:htmlforms/primary-care-adult-followup.xml", "pihcore:htmlforms/primary-care-peds-initial.xml", "pihcore:htmlforms/primary-care-peds-followup.xml", "pihcore:htmlforms/ncd-adult-initial.xml", "pihcore:htmlforms/ncd-adult-followup.xml"));
        // add any country-specific forms
        if (config.getCountry().equals(ConfigDescriptor.Country.HAITI)) {
            htmlforms.addAll(Arrays.asList("pihcore:htmlforms/haiti/hiv/zl/hiv-intake.xml", "pihcore:htmlforms/haiti/patientRegistration-contact.xml", "pihcore:htmlforms/haiti/patientRegistration-social.xml", "pihcore:htmlforms/haiti/patientRegistration-insurance.xml", "pihcore:htmlforms/haiti/checkin.xml", "pihcore:htmlforms/haiti/liveCheckin.xml", "pihcore:htmlforms/haiti/hiv/zl/hiv-followup.xml", "pihcore:htmlforms/haiti/hiv/zl/vct.xml", "pihcore:htmlforms/haiti/hiv/zl/section-hiv-serology.xml", "pihcore:htmlforms/haiti/hiv/zl/section-symptoms.xml", "pihcore:htmlforms/haiti/hiv/zl/section-who-stages.xml", "pihcore:htmlforms/haiti/hiv/zl/section-hiv-oi.xml", "pihcore:htmlforms/haiti/hiv/zl/section-hiv-state.xml", "pihcore:htmlforms/haiti/hiv/iSantePlus/Adherence.xml", "pihcore:htmlforms/haiti/hiv/iSantePlus/SaisiePremiereVisiteAdult.xml", "pihcore:htmlforms/haiti/hiv/iSantePlus/SaisiePremiereVisitePediatrique.xml", "pihcore:htmlforms/haiti/hiv/iSantePlus/VisiteDeSuivi.xml", "pihcore:htmlforms/haiti/hiv/iSantePlus/VisiteDeSuiviPediatrique.xml"));
        } else if (config.getCountry().equals(ConfigDescriptor.Country.LIBERIA)) {
            htmlforms.addAll(Arrays.asList("pihcore:htmlforms/liberia/checkin.xml", "pihcore:htmlforms/liberia/liveCheckin.xml", "pihcore:htmlforms/liberia/patientRegistration-contact.xml", "pihcore:htmlforms/liberia/patientRegistration-social.xml"));
        } else if (config.getCountry().equals(ConfigDescriptor.Country.SIERRA_LEONE)) {
            htmlforms.addAll(Arrays.asList("pihcore:htmlforms/patientRegistration.xml", "pihcore:htmlforms/patientRegistration-rs.xml", "pihcore:htmlforms/sierra_leone/checkin.xml", "pihcore:htmlforms/sierra_leone/liveCheckin.xml", "pihcore:htmlforms/sierra_leone/patientRegistration-contact.xml", "pihcore:htmlforms/sierra_leone/patientRegistration-social.xml"));
        }
        if (htmlforms != null) {
            for (String htmlform : htmlforms) {
                HtmlFormUtil.getHtmlFormFromUiResource(resourceFactory, formService, htmlFormEntryService, htmlform);
            }
        }
    } catch (Exception e) {
        // this is a hack to get component test to pass until we find the proper way to mock this
        if (ResourceFactory.getInstance().getResourceProviders() == null) {
            log.error("Unable to load HTML forms--this error is expected when running component tests");
        } else {
            throw e;
        }
    }
}
Also used : HtmlFormEntryService(org.openmrs.module.htmlformentry.HtmlFormEntryService) FormService(org.openmrs.api.FormService) ArrayList(java.util.ArrayList) ResourceFactory(org.openmrs.ui.framework.resource.ResourceFactory)

Example 3 with ResourceFactory

use of org.openmrs.ui.framework.resource.ResourceFactory in project openmrs-module-mirebalais by PIH.

the class CustomAppUtilTest method shouldFindResourceAtSiteLevel.

@Test
public void shouldFindResourceAtSiteLevel() {
    File file = mock(File.class);
    ResourceFactory resourceFactory = mock(ResourceFactory.class);
    when(resourceFactory.getResource("pihcore", "htmlforms/checkin.xml")).thenReturn(file);
    when(resourceFactory.getResource("pihcore", "htmlforms/other/checkin.xml")).thenReturn(file);
    when(resourceFactory.getResource("pihcore", "htmlforms/other/other/checkin.xml")).thenReturn(file);
    Config config = mock(Config.class);
    when(config.getCountry()).thenReturn(ConfigDescriptor.Country.OTHER);
    when(config.getSite()).thenReturn(ConfigDescriptor.Site.OTHER);
    String resourcePath = CustomAppLoaderUtil.determineResourcePath(config, "pihcore", "htmlforms", "checkin.xml");
    assertThat(resourcePath, is("pihcore:htmlforms/other/other/checkin.xml"));
}
Also used : Config(org.openmrs.module.pihcore.config.Config) ResourceFactory(org.openmrs.ui.framework.resource.ResourceFactory) File(java.io.File) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ResourceFactory

use of org.openmrs.ui.framework.resource.ResourceFactory in project openmrs-module-mirebalais by PIH.

the class CustomAppUtilTest method shouldFindHtmlResourcePathAtCountryLevel.

@Test
public void shouldFindHtmlResourcePathAtCountryLevel() {
    File file = mock(File.class);
    ResourceFactory resourceFactory = mock(ResourceFactory.class);
    when(resourceFactory.getResource("pihcore", "htmlforms/checkin.xml")).thenReturn(file);
    when(resourceFactory.getResource("pihcore", "htmlforms/other/checkin.xml")).thenReturn(file);
    Config config = mock(Config.class);
    when(config.getCountry()).thenReturn(ConfigDescriptor.Country.OTHER);
    when(config.getSite()).thenReturn(ConfigDescriptor.Site.OTHER);
    String resourcePath = CustomAppLoaderUtil.determineHtmlFormPath(config, "checkin");
    assertThat(resourcePath, is("pihcore:htmlforms/other/checkin.xml"));
}
Also used : Config(org.openmrs.module.pihcore.config.Config) ResourceFactory(org.openmrs.ui.framework.resource.ResourceFactory) File(java.io.File) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ResourceFactory (org.openmrs.ui.framework.resource.ResourceFactory)4 File (java.io.File)3 Test (org.junit.Test)3 Config (org.openmrs.module.pihcore.config.Config)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 ArrayList (java.util.ArrayList)1 FormService (org.openmrs.api.FormService)1 HtmlFormEntryService (org.openmrs.module.htmlformentry.HtmlFormEntryService)1