From fb916b80c6490e1a1e977ca905940fcda25f8cd6 Mon Sep 17 00:00:00 2001 From: icrc-toliveira Date: Mon, 24 May 2021 15:34:19 +0100 Subject: [PATCH 1/6] HTML-777 - Validate date in Edit mode --- .../htmlform/EnterHtmlFormFragmentController.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/omod/src/main/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentController.java b/omod/src/main/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentController.java index 0a5b14d..f7abcd0 100644 --- a/omod/src/main/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentController.java @@ -278,6 +278,19 @@ && hasNoTimeComponent(formEncounter.getEncounterDatetime())) { new FormSubmissionError("general-form-error", ui.message("htmlformentryui.datetimeBeforeVisitDate"))); } + if (validationErrors.size() > 0) { + return returnHelper(validationErrors, fes, null); + } + } else if(visit != null) { + if (encounter.getEncounterDatetime().before(visit.getStartDatetime())) { + validationErrors.add( + new FormSubmissionError("general-form-error", ui.message("htmlformentryui.datetimeAfterVisitDate"))); + } + + if (visit.getStopDatetime() != null && encounter.getEncounterDatetime().after(visit.getStopDatetime())) { + validationErrors.add( + new FormSubmissionError("general-form-error", ui.message("htmlformentryui.datetimeBeforeVisitDate"))); + } if (validationErrors.size() > 0) { return returnHelper(validationErrors, fes, null); } From f03b444c6db2fb58b7af046106a694d8390c7c52 Mon Sep 17 00:00:00 2001 From: icrc-toliveira Date: Fri, 28 May 2021 10:03:40 +0100 Subject: [PATCH 2/6] HTML-777 - Ident the file using the install --- .../htmlform/EnterHtmlFormFragmentController.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentController.java b/omod/src/main/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentController.java index f7abcd0..c974e59 100644 --- a/omod/src/main/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentController.java @@ -281,15 +281,12 @@ && hasNoTimeComponent(formEncounter.getEncounterDatetime())) { if (validationErrors.size() > 0) { return returnHelper(validationErrors, fes, null); } - } else if(visit != null) { + } else if (visit != null) { if (encounter.getEncounterDatetime().before(visit.getStartDatetime())) { - validationErrors.add( - new FormSubmissionError("general-form-error", ui.message("htmlformentryui.datetimeAfterVisitDate"))); + validationErrors.add(new FormSubmissionError("general-form-error", ui.message("htmlformentryui.datetimeAfterVisitDate"))); } - if (visit.getStopDatetime() != null && encounter.getEncounterDatetime().after(visit.getStopDatetime())) { - validationErrors.add( - new FormSubmissionError("general-form-error", ui.message("htmlformentryui.datetimeBeforeVisitDate"))); + validationErrors.add(new FormSubmissionError("general-form-error", ui.message("htmlformentryui.datetimeBeforeVisitDate"))); } if (validationErrors.size() > 0) { return returnHelper(validationErrors, fes, null); From ad829665c59e853ac619bff3c4798f330c6e942b Mon Sep 17 00:00:00 2001 From: icrc-toliveira Date: Thu, 1 Jul 2021 16:20:44 +0100 Subject: [PATCH 3/6] HTML-777 - Add test for Changing date in edit mode --- ...mlFormFragmentControllerComponentTest.java | 60 ++++++++++++++++++- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java b/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java index 0fd2f46..1331ad1 100644 --- a/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java +++ b/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java @@ -55,9 +55,7 @@ import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -385,6 +383,62 @@ public void testEditingHtmlFormDefinedInUiResourceShouldChangeTimeOfEncounterDat } + @Test + public void testEditingHtmlFormDefinedInUiResourceShouldNotChangeTimeOfEncounterDateIfNewDateIsPriorToDateOfVisit() + throws Exception { + // first, ensure the form is created and persisted, by calling the controller display method + testDefiningAnHtmlFormInUiResource(); + HtmlForm hf = htmlFormEntryService.getHtmlFormByForm(formService.getFormByUuid("form-uuid")); + + // make "Hippocrates" a provider + Provider provider = new Provider(); + provider.setPerson(personService.getPerson(502)); + providerService.saveProvider(provider); + + Patient patient = patientService.getPatient(8); + assertThat(encounterService.getEncountersByPatient(patient).size(), is(0)); + + Visit visit = visitService.getVisit(1001); + visit.setStartDatetime(new DateTime(2012, 1, 20, 10, 10, 10, 0).toDate()); + + Date initialEncounterDate = new DateTime(2012, 1, 20, 10, 10, 10, 0).toDate(); + String dateString = new SimpleDateFormat("yyyy-MM-dd").format(initialEncounterDate); + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("w2", "70"); // weight in kg + request.addParameter("w5", dateString); // date + request.addParameter("w3hours", "10"); + request.addParameter("w3minutes", "10"); + request.addParameter("w3seconds", "10"); + request.addParameter("w7", "2"); // location = Xanadu + request.addParameter("w9", "502"); // provider = Hippocrates + + SimpleObject result = controller.submit(sessionContext, patient, hf, null, visit, false, null, adtService, + featureToggles, ui, request); + assertThat((Boolean) result.get("success"), is(Boolean.TRUE)); + assertThat(encounterService.getEncountersByPatient(patient).size(), is(1)); + Encounter created = encounterService.getEncountersByPatient(patient).get(0); + + Date updatedEncounterDate = new DateTime(2012, 1, 20, 9, 10, 10, 0).toDate(); + String updatedDateString = new SimpleDateFormat("yyyy-MM-dd").format(updatedEncounterDate); + + created.setEncounterDatetime(updatedEncounterDate); + + MockHttpServletRequest editRequest = new MockHttpServletRequest(); + editRequest.addParameter("w2", "70"); // weight in kg + editRequest.addParameter("w5", updatedDateString); // date + editRequest.addParameter("w3hours", "9"); /// note that we are zeroing out the hour, minute and day component + editRequest.addParameter("w3minutes", "10"); + editRequest.addParameter("w3seconds", "10"); + editRequest.addParameter("w7", "2"); // location = Xanadu + editRequest.addParameter("w9", "502"); // provider = Hippocrates + + result = controller.submit(sessionContext, patient, hf, created, visit, false, null, adtService, featureToggles, ui, + editRequest); + assertThat((Boolean) result.get("success"), is(Boolean.FALSE)); + assertNotNull(result.get("errors")); + } + @Test public void testEditingHtmlFormDefinedInUiResourceShouldChangeTimeOfEncounterDateIfNewDateDifferentFromOldDate() throws Exception { From 2173976636269c9ee936e20190b1b8f89e933741 Mon Sep 17 00:00:00 2001 From: icrc-toliveira Date: Thu, 1 Jul 2021 16:47:18 +0100 Subject: [PATCH 4/6] HTML-777 - Resolve conflict --- ...mlFormFragmentControllerComponentTest.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java b/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java index f2f6bc6..68c056d 100644 --- a/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java +++ b/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java @@ -285,21 +285,17 @@ public void testEditingHtmlFormDefinedInUiResourceShouldNotChangeTimeOfEncounter assertThat(encounterService.getEncountersByPatient(patient).size(), is(0)); Visit visit = visitService.getVisit(1001); - visit.setStartDatetime(new DateTime(2012, 1, 20, 10, 10, 10, 0).toDate()); - Date initialEncounterDate = new DateTime(2012, 1, 20, 10, 10, 10, 0).toDate(); - String dateString = new SimpleDateFormat("yyyy-MM-dd").format(initialEncounterDate); + Date date = new DateMidnight(2012, 1, 20).toDate(); + String dateString = new SimpleDateFormat("yyyy-MM-dd").format(date); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("w2", "70"); // weight in kg - request.addParameter("w5", dateString); // date - request.addParameter("w3hours", "10"); - request.addParameter("w3minutes", "10"); - request.addParameter("w3seconds", "10"); - request.addParameter("w7", "2"); // location = Xanadu - request.addParameter("w9", "502"); // provider = Hippocrates + request.addParameter("w3", dateString); // date + request.addParameter("w5", "2"); // location = Xanadu + request.addParameter("w7", "502"); // provider = Hippocrates - SimpleObject result = controller.submit(sessionContext, patient, hf, null, visit, false, null, adtService, + SimpleObject result = controller.submit(sessionContext, patient, hf, null, visit, true, null, adtService, featureToggles, ui, request); assertThat((Boolean) result.get("success"), is(Boolean.TRUE)); assertThat(encounterService.getEncountersByPatient(patient).size(), is(1)); @@ -313,11 +309,8 @@ public void testEditingHtmlFormDefinedInUiResourceShouldNotChangeTimeOfEncounter MockHttpServletRequest editRequest = new MockHttpServletRequest(); editRequest.addParameter("w2", "70"); // weight in kg editRequest.addParameter("w5", updatedDateString); // date - editRequest.addParameter("w3hours", "9"); /// note that we are zeroing out the hour, minute and day component - editRequest.addParameter("w3minutes", "10"); - editRequest.addParameter("w3seconds", "10"); - editRequest.addParameter("w7", "2"); // location = Xanadu - editRequest.addParameter("w9", "502"); // provider = Hippocrates + editRequest.addParameter("w5", "2"); // location = Xanadu + editRequest.addParameter("w7", "502"); // provider = Hippocrates result = controller.submit(sessionContext, patient, hf, created, visit, false, null, adtService, featureToggles, ui, editRequest); From f0f63458d7c0173b71cc8e3eb188ef9a11d28d71 Mon Sep 17 00:00:00 2001 From: icrc-toliveira Date: Thu, 1 Jul 2021 16:53:16 +0100 Subject: [PATCH 5/6] HTML-777 - Clean indentation --- ...mlFormFragmentControllerComponentTest.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java b/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java index 68c056d..8f8e24a 100644 --- a/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java +++ b/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java @@ -134,7 +134,7 @@ public void before() throws Exception { @Test public void testDefiningAnHtmlFormInUiResource() throws Exception { - + FragmentModel model = new FragmentModel(); Patient patient = new Patient(); String resourcePath = "emr:htmlforms/vitals.xml"; @@ -154,7 +154,7 @@ public void testDefiningAnHtmlFormInUiResource() throws Exception { @Test public void testSubmittingHtmlFormDefinedInUiResource() throws Exception { - + // first, ensure the form is created and persisted, by calling the controller display method testDefiningAnHtmlFormInUiResource(); HtmlForm hf = htmlFormEntryService.getHtmlFormByForm(formService.getFormByUuid("form-uuid")); @@ -198,7 +198,7 @@ public void testSubmittingHtmlFormDefinedInUiResource() throws Exception { @Test public void testSubmittingHtmlFormDefinedInUiResourceShouldCreateOpenVisit() throws Exception { - + // first, ensure the form is created and persisted, by calling the controller display method testDefiningAnHtmlFormInUiResource(); HtmlForm hf = htmlFormEntryService.getHtmlFormByForm(formService.getFormByUuid("form-uuid")); @@ -234,7 +234,7 @@ public void testSubmittingHtmlFormDefinedInUiResourceShouldCreateOpenVisit() thr @Test public void testSubmittingHtmlFormDefinedInUiResourceShouldAssociateWithExistingVisit() throws Exception { - + // first, ensure the form is created and persisted, by calling the controller display method testDefiningAnHtmlFormInUiResource(); HtmlForm hf = htmlFormEntryService.getHtmlFormByForm(formService.getFormByUuid("form-uuid")); @@ -268,56 +268,56 @@ public void testSubmittingHtmlFormDefinedInUiResourceShouldAssociateWithExisting assertThat(created.getVisit(), is(visit)); assertThat(created.getEncounterDatetime(), is(visit.getStartDatetime())); // make sure the encounter date has been shifted to match the visit start time of 10:10:10 } - + @Test public void testEditingHtmlFormDefinedInUiResourceShouldNotChangeTimeOfEncounterDateIfNewDateIsPriorToDateOfVisit() - throws Exception { + throws Exception { // first, ensure the form is created and persisted, by calling the controller display method testDefiningAnHtmlFormInUiResource(); HtmlForm hf = htmlFormEntryService.getHtmlFormByForm(formService.getFormByUuid("form-uuid")); - + // make "Hippocrates" a provider Provider provider = new Provider(); provider.setPerson(personService.getPerson(502)); providerService.saveProvider(provider); - + Patient patient = patientService.getPatient(8); assertThat(encounterService.getEncountersByPatient(patient).size(), is(0)); - + Visit visit = visitService.getVisit(1001); - + Date date = new DateMidnight(2012, 1, 20).toDate(); String dateString = new SimpleDateFormat("yyyy-MM-dd").format(date); - + MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("w2", "70"); // weight in kg request.addParameter("w3", dateString); // date request.addParameter("w5", "2"); // location = Xanadu request.addParameter("w7", "502"); // provider = Hippocrates - + SimpleObject result = controller.submit(sessionContext, patient, hf, null, visit, true, null, adtService, - featureToggles, ui, request); + featureToggles, ui, request); assertThat((Boolean) result.get("success"), is(Boolean.TRUE)); assertThat(encounterService.getEncountersByPatient(patient).size(), is(1)); Encounter created = encounterService.getEncountersByPatient(patient).get(0); - + Date updatedEncounterDate = new DateTime(2012, 1, 20, 9, 10, 10, 0).toDate(); String updatedDateString = new SimpleDateFormat("yyyy-MM-dd").format(updatedEncounterDate); - + created.setEncounterDatetime(updatedEncounterDate); - + MockHttpServletRequest editRequest = new MockHttpServletRequest(); editRequest.addParameter("w2", "70"); // weight in kg editRequest.addParameter("w5", updatedDateString); // date editRequest.addParameter("w5", "2"); // location = Xanadu editRequest.addParameter("w7", "502"); // provider = Hippocrates - + result = controller.submit(sessionContext, patient, hf, created, visit, false, null, adtService, featureToggles, ui, - editRequest); + editRequest); assertThat((Boolean) result.get("success"), is(Boolean.FALSE)); assertNotNull(result.get("errors")); } - + @Test public void testFeatureTogglingViaVelocityShouldNotShowFeatureIfToggledOff() throws Exception { FragmentModel model = new FragmentModel(); From 2895a056401d27d8f2f5345100955271567adc3b Mon Sep 17 00:00:00 2001 From: icrc-toliveira Date: Thu, 8 Jul 2021 16:34:23 +0100 Subject: [PATCH 6/6] HTML-777 - Fix error found in testEditingHtmlFormDefinedInUiResourceShouldNotChangeTimeOfEncounterDateIfNewDateIsPriorToDateOfVisit --- .../htmlform/EnterHtmlFormFragmentControllerComponentTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java b/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java index 8f8e24a..98613c5 100644 --- a/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java +++ b/omod/src/test/java/org/openmrs/module/htmlformentryui/fragment/controller/htmlform/EnterHtmlFormFragmentControllerComponentTest.java @@ -308,7 +308,7 @@ public void testEditingHtmlFormDefinedInUiResourceShouldNotChangeTimeOfEncounter MockHttpServletRequest editRequest = new MockHttpServletRequest(); editRequest.addParameter("w2", "70"); // weight in kg - editRequest.addParameter("w5", updatedDateString); // date + editRequest.addParameter("w3", updatedDateString); // date editRequest.addParameter("w5", "2"); // location = Xanadu editRequest.addParameter("w7", "502"); // provider = Hippocrates