Project: Implement Spring Data to LibreHealth Toolkit


(Yash D. Saraf) #66

@sunbiz I’ve added a data loader similar to the pre-requisite task project which retrieves sample resources from a FHIR server and the data is saved in the database just fine (except for StackOverFlow errors with Jackson which were solved using Gson instead), but retrieving data back from the database gets stuck for some reason without throwing any errors whatsoever.
I’ve succesfully tried logging the queries being executed so the error is not on the cassandra part. It seems the error must be somewhere in data conversion, I’ll keep you posted on this.

PS: Data retrieval worked fine when I was using a sample Patient model.

(Saptarshi Purkayastha) #67

@yashdsaraf by when do you think you will be able to support the CRUD on the full Patient resource at least? I want to start thinking about the way to distribute this such that it can be an EHR platform. i.e. support Authentication, module assembly etc?

(Yash D. Saraf) #68

@sunbiz As I said in my previous post I’m able to save the Patient which means implementing the Update and Delete functionalities should be quite straight forward as well. Once the READ operation is entirely sorted out, others shouldn’t take much longer. I’m working on fixing the no output issue I mentioned earlier, once that’s done I’ll be able to give you a much better answer as to when the CRUD support will be complete.

That sounds exciting! :grinning:

(Yash D. Saraf) #69

@sunbiz I’ve tried debugging the app to find where the app gets hung up, all I know this far is that CQL queries are executed successfully and the ResourceConverter is the last one to get executed before the app gets stuck. I also tried to make a custom model using just a single data type from HAPI FHIR structures e.g IdType where the app didn’t get stuck but Jackson threw some mapping errors which I’m afraid will come later in our app as well. I’m currently trying to get a non reactive version of the app working, I’ll get back to you with the progress in some time.

(Yash D. Saraf) #70

@sunbiz The non reactive version didn’t work either. It seems I’m back to square one regarding this error, it would be great if you could give the code a try

Here’s what I know so far,

  • Saving works but the app freezes on select operation without any error or output
  • Select queries are successfully executed (you can enable logging from so the error is not in the CQL queries
  • I used the debugger to track all the converters and they were successfully executed as well
  • Execution doesn’t reach the stage where the CustomPatient object is converted to JSON to be returned to the browser. (I know this because Jackson errors out on UriType fields and there are no such errors in this case.)

Any ideas on how to solve or debug this?

(Yash D. Saraf) #71

@sunbiz @namratanehete I’m working on the CREATE, UPDATE and DELETE operations for Patient.
I’m using for reference.
It says that

servers MAY choose to allow clients to PUT a resource to a location that does not yet exist on the server - effectively, allowing the client to define the id of the resource.

Do we want to allow creating a resource with unknown id using PUT?

(Saptarshi Purkayastha) #72

Yes, I think we should allow it.

(Yash D. Saraf) #73

@sunbiz I’ve implemented CRUD on sample patient model, referring to Here’s the gist of the code.
I also figured out a way out of Jackson mapping errors, since we can’t directly annotate the HAPI models, we can use Jackson Mixins to overcome stackoverflow errors and we can choose which properties are displayed and which ones aren’t.
For the READ error, I created a sample spring project with spring boot snapshot version and it is throwing some mapping errors (unlike our original app which just keeps on loading without any output or error whatsoever). I’d like to go down this rabbit hole for now and see where it leads. I’ll report back the progress in some time.

(Yash D. Saraf) #74

@sunbiz The snapshot eventually started freezing on READ as well. So I took the long way around and started eliminating all the properties in Patient to isolate the cause of the error. Finally after trimming down Patient to just a couple of properties the READ operation started working. I will start enabling the properties that need to be persisted today, I’m confident that this will finally complete the READ operation.

(Saptarshi Purkayastha) #75

@yashdsaraf do you have a branch where I can test this on? I would like to see @prashadi and you working off the same codebase now, that you are both fairly well into your projects.

Can you please provide your repos that I can use to cherry-pick and move to the librehealth org in gitlab?

(Yash D. Saraf) #76

@sunbiz I found the error as to why the app got stuck on READ operation. Apparently the spring cassandra’s mapping converter could not find setters for some properties. For e.g For Animal property I was getting

java.lang.NoSuchMethodError: org.hl7.fhir.dstu3.model.Patient.setAnimal(Lorg/hl7/fhir/dstu3/model/Patient$AnimalComponent;)V 

But using a very strange workaround of marking animal as transient and creating getter/setter with a different name got the app working.

  public AnimalComponent getAnimal() {
    return super.getAnimal();

  public AnimalComponent getDummyAnimal() {
    return super.getAnimal();

  public void setDummyAnimal(AnimalComponent value) {

My guess is this error was not recognized by the reactive stream and it just kept waiting for the data. This is why the app froze every time a GET query was fired.
I’ve pushed the code with updated mixins, converters and this workaround at link.
I’d recommend to not cherry pick the commits just yet, since we know the workaround for the error now, I can get the whole patient model working. I’ll try to push the whole working patient model by tonight as well as a blog post about the workaround.

(Saptarshi Purkayastha) #77

ok, I’ll wait, but please update us soon. We are already a week into phase 2 of GSoC

(Yash D. Saraf) #78

@sunbiz I’ve pushed the code with working READ operation and modeled Patient to look like
There are some issues where the data retrieved is showed as JSON instead of primitive types, I’m working on fixing that now.

(Yash D. Saraf) #79

@sunbiz Here’s the blog post regarding the workaround and CRUD operations for sample Patient model -

(Yash D. Saraf) #80

@sunbiz I’ve added the save and update functions for Patient and fixed the incorrect serialization issues for a lot of properties. There are still some issues when generic types such as Type and Resource are serialized, I’m working on fixing those.

(Yash D. Saraf) #81

@sunbiz Here’s the blog post for my last week’s progress
There are a couple of serialization issues left and then CRUD for patient would be complete.

(Yash D. Saraf) #82

@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.

(Yash D. Saraf) #83

@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).

(Prashadi) #84

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

(Yash D. Saraf) #85

@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.