Guide on how to properly extend the Patient model

We have a requirement to record patient insurer during patient registration. So we may need to add two fields

boolean insured; // true if patient is insured

Insurer insurer; // patient insurer

During patient registration, we have a checkbox insured and if it’s checked we select an insurer from a dropdown of insurers in the system. Now I’m trying to figure out how we’ll save this information together with the other recorded patient data.

I talked @dkayiwa on irc and he suggested I use person_attribute for this. But I’m not sure on how to proceed with it. I have seen this doc https://wiki.openmrs.org/display/docs/Managing+Person+Attribute+Types but it just shows me how to manage person attributes types from the admin page.

@ivange94 After installing the patient attributes, keep the track of their uuid values…

Then you can create a new copy of the registration app, adding a section like at https://github.com/METS-Programme/openmrs-module-aijar/blob/master/omod/src/main/resources/apps/aijar_registerpatient_app.json#L76-L94 (without the cssClasses) …

You can later change the insured to a radio button

If you find the above hard, you can also try out this: https://wiki.openmrs.org/display/docs/XForms+Module+Patient+Registration

@ssmusoke Unfortunately I’m not sure I can use this approach. The registration page(gsp page) already has too many customizations(not done by me) and I’m not sure how modifying this will affect that page considering it was only used to add an app icon on the home screen.

Just like I commented on @ssmusoke response, the registration page already has too many customizations and I’m assuming your suggestion says I should try out the xforms patient registration module.

What I have currently is this,

jq.getJSON("/openmrs/ws/rest/v1/insurer", function (response) {
     var html = "<select name='insurer'><option>Select Insurer</option>";
     jq.each(response.results, function () {
         html += '<option value="' + this.uuid + '">' + this.display + "</option>";
     });
     html += "</select>";
     jq("#paycatgs").html(html);
 }); 

So my thought is that when this form will be submitted, we’ll have two parameters,

insured=true&insurer={insurerUuid}

And I can retrieve a the selected insurer in the controller via

Insurer insurer = service.getInsurerByUuid(insurerUuid);

Now my problem is saving that information as a person attribute.

For REST calls, you could take a look at https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/PersonAttributeController1_9Test.java

@dkayiwa sorry if I’m not understanding what you are trying to pass across. Maybe you are wrongly assuming my knowledge of something or maybe my approach is wrong and we are talking of two different things.

When my form is submitted, I retrieved the insurer inside my java controller using

Insurer insurer = insurerService.getInsurer(insurerUuid); // insurerUuid was submitted as a request param

I can create a person attribute type from the UI and use a setting to retrieve it as you earlier suggested on irc.

Now what I’m not sure is what to do with my insurer object so I can save it with the patient record. The system already has a list of insurers added via an insurancemanagement module. What I am doing now is referencing these insurers when saving a patient record.

How do I make use of the person attribute type I created earlier here?

Are you looking for something like below?

Patient patient = new Patient();
PersonAttributeType attributeType = Context.getPersonService().getPersonAttributeTypeByUuid(attributeTypeUuid);
PersonAttribute personAttribute = new PersonAttribute(attributeType, insurerValue);
patient.setCreator(creator);
patient.setDateCreated(dateCreated);
patient.addAttribute(personAttribute);