@Before public void setUp() throws Exception { String xml = (new TestUtil()).loadXmlFromFile(XML_HTML_FORM_ENTRY_REGIMEN_UTIL_TEST_DATASET); // used to avoid lock timeout on GP#order.nextOrderNumberSeed AdministrationService administrationService = mock(AdministrationService.class); when(administrationService.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_STANDARD_DRUG_REGIMENS)) .thenReturn(xml); when(administrationService.getGlobalProperty("")).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocationOnMock) throws Throwable { return "" + orderNumberCounter++; } }); ServiceContext.getInstance().setAdministrationService(administrationService); }
public void createCloneForExport_shouldIncludeAppropriateDrugsReferencedByStandardRegimen() throws Exception { HtmlForm form = new HtmlForm(); form.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "metadataSharingTestFormRegimens.xml"));
form.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "metadataSharingTestForm.xml"));
form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "obsGroupDataExportTest.xml")); List<String> extraCols = new ArrayList<String>(); extraCols.add("valueModifier");
@Test public void testExportWithEncounterRoleAndProvider() throws Exception { HtmlForm form = new HtmlForm(); form.setXmlData(new TestUtil().loadXmlFromFile("org/openmrs/module/htmlformentry/include/metadataSharingExportTest.xml")); HtmlFormExporter exporter = new HtmlFormExporter(form); HtmlForm formClone = exporter.export(true, true, true, true); Collection<OpenmrsObject> dependencies = formClone.getDependencies(); Assert.assertTrue(dependencies.contains(Context.getEncounterService().getEncounterRoleByUuid("e5c5cc92-5283-11e1-bb6a-d975bd577a5e"))); Assert.assertTrue(dependencies.contains(Context.getEncounterService().getEncounterRoleByUuid("eb75d754-5283-11e1-bb6a-d975bd577a5e"))); Assert.assertTrue(dependencies.contains(Context.getProviderService().getProviderByUuid("d2299800-cca9-11e0-9572-0800200c9a66"))); Assert.assertTrue(dependencies.contains(Context.getProviderService().getProviderByUuid("c2299800-cca9-11e0-9572-0800200c9a66"))); }
@Test @Verifies(value = "should recognize and return section tags in xml", method = "getSectionNodes(HtmlForm)") public void getSectionNodes_shouldReturnSectionNodesCorrectly() throws Exception { Form form = new Form(); HtmlForm htmlform = new HtmlForm(); htmlform.setForm(form); form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestForm.xml")); Map<Integer, String> map = HtmlFormEntryExportUtil.getSectionIndex(htmlform); String st = ""; for (Map.Entry<Integer, String> e : map.entrySet()){ st += "|" + e.getKey() + " : " + e.getValue(); } //System.out.println(st); TestUtil.assertFuzzyContains("Section One", st); TestUtil.assertFuzzyContains("Section One Inner One", st); TestUtil.assertFuzzyContains("Section One Inner Two", st); TestUtil.assertFuzzyContains("no name specified", st); }
form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "datatypeRenderingTest.xml")); List<String> extraCols = new ArrayList<String>(); extraCols.add("valueModifier");
@Before public void setupDatabase() throws Exception { executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); String xml = (new TestUtil()).loadXmlFromFile(XML_DATASET_PATH + XML_HTML_FORM_ENTRY_REGIMEN_UTIL_TEST_DATASET); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_STANDARD_DRUG_REGIMENS); gp.setPropertyValue(xml); Context.getAdministrationService().saveGlobalProperty(gp); }
/** * calls session.createForm on a form that has both conceptIds with labels, and conceptIds without labels in obs tags. * Verifies that the dropdown options for selecting a concept are correctly labeled. * @throws Exception */ @Test @Verifies(value = "should test labels generation for concept selects on dropdown options", method = "") public void getSectionNodes_shouldReturnDropdownForConceptSelects() throws Exception { Form form = new Form(); HtmlForm htmlform = new HtmlForm(); htmlform.setForm(form); form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "obsGroupDataExportTest.xml")); FormEntrySession session = new FormEntrySession(HtmlFormEntryUtil.getFakePerson(), htmlform, null); String xml = session.createForm(htmlform.getXmlData()); // System.out.println(xml); Assert.assertTrue(xml.contains("<option value=\"\" selected=\"true\"></option><option value=\"2474\">Susc</option><option value=\"3017\">Interm</option>")); Assert.assertTrue(xml.contains("<option value=\"\" selected=\"true\"></option><option value=\"2474\">Susceptible</option><option value=\"3017\">Intermediate</option><option value=\"1441\">Resistant</option>")); }
form.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "metadataSharingTestForm.xml"));
@Test @Verifies(value = "should return section as a new htmlform", method = "getSectionAsForm(HtmlForm)") public void getSectionAsForm_shouldReturnStringCorrectly() throws Exception { Form form = new Form(); HtmlForm htmlform = new HtmlForm(); htmlform.setForm(form); form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestForm.xml")); String newXml = HtmlFormEntryExportUtil.getSectionAsFormXml(htmlform, 1); //System.out.println(newXML); htmlform.setXmlData(newXml); FormEntrySession session = new FormEntrySession(HtmlFormEntryUtil.getFakePerson(), htmlform, null); String html = session.getHtmlToDisplay(); System.out.println(html); TestUtil.assertFuzzyContains("<span class=\"sectionHeader\">Section One Inner One</span>", html); TestUtil.assertFuzzyContains("ISONIAZID <select id=\"w2\" name=\"w2\" size=\"1\"><option value=\"\" selected=\"true\"></option><option value=\"2474\">Susceptible</option><option value=\"3017\">Intermediate</option><option value=\"1441\">Resistant</option></select>", html); }
/** * see {@link HtmlFormSubstitutionUtils#replaceProgramNamesWithUuids(HtmlForm)} * @throws Exception */ @Test @Verifies(value = "should replace program names with uuids", method = "replaceProgramNamesWithUuids(HtmlForm)") public void replaceProgamNamesWithUuids_shouldReplaceProgramNamesWithUuids() throws Exception { HtmlForm form = new HtmlForm(); form.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "metadataSharingTestForm.xml")); HtmlFormSubstitutionUtils.replaceProgramNamesWithUuids(form); // make the program is no longer referenced by name TestUtil.assertFuzzyDoesNotContain("programId=\"MDR-TB PROGRAM\"", form.getXmlData()); // make sure the program is now referenced by uuid TestUtil.assertFuzzyContains("programId=\"71779c39-d289-4dfe-91b5-e7cfaa27c78b\"", form.getXmlData()); }
form.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "metadataSharingTestForm.xml"));
@Before public void setupDatabase() throws Exception { executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_DRUG_ORDER_ELEMENT_DATASET)); String xml = (new TestUtil()).loadXmlFromFile(XML_DATASET_PATH + XML_HTML_FORM_ENTRY_REGIMEN_UTIL_TEST_DATASET); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_STANDARD_DRUG_REGIMENS); gp.setPropertyValue(xml); Context.getAdministrationService().saveGlobalProperty(gp); }
@Before public void setupDatabase() throws Exception { executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_DRUG_ORDER_ELEMENT_DATASET)); String xml = (new TestUtil()).loadXmlFromFile(XML_DATASET_PATH + XML_HTML_FORM_ENTRY_REGIMEN_UTIL_TEST_DATASET); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_STANDARD_DRUG_REGIMENS); gp.setPropertyValue(xml); Context.getAdministrationService().saveGlobalProperty(gp); }
form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml")); String newXml = HtmlFormEntryExportUtil.getSectionAsFormXml(htmlform, 0); htmlform.setXmlData(newXml);
@Test @Verifies(value = "should return encounter with all child objects voided according to schema", method = "voidEncounterByHtmlFormSchema") public void testVoidEncounterByHtmlFormSchema_shouldReturnEncounterVoided() throws Exception { executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); Encounter e = new Encounter(); e.setPatient(Context.getPatientService().getPatient(2)); Date date = Context.getDateFormat().parse("01/02/2003"); e.setDateCreated(new Date()); e.setEncounterDatetime(date); e.setLocation(Context.getLocationService().getLocation(2)); e.setProvider(Context.getPersonService().getPerson(502)); //add a bunch of obs... TestUtil.addObs(e, 2474, Context.getConceptService().getConcept(656), date); //matches Form form = new Form(); HtmlForm htmlform = new HtmlForm(); htmlform.setForm(form); form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml")); HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null); //this is going to test out the voided state of the obs in the encounter after processing: Assert.assertTrue(e.isVoided()); }
/** * see {@link HtmlFormSubstitutionUtils#replaceIdsWithUuids(HtmlForm)} * @throws Exception */ @Test @Verifies(value = "should convert ids to uuids within repeat tags", method = "replaceConceptIdsWithUuids(HtmlForm)") public void replaceConceptIdsWithUuids_shouldReplaceConceptIdsWithUuidsWithMacros() throws Exception { executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); HtmlForm form = new HtmlForm(); form.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "metadataSharingWithMacrosTestForm.xml")); HtmlFormSubstitutionUtils.replaceIdsWithUuids(form); // make sure it's left the macro references alone TestUtil.assertFuzzyContains("groupingConceptId=\"\\$allergyGroup\"", form.getXmlData()); TestUtil.assertFuzzyContains("conceptId=\"\\$allergy\"", form.getXmlData()); TestUtil.assertFuzzyContains("answerConceptIds=\"\\$allergyAnswers\"", form.getXmlData()); // test that the macros themselves have been substituted TestUtil.assertFuzzyContains("allergyGroup=32296060-03aa-102d-b0e3-001ec94a0cc1", form.getXmlData()); TestUtil.assertFuzzyContains("allergy=32296060-03aa-102d-b0e3-001ec94a0cc4", form.getXmlData()); TestUtil.assertFuzzyContains("allergyAnswers=32296060-03aa-102d-b0e3-001ec94a0cc5,32296060-03aa-102d-b0e3-001ec94a0cc6", form.getXmlData()); }
/** * see {@link HtmlFormSubstitutionUtils#replaceIdsWithUuids(HtmlForm)} * @throws Exception */ @Test @Verifies(value = "should convert ids to uuids within repeat tags", method = "replaceConceptIdsWithUuids(HtmlForm)") public void replaceConceptIdsWithUuids_shouldReplaceConceptIdsWithUuidsWithinRepeatTags() throws Exception { executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); HtmlForm form = new HtmlForm(); form.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "metadataSharingWithRepeatTestForm.xml")); HtmlFormSubstitutionUtils.replaceIdsWithUuids(form); // make sure it's left the keys alone TestUtil.assertFuzzyContains("groupingConceptId=\"\\{allergyGroup\\}\"", form.getXmlData()); TestUtil.assertFuzzyContains("conceptId=\"\\{allergy\\}\"", form.getXmlData()); TestUtil.assertFuzzyContains("answerConceptIds=\"\\{allergyAnswers\\}\"", form.getXmlData()); // test that the first render tag has been substituted TestUtil.assertFuzzyContains("allergyGroup=\"32296060-03aa-102d-b0e3-001ec94a0cc1\"", form.getXmlData()); TestUtil.assertFuzzyContains("allergy=\"32296060-03aa-102d-b0e3-001ec94a0cc4\"", form.getXmlData()); TestUtil.assertFuzzyContains("allergyAnswers=\"32296060-03aa-102d-b0e3-001ec94a0cc5,32296060-03aa-102d-b0e3-001ec94a0cc6\"", form.getXmlData()); // test that the second render tag has been substituted TestUtil.assertFuzzyContains("allergyGroup=\"42296060-03-102d-b0e3-001ec94a0cc1\"", form.getXmlData()); TestUtil.assertFuzzyContains("allergy=\"aa52296060-03-102d-b0e3-001ec94a0cc1\"", form.getXmlData()); TestUtil.assertFuzzyContains("allergyAnswers=\"32296060-03aa-102d-b0e3-001ec94a0cc6,32296060-03aa-102d-b0e3-001ec94a0cc7\"", form.getXmlData()); }
form.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "metadataSharingTestForm.xml")); HtmlFormSubstitutionUtils.replaceIdsWithUuids(form);