Project: Implement Spring Data to LibreHealth Toolkit

toolkit
gsoc2018-project
gsoc2018

(Yash D. Saraf) #71

@sunbiz @namratanehete I’m working on the CREATE, UPDATE and DELETE operations for Patient.
I’m using https://www.hl7.org/fhir/http.html 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 https://www.hl7.org/fhir/http.html. 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.

@Transient
  @Override
  public AnimalComponent getAnimal() {
    return super.getAnimal();
  }

  @Column("animal")
  public AnimalComponent getDummyAnimal() {
    return super.getAnimal();
  }

  public void setDummyAnimal(AnimalComponent value) {
    super.setAnimal(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 https://www.hl7.org/fhir/patient.html.
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 - https://medium.com/@yashdsaraf/gsoc-librehealth-work-around-for-app-freezing-on-read-605dd2ed5c25


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


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


(Prashadi) #86

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


(Yash D. Saraf) #87

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.


(Prashadi) #88

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


(Yash D. Saraf) #89

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.


(Yash D. Saraf) #90

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