We are trying to push encounter-obs data for a Boolean concept via REST. Trying inserting data we found that if value is 0/1 for boolean concept, OpenMRS always considers it as FALSE. But sending data as true/false works fine i.e. interpreted correctly. Is this expected behaviour i.e. not allowing 0/1 instead of true/false for boolean concepts. Shouldn’t it throw exception if data is not in correct format?
Hi - Did Boolean concept accept 0/1 values previously? We were under this assumption and set up our data collection forms to accept 0/1 values, which are then used in various analyses and calculations within the form. Allowing Boolean concept to accept 0/1 would be very beneficial to our project. Would this be an option?
Since OpenMRS 1.7.0 (released in 2010), observations for boolean concepts have been stored in the database as coded concepts (TRUE or FALSE). Prior to this, they used to be stored in the database as 1/0, but it has been a very long time since that was the case.
I suppose it would be okay to make the REST interface even more liberal in what it accepts as input, e.g. accept any of 1/0, true/false, “true”/“false”, or uuids for the true/false concepts.
But do you really need this? If you’re calling the REST web service, couldn’t your code just send true or false when submitting data?
The REST service should be smart enough to properly interpret TRUE & FALSE (case-insensitive) as well as 0 & 1 as values (either literal or string form) for a boolean concept and do the right thing. As @darius mentioned, we always store booleans as coded values under the hood, but clients of REST shouldn’t be forced to learn our data model or business rules.
If I sent any/all of the following as boolean properties within a JSON message (focusing just on the formats of the values for this example):
I would expect the REST API to be able to interpret them into corresponding boolean values of true or false. If the REST API couldn’t handle any of these forms, I would consider it a bug (or at least a poor choice). We (OpenMRS in our APIs) need to be doing a better job of encapsulation (rather than making clients work against our data model or perform our business rules for us) and, in the process, make our APIs higher level and easier for clients to learn & use.
@dkayiwa you need to create a new ticket for this change, and attach it to
an unreleased fix version, so that people can properly interpret this in
the release notes.