use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-coreapps by openmrs.
the class EncounterDispositionTagHandlerComponentTest method testShouldDisplayAdmissionLocationAfterEnteringAdmissionDisposition.
@Test
public void testShouldDisplayAdmissionLocationAfterEnteringAdmissionDisposition() throws Exception {
final Date date = new Date();
final DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
final Concept admissionDisposition = HtmlFormEntryUtil.getConcept("org.openmrs.module.emrapi: Admit to hospital");
new RegressionTestHelper() {
@Override
public String getXmlDatasetPath() {
return "";
}
@Override
public String getFormName() {
return "encounterDispositionSimpleForm";
}
@Override
public Map<String, Object> getFormEntrySessionAttributes() {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("uiUtils", new TestUiUtils());
return attributes;
}
@Override
public String[] widgetLabels() {
return new String[] { "Date:", "Location:", "Provider:", "Disposition:", "Encounter Type:" };
}
@Override
public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
request.setParameter(widgets.get("Date:"), dateAsString(date));
request.setParameter(widgets.get("Location:"), "2");
request.setParameter(widgets.get("Provider:"), "1");
request.setParameter(widgets.get("Encounter Type:"), "1");
request.setParameter(widgets.get("Disposition:"), admissionDisposition.toString());
// hack, manually reference the widget the location
request.setParameter("w10", "1");
}
@Override
public boolean doViewEncounter() {
return true;
}
@Override
public void testViewingEncounter(Encounter encounter, String html) {
// make sure the admission location is displayed (ie, does not have style="display:none;")
TestUtil.assertFuzzyContains("p id=\"[^\"]+\"><label><uimessage code=\"Admission Location\">", html);
}
}.run();
}
use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-coreapps by openmrs.
the class EncounterDispositionTagHandlerComponentTest method testFormOnlyShowsDispositionsInDescriptor.
@Test
public void testFormOnlyShowsDispositionsInDescriptor() throws Exception {
ConceptClass misc = conceptService.getConceptClassByName("Misc");
ConceptDatatype naDatatype = conceptService.getConceptDatatypeByName("N/A");
Concept dispositionConcept = dispositionService.getDispositionDescriptor().getDispositionConcept();
dispositionConcept.addAnswer(new ConceptAnswer(new ConceptBuilder(conceptService, naDatatype, misc).addName("Should not be in option list").saveAndGet()));
new RegressionTestHelper() {
@Override
public void testBlankFormHtml(String html) {
assertThat(html, containsString("disposition.admission"));
assertThat(html, containsString("disposition.transfer"));
assertThat(html, containsString("disposition.discharge"));
assertThat(html, not(containsString("Should not be in option list")));
}
@Override
public String getXmlDatasetPath() {
return "";
}
@Override
public String getFormName() {
return "encounterDispositionSimpleForm";
}
@Override
public Map<String, Object> getFormEntrySessionAttributes() {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("uiUtils", new TestUiUtils());
return attributes;
}
@Override
public String[] widgetLabels() {
return new String[] { "Date:", "Location:", "Provider:", "Disposition:", "Encounter Type:" };
}
}.run();
}
use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-pihcore by PIH.
the class CauseOfDeathListTagHandlerComponentTest method testCreateAndEdit.
@Test
public void testCreateAndEdit() throws Exception {
final ConceptName causeOne = conceptService.getConceptNameByUuid("2f7263e4-2a57-49b5-aef0-af9a259aac65");
final Concept causeTwo = conceptService.getConcept(13);
final Concept editedCauseTwo = conceptService.getConcept(11);
final String causeThree = "Cause Three";
final String editedCauseThree = "Edited Cause Three";
final Concept causeFour = conceptService.getConcept(16);
ArrayNode submission = jackson.createArrayNode();
ObjectNode one = submission.addObject();
one.put("ConceptName", causeOne.getUuid());
ObjectNode two = submission.addObject();
two.put("Concept", causeTwo.getUuid());
ObjectNode three = submission.addObject();
three.put("NonCodedValue", causeThree);
ObjectNode four = submission.addObject();
four.put("Concept", causeFour.getUuid());
final String createJson = jackson.writeValueAsString(submission);
two.put("Concept", editedCauseTwo.getUuid());
three.put("NonCodedValue", editedCauseThree);
// this removes 'four'
submission.remove(3);
final String editJson = jackson.writeValueAsString(submission);
final Date date = new Date();
new RegressionTestHelper() {
@Override
public String getXmlDatasetPath() {
return "";
}
@Override
public String getFormName() {
return "causesOfDeathForm";
}
@Override
public String[] widgetLabels() {
return new String[] { "Date:", "Location:", "Provider:", "Causes:" };
}
@Override
public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
request.setParameter(widgets.get("Date:"), dateAsString(date));
request.setParameter(widgets.get("Location:"), "2");
request.setParameter(widgets.get("Provider:"), "1");
request.setParameter(widgets.get("Causes:"), createJson);
}
@Override
public void testResults(SubmissionResults results) {
results.assertNoErrors();
results.assertEncounterCreated();
results.assertProvider(1);
results.assertLocation(2);
results.assertObsGroupCreatedCount(4);
results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeOne, sequenceConcept.getId(), 1);
results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeTwo, sequenceConcept.getId(), 2);
results.assertObsGroupCreated(groupingConcept.getConceptId(), nonCodedCauseConcept.getId(), causeThree, sequenceConcept.getId(), 3);
results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeFour, sequenceConcept.getId(), 4);
assertThat(results.getPatient().getCauseOfDeath(), is(causeFour));
}
@Override
public boolean doEditEncounter() {
return true;
}
@Override
public String[] widgetLabelsForEdit() {
return widgetLabels();
}
@Override
public void setupEditRequest(MockHttpServletRequest request, Map<String, String> widgets) {
request.setParameter(widgets.get("Date:"), dateAsString(date));
request.setParameter(widgets.get("Location:"), "2");
request.setParameter(widgets.get("Provider:"), "1");
request.setParameter(widgets.get("Causes:"), editJson);
}
@Override
public void testEditedResults(SubmissionResults results) {
results.assertNoErrors();
results.assertEncounterCreated();
results.assertProvider(1);
results.assertLocation(2);
// there should be one voided member obs (causeTwo->causeTwoEdited), and one voided obs group (causeThree)
// was causeThree
results.assertObsVoided(groupingConcept.getConceptId(), null);
assertVoidedObsInObsGroup(results.getEncounterCreated(), groupingConcept, codedCauseConcept, causeTwo);
results.assertObsGroupCreatedCount(3);
results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeOne, sequenceConcept.getId(), 1);
results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), editedCauseTwo, sequenceConcept.getId(), 2);
results.assertObsGroupCreated(groupingConcept.getConceptId(), nonCodedCauseConcept.getId(), editedCauseThree, sequenceConcept.getId(), 3);
assertThat(results.getPatient().getCauseOfDeath(), is(unknownConcept));
}
private void assertVoidedObsInObsGroup(Encounter encounter, Concept groupingConcept, Concept concept, Concept value) {
for (Obs candidate : encounter.getObsAtTopLevel(true)) {
if (groupingConcept.equals(candidate.getConcept())) {
for (Obs member : candidate.getGroupMembers(true)) {
if (member.getVoided() && member.getConcept().equals(concept) && member.getValueCoded().equals(value)) {
return;
}
}
}
}
Assert.fail("Did not find a voided obs of " + concept + "=" + value + " inside a group of " + groupingConcept);
}
}.run();
}
use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-pihcore by PIH.
the class FamilyHistoryRelativeCheckboxesTagHandlerTest method testCreateAndEdit.
@Test
public void testCreateAndEdit() throws Exception {
final Date date = new Date();
final Concept construct = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_CONSTRUCT);
final Concept which = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_DIAGNOSIS);
final Concept relative = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_RELATIONSHIP);
final Concept presence = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_PRESENCE);
final Concept comment = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_COMMENT);
new RegressionTestHelper() {
@Override
public String getXmlDatasetPath() {
return "";
}
@Override
public String getFormName() {
return "familyHistoryForm";
}
@Override
public String[] widgetLabels() {
// Cancer:!!1 is because we need to skip the text field that comes before the checkbox
return new String[] { "Date:", "Location:", "Provider:", "Asthma:", "Cancer:!!1", "zl.familyHistoryRelativeCheckboxes.specifyLabel" };
}
@Override
public void testBlankFormHtml(String html) {
System.out.println(html);
}
@Override
public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
request.setParameter(widgets.get("Date:"), dateAsString(date));
request.setParameter(widgets.get("Location:"), "2");
request.setParameter(widgets.get("Provider:"), "1");
request.setParameter(widgets.get("Asthma:"), father.getUuid());
request.setParameter(widgets.get("Cancer:!!1"), father.getUuid());
request.setParameter(widgets.get("zl.familyHistoryRelativeCheckboxes.specifyLabel"), "");
}
@Override
public void testResults(SubmissionResults results) {
results.assertNoErrors();
results.assertEncounterCreated();
results.assertObsGroupCreatedCount(2);
results.assertObsGroupCreated(construct.getConceptId(), which.getId(), ashthma, relative.getId(), father, presence.getId(), yes);
results.assertObsGroupCreated(construct.getConceptId(), which.getId(), cancer, relative.getId(), father, presence.getId(), yes);
}
@Override
public boolean doEditEncounter() {
return true;
}
@Override
public String[] widgetLabelsForEdit() {
return widgetLabels();
}
@Override
public void setupEditRequest(MockHttpServletRequest request, Map<String, String> widgets) {
request.setParameter(widgets.get("Date:"), dateAsString(date));
request.setParameter(widgets.get("Location:"), "2");
request.setParameter(widgets.get("Provider:"), "1");
// this is an unchecked checkbox (but HFE isn't smart enough to know this)
request.removeParameter(widgets.get("Asthma:"));
request.setParameter(widgets.get("Cancer:!!1"), father.getUuid());
request.setParameter(widgets.get("zl.familyHistoryRelativeCheckboxes.specifyLabel"), "Melanoma");
}
@Override
public void testEditedResults(SubmissionResults results) {
results.assertNoErrors();
results.assertEncounterCreated();
// there should be one voided obs group (asthma)
results.assertObsVoided(construct.getConceptId(), null);
// there should be one obs group (Cancer), now also with a comment
results.assertObsGroupCreatedCount(1);
results.assertObsGroupCreated(construct.getConceptId(), which.getId(), cancer, relative.getId(), father, presence.getId(), yes, comment.getId(), "Melanoma");
}
}.run();
}
Aggregations