Exception when creating patient via REST API

I’m using reference application version 2.12.

I tried to create a patient via the rest API, combining the patient and person data as one submission, as suggested here by @dkayiwa:

However, I get an exception:

“No serializer found for class org.springframework.validation.DefaultMessageCodesResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)”

My POST was to http://localhost:8080/openmrs/ws/rest/v1/patient with body:

{
   "identifiers":[
      {
         "identifier":"6805316666080",
         "identifierType":"9436ae23-a698-4610-af03-9bc1b5b01ac7",
         "preferred":true
      }
   ],
   "person":{
      "gender":"M",
      "birthdate":"1968-05-31T00:00:00.000+0100",
      "birthdateEstimated":false,
      "dead":false,
      "names":[
         {
            "givenName":"John",
            "familyName":"Doe",
			"preferred":true
         }
      ]
   }
}

Can you share the full server side stack trace?

Full stack trace in follow-up reply, below.

Daniel, this seems to be the same exception that I get when searching for a patient. I previously created topic 37212 for that, but perhaps they can be merged.

I guess both the patient create and search end up serializing the patient object as JSON, which triggers this error?

However, if I simply GET the patient by UUID it does work, e.g.: GET http://localhost:8080/openmrs/ws/rest/v1/person/414a69dc-3c6b-4644-ad01-52696a8916d1

Your pastebin link is empty.

What url do you use for searching to get the errors? It would be great to have a pastebin link that has the full server side log.

As far as I know creating a patient in Bahmni (via API) requires first to have a person and on top of it create the patient. I think that is necessary and cannot be done in one submission.

I now create the person, which works, then a patient linked to the person, which yields the same exception.

This seems like the same error described in POSTING a patient via rest, which is the right patientIdentifierType?, i.e. it is related to the patient identifier.

I have now tried POSTing a patient as per the following, to no avail:

  1. With identifier type “OpenMRS ID” (uuid=“05a29f94-c0ed-11e2-94be-8c13b969e334”) and identifier=“3335” - which is a valid Luhn Mod-30 identifier with check-digit included. Yields same exception.
  2. With my own custom identifier type “Passport number” (no format string, no validator, not required). Yields same exception.
  3. With both the above, only no. 1 set as “preferred”. Yields same exception.

I have now discovered that the REST API returns one error, while the log contains a warning about another error:

REST API: 500 Internal Server Error

No serializer found for class org.springframework.validation.DefaultMessageCodesResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

REST error pastebin here.

Log file

WARN - ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(414) |2022-08-05T08:13:09,060| Failure in @ExceptionHandler
org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController#validationExceptionHandler(ValidationException, HttpServletRequest, HttpServletResponse) org.springframework.http.converter.HttpMessageNotWritableException:
No converter found for return value of type: class org.openmrs.module.webservices.rest.SimpleObject

Log warning pastebin here.

I tested these with the following POST. I have previously generated the valid OpenMRS ID “10001V” using IDGEN. The person exists already, now just trying to create the patient:

POST http://localhost:8080/openmrs/ws/rest/v1/patient

{
   "person": "da725170-9ad5-4623-9d3e-b1d0789f8a6a",
   "identifiers":[
      {
         "identifier":"10001V",
         "identifierType":"05a29f94-c0ed-11e2-94be-8c13b969e334",
         "preferred":true
      }
   ]
}

OK, I have fixed it myself, yay! :smiley:

In case someone else finds this useful in the future, here’s how to create a patient-person via the REST API. This refers to the reference application (2.12):

  1. The patient identifier type “OpenMRS ID” (uuid=“05a29f94-c0ed-11e2-94be-8c13b969e334”) is a required identifier type, i.e. when you create a patient, it should have at least this identifier specified.
  2. The reference application uses the IDGEN module, which means you have to pre-generate a valid OpenMRS id, then specify that id when creating the patient.
  3. A patient is a sub-class of person: the old docs specify that you first have to create the person, then the patient, but newer installations allow you to create the person and patient in one go.
  4. You must specify the location of each identifier. This got me initially, since the database table patient_identifier allows a null location_id, but the code bombs out if you don’t specify it.

Here is an example post that creates a new person and patient with two identifiers, the first one being the required OpenMRS ID, the second one a custom identifier type (“Passport number”) that I created manually. I’m using location uuid “6351fcf4-e311-4a19-90f9-35667d99a8af” for both, which in my installation is “Registration Desk”:

{
   "identifiers":[
      {
         "identifier":"10004M",
         "identifierType":"05a29f94-c0ed-11e2-94be-8c13b969e334",
         "location": "6351fcf4-e311-4a19-90f9-35667d99a8af",
         "preferred":true
      },
      {
         "identifier":"P1234",
         "identifierType":"48d8bf6c-5672-4e26-967e-a6ebea1f1a28",
         "location": "6351fcf4-e311-4a19-90f9-35667d99a8af"
      }
   ],
   "person":{
      "gender":"F",
      "birthdate":"1971-03-31T00:00:00.000+0100",
      "birthdateEstimated":false,
      "dead":false,
      "names":[
         {
            "givenName":"Anna",
            "familyName":"Bee",
			"preferred":true
         }
      ]
   }
}

The REST API could do with some better error handling, since any subtle error in the input data generates an opaque 500 Internal Server Error; it should return a 400 with a useful description of the validation failure. It seemed I got the same random 500 error for any of the following:

  • Location not specified in identifier
  • Not specifying a required identifier (OpenMRS ID)
  • Specifying an OpenMRS ID that wasn’t pre-generated.
3 Likes