Patient Registration Page - Identifier Type Input

I am currently linking the REST Api to the Patient Registration page in the OpenMRS Android Client.

The Patient creation REST Api takes in two inputs…a person field, which is what takes in the form inputs from the user, and an identifier field, of the following form:

"identifiers": [{
    "identifierType": "05a29f94-c0ed-11e2-94be-8c13b969e334",
    "identifier": "9AW2N9PHC7WJ2FC7YLV",                
    "location": "8d6c993e-c2cc-11de-8d13-0010c6dffd0f"
  }]

In case of the Android app, what should I fill this field with?

GET

http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patientidentifiertype

Returns

{
    "results": [{
        "uuid": "05a29f94-c0ed-11e2-94be-8c13b969e334",
        "display": "OpenMRS ID",
        "links": [{
            "rel": "self",
            "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patientidentifiertype/05a29f94-c0ed-11e2-94be-8c13b969e334"
        }]
    }, {
        "uuid": "8d79403a-c2cc-11de-8d13-0010c6dffd0f",
        "display": "Old Identification Number",
        "links": [{
            "rel": "self",
            "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patientidentifiertype/8d79403a-c2cc-11de-8d13-0010c6dffd0f"
        }]
    }, {
        "uuid": "8d793bee-c2cc-11de-8d13-0010c6dffd0f",
        "display": "OpenMRS Identification  Number",
        "links": [{
            "rel": "self",
            "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patientidentifiertype/8d793bee-c2cc-11de-8d13-0010c6dffd0f"
        }]
    }]
}

Should this be user selectable?

Tagging @raff for comments.

I created a patient via the UI on that server. When I access the created patient via the API I get:

curl -u admin:Admin123 http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patient/0b8a6614-ece0-40ff-9501-c8d821502a70/identifier
{
    "results": [{
        "display": "OpenMRS ID = 10005K",
        "uuid": "40b65e70-1d45-4256-82b9-085ba93e34c3",
        "identifier": "10005K",
        "identifierType": {
            "uuid": "05a29f94-c0ed-11e2-94be-8c13b969e334",
            "display": "OpenMRS ID",
            "links": [{
                "rel": "self",
                "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patientidentifiertype/05a29f94-c0ed-11e2-94be-8c13b969e334"
            }]
        },
        "location": {
            "uuid": "7fdfa2cb-bc95-405a-88c6-32b7673c0453",
            "display": "Laboratory",
            "links": [{
                "rel": "self",
                "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/location/7fdfa2cb-bc95-405a-88c6-32b7673c0453"
            }]
        },
        "preferred": true,
        "voided": false,
        "links": [{
            "rel": "self",
            "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patient/0b8a6614-ece0-40ff-9501-c8d821502a70/identifier/40b65e70-1d45-4256-82b9-085ba93e34c3"
        }, {
            "rel": "full",
            "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patient/0b8a6614-ece0-40ff-9501-c8d821502a70/identifier/40b65e70-1d45-4256-82b9-085ba93e34c3?v=full"
        }],
        "resourceVersion": "1.8"
    }]
}

It appears that an ID of type OpenMRS ID is created, so if you want the same behaviour as the Reference Application, that’s what you should use.

However, if you want your app to work with any OpenMRS backend server, it would have to be more dynamic.

If you get the full representations from the patientidentifiertype resource, you get the following:

curl -u admin:Admin123 http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patientidentifiertype\?v\=full
{
    "results": [{
        "uuid": "05a29f94-c0ed-11e2-94be-8c13b969e334",
        "display": "OpenMRS ID",
        "name": "OpenMRS ID",
        "description": "OpenMRS patient identifier, with check-digit",
        "format": null,
        "formatDescription": null,
        "required": true,
        "checkDigit": true,
        "validator": "org.openmrs.module.idgen.validator.LuhnMod30IdentifierValidator",
        "locationBehavior": null,
        "uniquenessBehavior": null,
        "retired": false,
        "auditInfo": {
            "creator": {
                "uuid": "A4F30A1B-5EB9-11DF-A648-37A07F9C90FB",
                "display": "daemon",
                "links": [{
                    "rel": "self",
                    "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/user/A4F30A1B-5EB9-11DF-A648-37A07F9C90FB"
                }]
            },
            "dateCreated": "2016-05-24T11:53:18.000-0900",
            "changedBy": null,
            "dateChanged": null
        },
        "links": [{
            "rel": "self",
            "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patientidentifiertype/05a29f94-c0ed-11e2-94be-8c13b969e334"
        }],
        "resourceVersion": "1.8"
    }, {
        "uuid": "8d79403a-c2cc-11de-8d13-0010c6dffd0f",
        "display": "Old Identification Number",
        "name": "Old Identification Number",
        "description": "Number given out prior to the OpenMRS system (No check digit)",
        "format": "",
        "formatDescription": null,
        "required": false,
        "checkDigit": false,
        "validator": null,
        "locationBehavior": null,
        "uniquenessBehavior": null,
        "retired": false,
        "auditInfo": {
            "creator": {
                "uuid": "ba62cf2e-2194-11e6-b260-28d2440db56c",
                "display": "admin",
                "links": [{
                    "rel": "self",
                    "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/user/ba62cf2e-2194-11e6-b260-28d2440db56c"
                }]
            },
            "dateCreated": "2005-09-22T00:00:00.000-0900",
            "changedBy": null,
            "dateChanged": null
        },
        "links": [{
            "rel": "self",
            "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patientidentifiertype/8d79403a-c2cc-11de-8d13-0010c6dffd0f"
        }],
        "resourceVersion": "1.8"
    }, {
        "uuid": "8d793bee-c2cc-11de-8d13-0010c6dffd0f",
        "display": "OpenMRS Identification Number",
        "name": "OpenMRS Identification Number",
        "description": "Unique number used in OpenMRS",
        "format": "",
        "formatDescription": null,
        "required": false,
        "checkDigit": true,
        "validator": "org.openmrs.patient.impl.LuhnIdentifierValidator",
        "locationBehavior": null,
        "uniquenessBehavior": null,
        "retired": false,
        "auditInfo": {
            "creator": {
                "uuid": "ba62cf2e-2194-11e6-b260-28d2440db56c",
                "display": "admin",
                "links": [{
                    "rel": "self",
                    "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/user/ba62cf2e-2194-11e6-b260-28d2440db56c"
                }]
            },
            "dateCreated": "2005-09-22T00:00:00.000-0900",
            "changedBy": null,
            "dateChanged": null
        },
        "links": [{
            "rel": "self",
            "uri": "http://devtest04.openmrs.org:8080/openmrs/ws/rest/v1/patientidentifiertype/8d793bee-c2cc-11de-8d13-0010c6dffd0f"
        }],
        "resourceVersion": "1.8"
    }]
}

Note the "required": true property. I guess you will have to create an ID for all the required identifier types.

Thanks @pascal

I know the UUIDs of the identifiertypes. Where do I get the value for the “identifier” field? I have the location UUID as well.

@pascal, please take a look.

I’m nearly done…I need to know how is the “identifier” field generated…or is it just assigned by the user? I made a new patient with a random string as identifier via the api and it works:

But the web UI has identifiers generated in an orderly fashion…as seen in the photo. So how does this work?

Identifiers in reference application are generated using the idgen module. Unfortunately the module does not yet expose the auto generation feature via rest, see https://issues.openmrs.org/browse/IDGEN-42

However, there’s a workaround showcased by @darius at https://gist.github.com/djazayeri/d3dc89988486fe6f988d

var identifierToUse;
$.getJSON("http://demo.openmrs.org/openmrs/module/idgen/generateIdentifier.form?source=1", function(data) {
  identifierToUse = data.identifiers[0];
});

I’ve updated the docs with the above solution.

2 Likes

Can you verify this? I am trying, but have been getting a 500 error.

I’m sending a GET request at the above URL with the auth header like all requests. Am I missing something here?

It works through the browser. Please share the code of your client.

I’m testing this out on http://requestmaker.com/

YWRtaW46QWRtaW4xMjM= is the base64 encoded string of admin:Admin123

Via the browser, I get

HTTP Status 500 -
type Exception report
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.hibernate.exception.ConstraintViolationException: could not insert: [org.openmrs.module.idgen.LogEntry]

It should say Header: Authorization Value: Basic YWRtaW46QWRtaW4xMjM=

Anyway, it doesn’t work indeed. The issue is that this endpoint doesn’t care about the basic authentication. You can use this instead: http://demo.openmrs.org/openmrs/module/idgen/generateIdentifier.form?source=1&username=admin&password=Admin123

2 Likes

The basic authorization worked just like it is typed for person creation :slight_smile:

But hey, this solution works. Gracias!