Person REST API - Filter type of person

How can we only get persons which are not users, patients, providers or at least get all persons with a similar name and filter them afterwards?

Have you tried feel free to carry out the experiment I believe you will get a clear picture.

Hi Juliet, Yes I have tried the demo…

this is for a new application for Bahmni.

We want to be able to add new persons not patients - so we are using the REST API post person.

However when we try to get the list we have added - we are using the REST API get person - this also returns users, and providers.

Is there an attribute we can use with REST API that we can filter the type of person or another way of achieving this?

Hi too Georgina, REST API just specify what it can provide and how to use it, details such as query parameters, response format, request limitations, public use/API keys, method e.t.c In short you will not get what you haven’t specified in your code

@gtl90 in the context of your app, does it make sense to distinguish specifically the persons that your app creates? If yes then you can just flank them with a specific person attribute upon creation. And query only for persons that carry that target attribute.

(I’m trusting that you’ve thought through the use case and you really want “just persons”; personally I would expect that anywhere you can use a person you could also use a person who’s a patient or a provider.)

This isn’t supported in either the core Java or REST API, so you’ll have to either add this, or do some kind of workaround.

You could add a module that adds a SQL or HQL query to do this, and then also expose this via REST.

Hi . Thank you so much for your advice. I am still fairly new to development so your help is appreciated. :smile:

This app is for persons that may become a patient in the future, or a relative of a patient however they are not an active patient or provider and by using the existing REST API the response includes all user data.

I was wondering if anyone in the community had needed this before or has done a successful work around.

When you say

My understanding is that your app handles a specific subset of persons (those that “may become patients”). By “handle” I mean both creates them in the first place, and subsequently does further operations with them.

If my understanding is correct and that your app creates the persons belonging to the subset in the first place, then I would set them with a custom person attribute. Your app queries would subsequently be made looking only for persons carrying that attribute.

Thank you for your time.

I have not created custom person attributes before using OPEN MRS, is there documentation or examples I can refer to? I attach the existing REST API I am using at the bottom of this message.

I want to keep this as standard as possible at the moment using the existing REST APIs too. Are there any custom/reserved objects (by objects i mean PersonType or would I need to append to existing object for a work around ) that I can use to store this this attribute in? which I then can use to call with the GET api?

{ “results”: [ { “uuid”: “”, “display”: “”, “gender”: “”, “age”: , “birthdate”: “”, “birthdateEstimated”: false, “dead”: false, “deathDate”: null, “causeOfDeath”: null, “preferredName”: { “display”: “”, “uuid”: “”, “givenName”: “”, “middleName”: null, “familyName”: “”, “familyName2”: null, “voided”: false, “links”: [ { “rel”: “self”, “uri”: “” }, { “rel”: “full”, “uri”: “” } ], “resourceVersion”: “1.8” }, “preferredAddress”: null, “names”: [ { “display”: “”, “uuid”: “”, “givenName”: “”, “middleName”: null, “familyName”: “”, “familyName2”: null, “voided”: false, “links”: [ { “rel”: “self”, “uri”: “” }, { “rel”: “full”, “uri”: “” } ], “resourceVersion”: “1.8” } ], “addresses”: [], “attributes”: [], “voided”: false, “auditInfo”: { “creator”: { “uuid”: “”, “display”: “”, “links”: [ { “rel”: “self”, “uri”: “” } ] }, “dateCreated”: “”, “changedBy”: null, “dateChanged”: null }, “deathdateEstimated”: false, “birthtime”: null, “links”: [ { “rel”: “self”, “uri”: “” } ], “resourceVersion”: “1.11” } ] }

For the sake of a proof of concept while you’re trying things out, just create a person attribute (‘PA’) type via the legacy admin UI. For example here on the official Ref App demo (but the relative path would be the same anywhere):

You could create a boolean PA type, such as “May Become Patient”. You should have your app create persons with the attribute “May Become Patient” set to true and use that criteria to fetch them.

1 Like

Hi @gtl90,

I am also trying to create a custom person attributes , did you find a documentation or examples to refer? :slight_smile:

Did you have a look at this:

It is not using API?

@isurun , did you mean creating custom person attributes using the rest API??

you can do a POST like

POST "http://localhost:8081/openmrs-standalone/ws/rest/v1/personattributetype" with a body like

  "name": "person_name",
  "description": "descriptionstring",
  "format": "java.lang.String",
  "foreignKey": 0,
  "sortWeight": 0,
  "searchable": true,
  "editPrivilege": {
    "name": "string",
    "description": "desc-string"
1 Like