Skip to content

Commit

Permalink
remove code that makes sure time component of an encounter date isn't…
Browse files Browse the repository at this point in the history
… lost when editing an encounter with a form that only collects date (without time), as we are now handling this within the main HFE module
  • Loading branch information
mogoodrich committed Jun 17, 2021
1 parent dc52002 commit a71ed1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,6 @@ public SimpleObject submit(UiSessionContext sessionContext, @RequestParam("perso
? fes.getSubmissionActions().getEncountersToCreate().get(0)
: encounter;

// this will handled in HFE (and could be removed from here) as-of HFE 3.9.0, see: https://issues.openmrs.org/browse/HTML-678
// we don't want to lose any time information just because we edited it with a form that only collects date
if (fes.getContext().getMode() == FormEntryContext.Mode.EDIT
&& hasNoTimeComponent(formEncounter.getEncounterDatetime())) {
keepTimeComponentOfEncounterIfDateComponentHasNotChanged(fes.getContext().getPreviousEncounterDate(),
formEncounter);
}

// create a visit if necessary (note that this currently only works in real-time mode)
if (createVisit != null && (createVisit) && visit == null) {
visit = adtService.ensureActiveVisit(patient, sessionContext.getSessionLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,17 @@ public class EnterHtmlFormFragmentControllerComponentTest extends BaseModuleWebC

UiSessionContext sessionContext;

public static final String FORM_DEFINITION = "<htmlform formUuid=\"form-uuid\" formName=\"Form Name\" formVersion=\"1.0\" formEncounterType=\"61ae96f4-6afe-4351-b6f8-cd4fc383cce1\">Weight:<obs id=\"weight\" conceptId=\"5089\"/> <encounterDate showTime=\"true\"/> <encounterLocation/> <encounterProvider/></htmlform>";
public static final String FORM_DEFINITION = "<htmlform formUuid=\"form-uuid\" formName=\"Form Name\" formVersion=\"1.0\" formEncounterType=\"61ae96f4-6afe-4351-b6f8-cd4fc383cce1\">Weight:<obs id=\"weight\" conceptId=\"5089\"/> <encounterDate /> <encounterLocation/> <encounterProvider/></htmlform>";

public static final String FEATURE_TOGGLE_TEST_FORM_DEFINITION = "<htmlform formUuid=\"form-uuid\" formName=\"Form Name\" formVersion=\"1.0\" formEncounterType=\"61ae96f4-6afe-4351-b6f8-cd4fc383cce1\"> <includeIf velocityTest=\"$featureToggles.isFeatureEnabled('someFeatureToggle')\"> featureToggledOn </includeIf>"
+ "<encounterDate showTime=\"true\"/> <encounterLocation/> <encounterProvider/></htmlform>";
+ "<encounterDate/> <encounterLocation/> <encounterProvider/></htmlform>";

private EnterHtmlFormFragmentController controller;

@Before
public void before() throws Exception {

executeDataSet("enterHtmlFormFragmentControllerTestDataset.xml");

resourceFactory = mock(ResourceFactory.class);
when(resourceFactory.getResourceAsString("emr", "htmlforms/vitals.xml")).thenReturn(FORM_DEFINITION);

Expand All @@ -137,6 +136,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";
Expand All @@ -156,6 +156,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"));
Expand All @@ -178,12 +179,9 @@ public void testSubmittingHtmlFormDefinedInUiResource() throws Exception {

MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("w2", "70"); // weight in kg
request.addParameter("w5", dateString); // date
request.addParameter("w3hours", "0");
request.addParameter("w3minutes", "0");
request.addParameter("w3seconds", "0");
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, null, null, adtService,
featureToggles, ui, request);
Expand All @@ -202,6 +200,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"));
Expand All @@ -219,12 +218,9 @@ public void testSubmittingHtmlFormDefinedInUiResourceShouldCreateOpenVisit() thr

MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("w2", "70"); // weight in kg
request.addParameter("w5", dateString); // date
request.addParameter("w3hours", "0");
request.addParameter("w3minutes", "0");
request.addParameter("w3seconds", "0");
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, null, true, null, adtService,
featureToggles, ui, request);
Expand All @@ -233,13 +229,14 @@ public void testSubmittingHtmlFormDefinedInUiResourceShouldCreateOpenVisit() thr
Encounter created = encounterService.getEncountersByPatient(patient).get(0);

assertNotNull(created.getVisit());
assertThat(created.getEncounterDatetime(), DateMatchers.within(1, TimeUnit.SECONDS, new Date()));
assertThat(created.getVisit().getStartDatetime(), DateMatchers.within(1, TimeUnit.SECONDS, new Date()));
assertThat(created.getEncounterDatetime(), DateMatchers.within(2, TimeUnit.SECONDS, new Date()));
assertThat(created.getVisit().getStartDatetime(), DateMatchers.within(2, TimeUnit.SECONDS, new Date()));
assertNull(created.getVisit().getStopDatetime());
}

@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"));
Expand All @@ -259,12 +256,9 @@ public void testSubmittingHtmlFormDefinedInUiResourceShouldAssociateWithExisting

MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("w2", "70"); // weight in kg
request.addParameter("w5", dateString); // date
request.addParameter("w3hours", "0");
request.addParameter("w3minutes", "0");
request.addParameter("w3seconds", "0");
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, true, null, adtService,
featureToggles, ui, request);
Expand All @@ -277,169 +271,6 @@ public void testSubmittingHtmlFormDefinedInUiResourceShouldAssociateWithExisting
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 testEditingHtmlFormDefinedInUiResourceShouldNotChangeTimeOfEncounterDateIfNewDateHasNoTimeComponentAndIsNotDifferentFromCurrentDate()
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));

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, null, 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);

