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:
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.:
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:
- 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.
- With my own custom identifier type “Passport number” (no format string, no validator, not required). Yields same exception.
- 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.
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:
OK, I have fixed it myself, yay!
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):
- 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.
- 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.
- 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.
- 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”:
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.