[GSoC][LibreHealth] Finalizing CRUD for Patient model

Last week I figured out a workaround for getting the READ operation working, but the modeling for Patient getting retrieved as JSON from the database was not done. The output contained a lot of unwanted properties and properties in the wrong format.

Using Jackson mixins I eliminated all the unwanted properties with reference to https://www.hl7.org/fhir/patient.html. As far as the issue of primitive types getting displayed as JSON objects was concerned, I modified the TypeConverter, which is responsible for converting all objects of Type or any of its subclasses to strings.

The custom converters emit a strange characteristic in that the write converters are used to convert the objects of the target class and all its subclasses to a given primitive data type. For e.g A converter for converting objects of Type to String will be used for objects of PrimitiveType too which is a subclass of Type . But the read converters are used to convert the data from primitive type to only the given data type. For e.g A converter for converting objects of String to Type will not be used for objects of PrimitiveType.

So I modified the TypeConverter to check if the given object was primitive in nature, if yes, then only the value is stored, else the whole object is serialized. Fortunately all the PrimitiveType subclasses have a constructor with a single string parameter which is used by default by the Spring Data Cassandra’s mapping mechanism. This solved the issue for most of the properties, but the issue remains that some properties have multi type data i.e their assigned type is Type but can hold data with any of the sub types. For e.g deceased property has Type as its data type but can hold either BooleanType or DateType data. This poses a problem as during deserialization, Jackson is unable to determine what type of value it is dealing with.

Another issue is that we cannot create a converter for Resource since all the models extend it so Patient is directly serialized using the converter and we get the error saying No persistent entity found. To avoid this I made a converter for List<Resource> instead, but apparently the spring converters are not very good at handling generics i.e List<Resource> is handled as List<?> . Due to this all the properties with a List of some component are sent to this converter, serializing them all to a single string instead of a JSON array.

I believe that these issues can be solved using custom serializers/deserializers (I have already created one for XhtmlNode class). But this solution does not seem sustainable as I will have to manually determine in many cases what is the real data type of the given data.

I’ve implemented the CREATE, UPDATE and DELETE operations from the sample Patient model to the original one. This means that the couple of issues I mentioned above in READ operations and modifying search operation to handle original Patient model are the only tasks remaining after which CRUD for Patient would be complete.

Like what you read? Give Yash Saraf a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.