MockHttpServletRequest editRequest = new MockHttpServletRequest();
editRequest.addParameter("w2", "70"); // weight in kg
editRequest.addParameter("w5", dateString); // date
editRequest.addParameter("w3hours", "0"); /// note that we are zeroing out the hour, minute and day component
editRequest.addParameter("w3minutes", "0");
editRequest.addParameter("w3seconds", "0");
editRequest.addParameter("w7", "2"); // location = Xanadu
editRequest.addParameter("w9", "502"); // provider = Hippocrates

result = controller.submit(sessionContext, patient, hf, created, null, false, null, adtService, featureToggles, ui,
editRequest);
assertThat((Boolean) result.get("success"), is(Boolean.TRUE));
assertThat(encounterService.getEncountersByPatient(patient).size(), is(1));

// since the date we passed in the same Date as the existing encounter date, we don't want to have blown away
// the time component
assertThat(created.getEncounterDatetime(), is(initialEncounterDate));

}

@Test
public void testEditingHtmlFormDefinedInUiResourceShouldChangeTimeOfEncounterDateIfNewDateHasTimeComponentEvenIfNotDifferentFromCurrentDate()
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));

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, null, 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, 20, 20, 20, 0).toDate();
String updatedDateString = new SimpleDateFormat("yyyy-MM-dd").format(updatedEncounterDate);

MockHttpServletRequest editRequest = new MockHttpServletRequest();
editRequest.addParameter("w2", "70"); // weight in kg
editRequest.addParameter("w5", updatedDateString); // date
editRequest.addParameter("w3hours", "20"); /// note that we are zeroing out the hour, minute and day component
editRequest.addParameter("w3minutes", "20");
editRequest.addParameter("w3seconds", "20");
editRequest.addParameter("w7", "2"); // location = Xanadu
editRequest.addParameter("w9", "502"); // provider = Hippocrates

result = controller.submit(sessionContext, patient, hf, created, null, false, null, adtService, featureToggles, ui,
editRequest);
assertThat((Boolean) result.get("success"), is(Boolean.TRUE));
assertThat(encounterService.getEncountersByPatient(patient).size(), is(1));

// this the date we input has an updated time component, we want to have updated the encounter date
assertThat(created.getEncounterDatetime(), is(updatedEncounterDate));

}

@Test
public void testEditingHtmlFormDefinedInUiResourceShouldChangeTimeOfEncounterDateIfNewDateDifferentFromOldDate()
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));

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, null, 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, 22, 0, 0, 0, 0).toDate();
String updatedDateString = new SimpleDateFormat("yyyy-MM-dd").format(updatedEncounterDate);

MockHttpServletRequest editRequest = new MockHttpServletRequest();
editRequest.addParameter("w2", "70"); // weight in kg
editRequest.addParameter("w5", updatedDateString); // date
editRequest.addParameter("w3hours", "0"); /// note that we are zeroing out the hour, minute and day component
editRequest.addParameter("w3minutes", "0");
editRequest.addParameter("w3seconds", "0");
editRequest.addParameter("w7", "2"); // location = Xanadu
editRequest.addParameter("w9", "502"); // provider = Hippocrates

result = controller.submit(sessionContext, patient, hf, created, null, false, null, adtService, featureToggles, ui,
editRequest);
assertThat((Boolean) result.get("success"), is(Boolean.TRUE));
assertThat(encounterService.getEncountersByPatient(patient).size(), is(1));

// this the date we input has an updated time component, we want to have updated the encounter date
assertThat(created.getEncounterDatetime(), is(updatedEncounterDate));

}

@Test
public void testFeatureTogglingViaVelocityShouldNotShowFeatureIfToggledOff() throws Exception {
FragmentModel model = new FragmentModel();
Expand Down

0 comments on commit a71ed1b

Please sign in to comment.