Project: Implement Spring Data to LibreHealth Toolkit

@sunbiz Here’s the blog post for my last week’s progress https://medium.com/@yashdsaraf/gsoc-librehealth-finalizing-crud-for-patient-model-57aa57273360
There are a couple of serialization issues left and then CRUD for patient would be complete.

@sunbiz I’ve added all the Patient’s attributes to the primitive search mechanism I wrote. Also the error for primitive types getting detected as JSON is fixed, though I’m sure the fix can be optimised.
After a lot of trial I still haven’t figured out how to handle the Resource type using spring converters.
The culprit property in this case is contained which is of type List<Resource>. The problem here is if I write a converter for Resource I get a PersistentEntity not found error, and if I write a converter for List<Resource>, due to how the type is handled in Spring Data Cassandra, the generic type is erased and this converter is used for all the List<?> type properties. Any ideas?
P.S this means that if we ignore the contained property, complete CRUD for Patient works.

@sunbiz The Resource serialization has finally been fixed, I had to extend the CassandraMappingContext and tell it to ignore all the classes annotated with @Table. I’ll describe the issue and its fix more thoroughly in a blog post beside my weekly post.
I’m checking out @prashadi’s project now and trying to figure out which way to go to make our projects work together. Next I’ll work on adding more resources (specifically the ones mentioned in @prashadi’s blog post).

@yashdsaraf i’m going through your code base to merge with my code base. Shall we change the package name openmrs to librehealth?

@prashadi Let me merge the patient-crud branch into master then we can go on to renaming the package. Also I kept the name org.openmrs since that’s what is used in the original toolkit as well - see here.

1 Like

@yashdsaraf since we building the platform from the beginning, I think we can use librehealth.

1 Like

Alright, I’ve merged the patient-crud branch. Master is now up to date, we can make the changes now. I’ve also added you as a developer on the repository on gitlab.

@yashdsaraf thank you. One more question. Is your module require cassandra 3.x and is it a must?

I’m using SASI indexing to create secondary indexes for using LIKE operations on certain fields. I believe SASI support was introduced in Cassandra 3. Although I’m not sure if it works on earlier versions as well.

@sunbiz I’ve got the minimal properties of Observation model up and running, I’ll be able to push the complete model by tomorrow. I’ve also started working on the Encounter model, CRUD (without search) for both of these models should be ready in a couple of days.

@sunbiz I’ve encountered an obstacle in implementing Observation, this issue is that Observation has a property status with data type Enumeration<ObservationStatus> and again due to type erasure in Spring Cassandra’s conversion mechanism it is passed to the Enumeration<AdministrativeGender> converter instead.
I tried temporarily disabling the property by marking its getter/setters with @Transient but that doesn’t seem to work either.
I’ve tried other types of converters (ConverterFactory and GenericConverter) but none of them worked due to type erasure. (i.e Even though I write type specific converter say Enumeration<ObservationStatus>, the conversion mechanism passes all the Enumeration<?> data to it.)
We need a way for instructing the mechanism to use property specific converters or to notice the generic types.

@sunbiz I’ve pushed the Observation model and will be pushing the Encounter model today. My next step will be to migrate the existing routerfunctions to controllers and making the code mergeable for @prashadi 's project.

2 Likes

@yashdsaraf I have successfully configured your project to insert patient data with some minor modifications. After my demo data is inserted for patient, I’m getting following error when retrieving the patient list.

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [org.hl7.fhir.dstu3.model.HumanName] at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getReadValue(MappingCassandraConverter.j

Do you have any idea about this?

Also I got following exception while demo data is getting insert.

Caused by: com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.hl7.fhir.dstu3.model.Attachment[“creationElement”]->org.hl7.fhir.dstu3.model.DateTimeType[“tzSign”]) at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:391) at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:351) at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:727) at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3893) at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3207) at org.librehealth.fhir.platform.converter.ConvertUtils.toString(ConvertUtils.java:21) … 57 common frames omitted Caused by: java.lang.NullPointerException: null at org.hl7.fhir.dstu3.model.DateTimeType.getTzSign(DateTimeType.java:182) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:688) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) … 66 common frames omitted

And I change the converter as follow which might not be the right option.

public String toString(Object object) { try { return JacksonConfig.mapper.writeValueAsString(object); } catch (JsonProcessingException e) { return “”; } }

Do you think any other suggestion that we can overcome the above error? I have committed the code to master branch if you need to look at it.

@prashadi I fixed this error in one of my recent commits, see here

This can be fixed by adding a mixin for Attachment class and annotating the getCreationElement() function with @JsonIgnore. I think I can make a merge request for this, but it’ll take some time since I’m not near my setup right now.

1 Like

That’s great. Thanks for the clarification @yashdsaraf.

@sunbiz I’ve pushed the Encounter model as well and @prashadi I’ve migrated all the existing handlers to restcontrollers. I also added the fixes for issues you mentioned in the last post. I couldn’t do extensive testing of the CRUD operations after migrating to restcontrollers, I will make sure it’s done by the end of the day.

1 Like

@sunbiz @judywawira I’ve completed my final evaluation. Here’s my GSoC 2018 final report https://medium.com/@yashdsaraf/gsoc-librehealth-final-report-210538d56b19

@yashdsaraf that’s great. I was away for few days. I think we need to merge the new code from your branch and stabilize the modules. Is there any more changes that will come from you?

@prashadi I won’t be adding any new features for now, let’s first focus on getting the two projects to work together.

1 Like