REST API Visit Resource Post Behavior

I have just noticed the REST API wont prevent a user from starting/creating multiple visits of the same visit type with exactly the same startDatetime for the same patient. I want to know if this is intentional and if yes what would be the use case for it? Otherwise may be it is a bug.

I actually think this is something that needs to be discussed from the API level and not rest

At the API level, we intentionally allow overlapping visits. I had wanted to prevent this, but Burke pointed out the use case where the OpenMRS implementation is covering multiple facilities, and/or that you might have a facility visit at location X, but then do a telephone visit to location Y, etc. As I try to describe these use cases, they aren’t very convincing, so maybe Burke can restate them better. :slight_smile:

The reference application does not support overlapping visits, and it bombs if it finds these in the database.

I think it would make sense to introduce some validation about overlapping visits at the API level (e.g. can’t have overlapping visits at two locations where one is an ancestor of the other in location hierarchy).

You can definitely have concurrent active visits. Outpatient clinics are frequently adjacent to the hospital or part of the same building and we occasionally allow hospitalized patients to be taken to an outpatient visit if they are stable and can safely attend without disrupting their inpatient care (e.g., you’re in the hospital recovering from your foobotomy surgery and are allowed to be wheeled down to the eye clinic for a previously scheduled appointment). There could also be concurrent outpatient visits if patients are seeing two different clinics the same days (you can theorize of visits opening & closing in perfect succession, but that’s rarely how things work in the real world).

That said, it’s hard for me to imagine why/how a patient would have two concurrent visits of the same type. In other words, we could enforce that there could only be one active visit of the same type for the same patient. Out of the box, if we provide only “Inpatient” and “Outpatient” visit types, this would allow for an outpatient visit to occur during a hospital stay, but would prevent concurrent hospitalizations or concurrent outpatient visits. If an implementation wants to allow concurrent outpatient visits, they could define different types of visits (most implementations will want these anyway to easily distinguish between visits to different departments/specialists).

So is this a bug at the API level?

It is not a bug, it was intentional but we can be change the validation to support some of the use cases Burke and Darius mentioned