use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-pihcore by PIH.
the class PastMedicalHistoryCheckboxTagHandlerTest method testCreateAndEdit.
@Test
public void testCreateAndEdit() throws Exception {
final Date date = new Date();
final Concept construct = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.PAST_MEDICAL_HISTORY_CONSTRUCT);
final Concept which = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.PAST_MEDICAL_HISTORY_FINDING);
final Concept presence = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.PAST_MEDICAL_HISTORY_PRESENCE);
final Concept comment = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.PAST_MEDICAL_HISTORY_COMMENT);
new RegressionTestHelper() {
@Override
public String getXmlDatasetPath() {
return "";
}
@Override
public String getFormName() {
return "pastMedicalHistoryForm";
}
@Override
public String[] widgetLabels() {
return new String[] { "Date:", "Location:", "Provider:", "Asthma:", "Epilepsy:", "STI:", "STI:!!1" };
}
@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:"), "present");
request.setParameter(widgets.get("STI:"), "present");
request.setParameter(widgets.get("STI:!!1"), "");
}
@Override
public void testResults(SubmissionResults results) {
results.assertNoErrors();
results.assertEncounterCreated();
results.assertObsGroupCreatedCount(2);
results.assertObsGroupCreated(construct.getConceptId(), which.getId(), ashthma, presence.getId(), yes);
results.assertObsGroupCreated(construct.getConceptId(), which.getId(), sti, 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:"));
// this is an unchecked checkbox (but HFE isn't smart enough to know this)
request.removeParameter(widgets.get("Epilepsy:"));
request.setParameter(widgets.get("STI:"), "present");
request.setParameter(widgets.get("STI:!!1"), "HIV");
}
@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 (STI), now also with a comment
results.assertObsGroupCreatedCount(1);
results.assertObsGroupCreated(construct.getConceptId(), which.getId(), sti, presence.getId(), yes, comment.getId(), "HIV");
}
}.run();
}
use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-coreapps by openmrs.
the class EncounterDispositionTagHandlerComponentTest method testShouldNotDisplayAdmissionLocationAfterEnteringDischargeDisposition.
@Test
public void testShouldNotDisplayAdmissionLocationAfterEnteringDischargeDisposition() throws Exception {
final Date date = new Date();
final DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
final Concept dischargeDisposition = HtmlFormEntryUtil.getConcept("org.openmrs.module.emrapi: Discharged");
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:"), dischargeDisposition.toString());
}
@Override
public boolean doViewEncounter() {
return true;
}
@Override
public void testViewingEncounter(Encounter encounter, String html) {
// make sure the admission location is not displayed (ie, has style="display:none;")
TestUtil.assertFuzzyContains("p id=\"[^\"]+\" style=\"display:none;\"><label><uimessage code=\"Admission Location\">", html);
}
}.run();
}
use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-coreapps by openmrs.
the class EncounterDiagnosesTagHandlerComponentTest method testHandleSubmissionHandlesValidSubmissionEnteringForm.
@Test
public void testHandleSubmissionHandlesValidSubmissionEnteringForm() throws Exception {
final int codedConceptId = 11;
ObjectMapper jackson = new ObjectMapper();
ArrayNode json = jackson.createArrayNode();
ObjectNode diagnosisNode = json.addObject();
diagnosisNode.put("certainty", "PRESUMED");
diagnosisNode.put("order", "PRIMARY");
diagnosisNode.put("diagnosis", CodedOrFreeTextAnswer.CONCEPT_PREFIX + codedConceptId);
final String jsonToSubmit = jackson.writeValueAsString(json);
final DiagnosisMetadata dmd = emrApiProperties.getDiagnosisMetadata();
final Date date = new Date();
new RegressionTestHelper() {
@Override
public String getXmlDatasetPath() {
return "";
}
@Override
public String getFormName() {
return "encounterDiagnosesSimpleForm";
}
@Override
public Map<String, Object> getFormEntrySessionAttributes() {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("uiUtils", new TestUiUtils() {
@Override
public String includeFragment(String providerName, String fragmentId, Map<String, Object> config) throws PageAction {
return "[[ included fragment " + providerName + "." + fragmentId + " here ]]";
}
});
return attributes;
}
@Override
public String[] widgetLabels() {
return new String[] { "Date:", "Location:", "Provider:", "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("encounterDiagnoses", jsonToSubmit);
}
@Override
public void testResults(SubmissionResults results) {
results.assertNoErrors();
results.assertEncounterCreated();
results.assertProvider(1);
results.assertLocation(2);
results.assertEncounterType(1);
results.assertObsCreatedCount(1);
results.assertObsGroupCreated(dmd.getDiagnosisSetConcept().getConceptId(), dmd.getDiagnosisCertaintyConcept().getId(), dmd.getConceptFor(Diagnosis.Certainty.PRESUMED), dmd.getDiagnosisOrderConcept().getId(), dmd.getConceptFor(Diagnosis.Order.PRIMARY), dmd.getCodedDiagnosisConcept().getId(), Context.getConceptService().getConcept(codedConceptId));
}
}.run();
}
use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-coreapps by openmrs.
the class EncounterDiagnosesTagHandlerComponentTest method testHandleSubmissionHandlesValidSubmissionEditingForm.
@Test
public void testHandleSubmissionHandlesValidSubmissionEditingForm() throws Exception {
final DiagnosisMetadata dmd = emrApiProperties.getDiagnosisMetadata();
final Date date = new Date();
// first, create an encounter
final Concept malaria = conceptService.getConcept(11);
final Patient patient = patientService.getPatient(8);
final Encounter existingEncounter = new Encounter();
existingEncounter.setEncounterType(new EncounterType(1));
existingEncounter.setPatient(patient);
existingEncounter.setEncounterDatetime(date);
existingEncounter.setLocation(locationService.getLocation(2));
Obs primaryDiagnosis = dmd.buildDiagnosisObsGroup(new Diagnosis(new CodedOrFreeTextAnswer(malaria), Diagnosis.Order.PRIMARY));
Obs secondaryDiagnosis = dmd.buildDiagnosisObsGroup(new Diagnosis(new CodedOrFreeTextAnswer("Unknown disease"), Diagnosis.Order.SECONDARY));
existingEncounter.addObs(primaryDiagnosis);
existingEncounter.addObs(secondaryDiagnosis);
encounterService.saveEncounter(existingEncounter);
ObjectMapper jackson = new ObjectMapper();
ArrayNode json = jackson.createArrayNode();
{
// change the existing primary diagnosis from PRESUMED to CONFIRMED
ObjectNode diagnosisNode = json.addObject();
diagnosisNode.put("certainty", "CONFIRMED");
diagnosisNode.put("order", "PRIMARY");
diagnosisNode.put("diagnosis", CodedOrFreeTextAnswer.CONCEPT_PREFIX + "11");
diagnosisNode.put("existingObs", primaryDiagnosis.getObsId());
}
{
// this is a new diagnosis
ObjectNode diagnosisNode = json.addObject();
diagnosisNode.put("certainty", "PRESUMED");
diagnosisNode.put("order", "SECONDARY");
diagnosisNode.put("diagnosis", CodedOrFreeTextAnswer.NON_CODED_PREFIX + "I had spelled it wrong before");
}
final String jsonToSubmit = jackson.writeValueAsString(json);
new RegressionTestHelper() {
@Override
public String getXmlDatasetPath() {
return "";
}
@Override
public String getFormName() {
return "encounterDiagnosesSimpleForm";
}
@Override
public Map<String, Object> getFormEntrySessionAttributes() {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("uiUtils", new TestUiUtils() {
@Override
public String includeFragment(String providerName, String fragmentId, Map<String, Object> config) throws PageAction {
return "[[ included fragment " + providerName + "." + fragmentId + " here ]]";
}
});
return attributes;
}
@Override
public Patient getPatientToView() throws Exception {
return patient;
}
@Override
public Encounter getEncounterToEdit() {
return existingEncounter;
}
@Override
public String[] widgetLabelsForEdit() {
return new String[] { "Date:", "Location:", "Provider:", "Encounter Type:" };
}
@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("Encounter Type:"), "1");
request.setParameter("encounterDiagnoses", jsonToSubmit);
}
@Override
public void testEditFormHtml(String html) {
System.out.println(html);
}
@Override
public void testEditedResults(SubmissionResults results) {
results.assertNoErrors();
results.assertEncounterEdited();
List<Obs> diagnoses = new ArrayList<Obs>();
for (Obs obs : results.getEncounterCreated().getObsAtTopLevel(true)) {
if (dmd.isDiagnosis(obs)) {
diagnoses.add(obs);
}
}
Matcher<Obs> newPrimary = new ObsGroupMatcher().withGroupingConcept(dmd.getDiagnosisSetConcept()).withNonVoidedObs(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(Diagnosis.Certainty.CONFIRMED)).withVoidedObs(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(Diagnosis.Certainty.PRESUMED)).withNonVoidedObs(dmd.getDiagnosisOrderConcept(), dmd.getConceptFor(Diagnosis.Order.PRIMARY)).withNonVoidedObs(dmd.getCodedDiagnosisConcept(), malaria);
Matcher<Obs> newSecondary = new ObsGroupMatcher().withGroupingConcept(dmd.getDiagnosisSetConcept()).withNonVoidedObs(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(Diagnosis.Certainty.PRESUMED)).withNonVoidedObs(dmd.getDiagnosisOrderConcept(), dmd.getConceptFor(Diagnosis.Order.SECONDARY)).withNonVoidedObs(dmd.getNonCodedDiagnosisConcept(), "I had spelled it wrong before");
Matcher<Obs> oldSecondary = new ObsGroupMatcher().withGroupingConcept(dmd.getDiagnosisSetConcept()).withVoidedObs(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(Diagnosis.Certainty.PRESUMED)).withVoidedObs(dmd.getDiagnosisOrderConcept(), dmd.getConceptFor(Diagnosis.Order.SECONDARY)).withVoidedObs(dmd.getNonCodedDiagnosisConcept(), "Unknown disease").thatIsVoided();
assertThat(diagnoses.size(), is(3));
assertThat(diagnoses, containsInAnyOrder(newPrimary, newSecondary, oldSecondary));
}
}.run();
}
use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-coreapps by openmrs.
the class EncounterDispositionTagHandlerComponentTest method testEnteringForm.
@Test
public void testEnteringForm() 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 void testResults(SubmissionResults results) {
results.assertNoErrors();
results.assertEncounterCreated();
results.assertProvider(1);
results.assertLocation(2);
results.assertEncounterType(1);
results.assertObsGroupCreatedCount(1);
results.assertObsGroupCreated(dispositionDescriptor.getDispositionSetConcept().getConceptId(), dispositionDescriptor.getDispositionConcept().getId(), admissionDisposition, dispositionDescriptor.getAdmissionLocationConcept().getId(), "1");
}
}.run();
}
Aggregations