500 Error Can't POST Patient into OpenMRS

I have spun up the demo version of OpenMRS in docker and am not able to POST a patient via the FHIR interface. I am getting the following error.

"‘Patient#null’ failed to validate with reason: Select a preferred identifier"

Is there something i need to setup in order to get OpenMRS to create a Patient and assign an OpenMRS ID?

Does the FHIR2 module require the resources to contain an external number of some sort?

I haven’t; been able to find much in the docs on the config required to Create New patients via the FHIR Interface

This isn’t a requirement of the FHIR module per se, but a requirement of OpenMRS. The FHIR module provides a FHIR interface, but POSTing a Patient resource isn’t really the correct way to create a patient in an EMR. A patient should be registered, which would be some kind of FHIR operation (which doesn’t currently exist, but is something we could look into adding).

The cheating way around this would be to generate a valid OpenMRS identifier (using the idgen module’s rest interface) add that identifier to your patient and POST that.

@ibacher Ok I created an ID with the idgen module, and have tried posting a simple Patient but am still getting a 500 error.

{
    "resourceType": "Patient",
    "id": "4c67ad95-5d46-4bd0-82c7-ce0f7d2622e7",
    "identifier": [
        {
            "extension": [
                {
                    "url": "http://fhir.openmrs.org/ext/patient/identifier#location",
                    "valueReference": {
                        "reference": "Location/58c57d25-8d39-41ab-8422-108a0c277d98",
                        "type": "Location",
                        "display": "Outpatient Clinic"
                    }
                }
            ],
            "use": "official",
            "type": {
                "text": "OpenMRS ID"
            },
            "value": "10002T"
        }
    ],
    "name": [
        {
            "given": [
                "Adam"
            ],
            "family": "John"
        }
    ],
    "gender": "male",
    "birthDate": "2004-08-12",
    "address": [
        {
            "state": "Mukono",
            "city": "Kampala",
            "country": "Uganda"
        }
    ]
}
{
    "resourceType": "OperationOutcome",
    "text": {
        "status": "generated",
        "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">ERROR</td><td>[]</td><td><pre>Failed to call access method: org.hibernate.exception.ConstraintViolationException: could not execute statement</pre></td>\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
    },
    "issue": [
        {
            "severity": "error",
            "code": "processing",
            "diagnostics": "Failed to call access method: org.hibernate.exception.ConstraintViolationException: could not execute statement"
        }
    ]
}

I dug into the logs and I am getting this error, but not sure which uuid is missing

ERROR - SqlExceptionHelper.logExceptions(142) |2022-01-12T15:27:27,728| Column 'uuid' cannot be null

@mrranger95 did u get any solution for fhir2 patient creation

@sanjay.d It is working now: You can test this out on dev server using a POST request on this end point: “https://dev3.openmrs.org/openmrs/ws/fhir2/R4/Patient/

Also make sure before sending the POST request you’ve set session location: https://dev3.openmrs.org/openmrs/ws/rest/v1/session

Reference here: https://openmrs.atlassian.net/wiki/spaces/docs/pages/228294725/Handling+Registration+Patient+Flow+in+OpenMRS+using+FHIR

Hi @parthfloyd ,

I have doubt regarding performer and category in fhir2 observation , I can see there is no column available in openmrs obs table, How i can store these two fields data into openmrs db obs table.

which repo has lastest code of core and rest module based on the fhir2 module? I see multiple field that we are sending through fhir2 endpoint but most of the openmrs table does not have column to store.

Thanks.

Have you heard chance to look at OpenMRS Observation - OpenMRS Core FHIR Implementation Guide v0.1.0? and the example OpenMRS Observation Example - JSON Representation - OpenMRS Core FHIR Implementation Guide v0.1.0?

2 Likes

Hi @mherman22 ,

I cant see any thing realted to perfomer and category , How I can store in openmrs DB? if I use fhir2 endpoint with this payload:

{ “resourceType”: “Observation”, “status”: “final”, “category”: [ { “coding”: [ { “system”: “Observation Category Codes - HL7 Terminology (THO) v6.3.0”, “code”: “vital-signs”, “display”: “Vital Signs” } ], “text”: “Vital Signs” } ], “code”: { “coding”: [ { “system”: “http://openmrs.org”, “code”: “e2cc0225-1433-4eb3-9c40-3a355ab93add”, “display”: “ASTHMA” } ], “text”: “ASTHMA” }, “subject”: { “reference”: “Patient/68bb538a-d15e-42fd-a543-f7d2149c045d” }, “encounter”: { “reference”: “Encounter/d57fe1da-7d9f-4e3f-9180-ac566d44f458” }, “effectiveDateTime”: “2025-03-12T10:30:00Z”, “issued”: “2025-03-12T10:45:00Z”, “performer”: [ { “reference”: “Practitioner/cb90b5f0-4b23-409f-bae7-b722205e1677” } ], “interpretation”: [ { “coding”: [ { “system”: “ObservationInterpretation - HL7 Terminology (THO) v6.3.0”, “code”: “L”, “display”: “LOW” } ] } ], “valueQuantity”: { “value”: 120, “unit”: “mmHg”, “system”: “http://unitsofmeasure.org”, “code”: “mm[Hg]” }, “note”: [ { “text”: “Patient had a slight fever before measurement.” } ] }

Thanks.

You can’t. Performer is not a field we support, as there’s nowhere to store that data in the OpenMRS data model, and category is not a writable field, as it’s derived from the concept associated with the observation.