# PatientProgam "voidLastState" object

**URL:** <https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978>\
**Category:** Development\
**Created:** [November 1, 2017, 9:48pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978 "2017-11-01T21:48:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mogoodrich](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mogoodrich/32/3324_2.png) [@mogoodrich](https://talk.openmrs.org/u/mogoodrich)\
**Post date:** [November 1, 2017, 9:48pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/1 "2017-11-01T21:48:06Z")

</div>

In core, the PatientState domain object has a “voidLastState(ProgramWorkflow)” utility method that voided the last (most recent) patient state for that patient within the specified workflow. This is what the REST module delegates to when deleting a state RESTfully.

There’s some business logic built int the method, namely that it sets the end date of the “next-to-last” patient state to null, which is generally the “right” behavior. That is if you have:

```
Pre-ART: Oct 1, 2017 to Oct 5, 2017
On ART: Oct 5 to Present

```

And delete, “On ART”, you end up with:

```
Pre-ART: Oct 1, 2017 to Present

```

The case when this doesn’t seem right is when a program is completed… for instance, say you have:

```
Program Completion Date: Oct 20, 2017
Pre-ART: Oct 1, 2017 to Oct 5, 2017
On ART: Oct 5 to Octo 20, 2017

```

If you delete the “On ART” in this case, you end up with:

```
Program Completion Date: Oct 20, 2017
Pre-ART: Oct 1, 2017 to Present

```

I would say the correct logic is to set the end date of the next-to-last state to “null” _if_ the program has not been completed, but, if not, set it to the completion date of the program?

Thoughts? And if people agree this should be changed, is this considered a bug and/or something we could backport all the way to 1.10.x?

Should be possible for me to just work around this in program widgets we are building in coreapps, but if people think it’s work changing in core, I’m willing to backport.

Take care, Mark

---

<div class="post-metadata">

**Author:** ![mogoodrich](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mogoodrich/32/3324_2.png) [@mogoodrich](https://talk.openmrs.org/u/mogoodrich)\
**Post date:** [November 1, 2017, 10:03pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/2 "2017-11-01T22:03:02Z")

</div>

Also, related to this, PatientProgram has the folllowing utility method to transition to a new state (which the REST module delegates to when adding new states):

`public void transitionToState(ProgramWorkflowState programWorkflowState, Date onDate)`

This method will set the end date of the current “last” state to the “onDate”, and then create a the new state with startDate = onDAte, and endDate = null.

In this case, do we want to set the endDate to the dateCompleted if the program is completed?

Or, as I’m thinking it through, maybe it is that we don’t want to allow a state transition (or voiding a state) after a program has been completed?

Take care, Mark

---

<div class="post-metadata">

**Author:** ![mogoodrich](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mogoodrich/32/3324_2.png) [@mogoodrich](https://talk.openmrs.org/u/mogoodrich)\
**Post date:** [November 2, 2017, 4:24pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/3 "2017-11-02T16:24:59Z")

</div>

@burke do you have any thoughts on this?

---

<div class="post-metadata">

**Author:** ![mogoodrich](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mogoodrich/32/3324_2.png) [@mogoodrich](https://talk.openmrs.org/u/mogoodrich)\
**Post date:** [November 3, 2017, 3:52pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/4 "2017-11-03T15:52:50Z")

</div>

So, as an update, although I do thing this is a bug, or at least a feature that should be implemented, the current behavior (not to set the end date of the most recent state in a workflow, regardless of whether the program has been completed or not) seems well established, so I was reluctant to change it and backport it. I created tickets for further discussion and shelved my current work in a branch, see:

> <https://issues.openmrs.org/browse/TRUNK-5228>

> <https://issues.openmrs.org/browse/TRUNK-5229>

> <https://issues.openmrs.org/browse/TRUNK-5230>

Take care! Mark

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [November 4, 2017, 5:58pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/5 "2017-11-04T17:58:30Z")

</div>

@mogoodrich how about a design call?

---

<div class="post-metadata">

**Author:** ![mogoodrich](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mogoodrich/32/3324_2.png) [@mogoodrich](https://talk.openmrs.org/u/mogoodrich)\
**Post date:** [November 6, 2017, 2:23pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/6 "2017-11-06T14:23:57Z")

</div>

I’m willing if others are interested… probably shouldn’t take a whole design call though… not a blocker on my part.

Take care, Mark

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [November 6, 2017, 4:06pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/7 "2017-11-06T16:06:13Z")

</div>

@jthomas what do you think?

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [November 6, 2017, 4:10pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/8 "2017-11-06T16:10:37Z")

</div>

Hey @mogoodrich were are on a design call now and do not seem to have any topic. Are you available?

---

<div class="post-metadata">

**Author:** ![mogoodrich](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mogoodrich/32/3324_2.png) [@mogoodrich](https://talk.openmrs.org/u/mogoodrich)\
**Post date:** [November 6, 2017, 5:06pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/9 "2017-11-06T17:06:21Z")

</div>

Oops, sorry… just got this now… did anyone have any thoughts on it? 🙂

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [November 6, 2017, 5:26pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/10 "2017-11-06T17:26:53Z")

</div>

@mogoodrich we decided to reschedule the discussion for some time when you could join.

---

<div class="post-metadata">

**Author:** ![jthomas](https://talk.openmrs.org/user_avatar/talk.openmrs.org/jthomas/32/21_2.png) [@jthomas](https://talk.openmrs.org/u/jthomas)\
**Post date:** [November 6, 2017, 5:27pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/11 "2017-11-06T17:27:04Z")

</div>

@mogoodrich this was not discussed on today’s design forum would Wednesday work for you?

---

<div class="post-metadata">

**Author:** ![mogoodrich](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mogoodrich/32/3324_2.png) [@mogoodrich](https://talk.openmrs.org/u/mogoodrich)\
**Post date:** [November 6, 2017, 5:31pm UTC](https://talk.openmrs.org/t/patientprogam-voidlaststate-object/13978/12 "2017-11-06T17:31:13Z")

</div>

Wednesday would work for me, thanks!
