Search in sources :

Example 1 with FormEntrySession

use of org.openmrs.module.htmlformentry.FormEntrySession in project openmrs-module-pihcore by PIH.

the class HtmlFormComponentTest method testHtmlForms.

@Test
public void testHtmlForms() throws Exception {
    String[] formsToTest = { "patientRegistration.xml", "patientRegistration-rs.xml", "patientRegistration-contact.xml", "patientRegistration-social.xml", // "vitals.xml",
    "transferNote.xml", "dischargeNote.xml", // "edNote.xml",
    "deathCertificate.xml", // "haiti/section-exam.xml",
    "section-dx.xml", // "haiti/liveCheckin.xml",
    "haiti/patientRegistration-contact.xml", "haiti/patientRegistration-social.xml" // "liberia/checkin.xml",
    // "liberia/liveCheckin.xml",
    };
    for (String formName : formsToTest) {
        // loading up all of the UI Framework beans to fetch this resource is problematic, so just get it directly:
        InputStream in = getClass().getClassLoader().getResourceAsStream("web/module/resources/htmlforms/" + formName);
        String xml = IOUtils.toString(in);
        IOUtils.closeQuietly(in);
        try {
            HtmlForm form = HtmlFormUtil.getHtmlFormFromResourceXml(Context.getFormService(), Context.getService(HtmlFormEntryService.class), xml);
            FormEntrySession fes = new FormEntrySession(new Patient(), form, FormEntryContext.Mode.ENTER, new MockHttpSession());
            String html = fes.getHtmlToDisplay();
        } catch (Exception ex) {
            ex.printStackTrace();
            Assert.fail("Failed to load " + formName + ": " + ex.getMessage());
        }
    }
}
Also used : HtmlForm(org.openmrs.module.htmlformentry.HtmlForm) InputStream(java.io.InputStream) HtmlFormEntryService(org.openmrs.module.htmlformentry.HtmlFormEntryService) FormEntrySession(org.openmrs.module.htmlformentry.FormEntrySession) Patient(org.openmrs.Patient) MockHttpSession(org.springframework.mock.web.MockHttpSession) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 2 with FormEntrySession

use of org.openmrs.module.htmlformentry.FormEntrySession in project openmrs-module-pihcore by PIH.

the class ApplyDispositionActionsTest method setUp.

@Before
public void setUp() throws Exception {
    encounter = new Encounter(1);
    encounter.setDateCreated(new Date());
    encounter.setPatient(patient);
    encounter.setVisit(visit);
    deathDispositionObsGroup.setConcept(dispositionObsGroupConcept);
    deathDispositionObs.setConcept(dispositionObsConcept);
    deathDispositionObs.setValueCoded(death);
    deathDispositionObsGroup.addGroupMember(deathDispositionObs);
    nonDispositionObsGroup.setConcept(nonDispositionObsGroupConcept);
    nonDispositionObs.setConcept(nonDispositionObsConcept);
    nonDispositionObsGroup.addGroupMember(nonDispositionObs);
    deathDisposition.setActions(Arrays.asList("dischargeIfAdmittedDispositionAction", "markPatientDeadDispositionAction"));
    dispositionService = mock(DispositionService.class);
    dischargeIfAdmittedDispositionAction = mock(DispositionAction.class);
    markPatientDeadDispositionAction = mock(DispositionAction.class);
    ServiceContext.getInstance().setPersonService(mock(PersonService.class));
    ServiceContext.getInstance().setApplicationContext(mock(ApplicationContext.class));
    HtmlForm htmlForm = new HtmlForm();
    htmlForm.setXmlData("<htmlform></htmlform>");
    session = new FormEntrySession(patient, encounter, FormEntryContext.Mode.ENTER, htmlForm, null);
    DispositionDescriptor dispositionDescriptor = new DispositionDescriptor();
    dispositionDescriptor.setDispositionConcept(dispositionObsConcept);
    dispositionDescriptor.setDispositionSetConcept(dispositionObsGroupConcept);
    when(dispositionService.getDispositionDescriptor()).thenReturn(dispositionDescriptor);
    when(dispositionService.getDispositionFromObsGroup(deathDispositionObsGroup)).thenReturn(deathDisposition);
    applyDispositionActions = new ApplyDispositionAction() {

        @Override
        <T> T getBean(String beanId, Class<T> clazz) {
            if (beanId.equals("dischargeIfAdmittedDispositionAction")) {
                return (T) dischargeIfAdmittedDispositionAction;
            } else if (beanId.equals("markPatientDeadDispositionAction")) {
                return (T) markPatientDeadDispositionAction;
            } else {
                return null;
            }
        }
    };
}
Also used : DispositionService(org.openmrs.module.emrapi.disposition.DispositionService) PersonService(org.openmrs.api.PersonService) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor) Date(java.util.Date) ApplicationContext(org.springframework.context.ApplicationContext) HtmlForm(org.openmrs.module.htmlformentry.HtmlForm) Encounter(org.openmrs.Encounter) FormEntrySession(org.openmrs.module.htmlformentry.FormEntrySession) DispositionAction(org.openmrs.module.emrapi.disposition.actions.DispositionAction) Before(org.junit.Before)

Aggregations

FormEntrySession (org.openmrs.module.htmlformentry.FormEntrySession)2 HtmlForm (org.openmrs.module.htmlformentry.HtmlForm)2 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Encounter (org.openmrs.Encounter)1 Patient (org.openmrs.Patient)1 PersonService (org.openmrs.api.PersonService)1 DispositionDescriptor (org.openmrs.module.emrapi.disposition.DispositionDescriptor)1 DispositionService (org.openmrs.module.emrapi.disposition.DispositionService)1 DispositionAction (org.openmrs.module.emrapi.disposition.actions.DispositionAction)1 HtmlFormEntryService (org.openmrs.module.htmlformentry.HtmlFormEntryService)1 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)1 ApplicationContext (org.springframework.context.ApplicationContext)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1