NumberFormat Exception rendering chart search view w/UUID

The chart search module extension point includes;

"url": "${project.parent.artifactId}/chartsearch.page?patientId={{patient.patientId}}",

where {{patient.patientId}} translates to the real patient id, like patientId=3838, however when am customizing the patient search widget to provide a chartsearch url as reported at: Defining unique URL for afterSelectedUrl property of patientsearch widget the patientId translates to uuid, which @darius said is meant to be so, so i wanted to support both of these at the same time, however the second results into a NumberFormatException which i have not yet been able to trace where it happens within the module’s code.

When i searched around, i met with https://issues.openmrs.org/browse/UIFR-145 where a similar issue was handled for StringToEncounterConverter, So i upgraded to UIFR 3.3.1 as suggested at https://github.com/openmrs/openmrs-module-htmlformentryui/pull/5 but this doesn’t fix the issue, any extra thing i need to know to solve this issue?

Put a breakpoint in the exact place where the exception is thrown and follow the way back. However in the stacktrace you should see all the methods and classes involved, isn’t that right?

1 Like

However, in this case there’s no reference in the log to where the error is thrown as being part of the chartsearch module.

Then maybe someone is swallowing the exception (or at least its cause). Sonar should detect these cases.

@k_joseph,

Looking at the stack trace I see:

org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.convert(StringToNumberConverterFactory.java:59)
...
at org.openmrs.ui.framework.UiFrameworkUtil.determineArgumentValue(UiFrameworkUtil.java:236) 

From this I guess that you have code in your controller like

controller(@RequestParam("patientId") Integer patientId, ...)

and naturally this fails with a NumberFormatException if a UUID is passed in.

Take a look at the first argument to this controller. This supports either patient_id or uuid, because it just lets the UI Framework (and Spring’s underlying conversion service) automatically take care of things.

(Particularly, StringToPatientConverter in the uiframework module already knows how to fetch a patient based on either a patient_id or a uuid.)

1 Like

Thanks @darius, that was the issue and your comment help me fix the issue :smile:

something i noticed however is that patient becomes null at the controller level when i use jq(’#chart-search-form-submit’).serialize() as URL which returns/transforms into something like:

url: "/openmrs-standalone/chartsearch/searchSavingSection/getResultsFromTheServer.action?successUrl=%2Fopenmrs-standalone%2Fchartsearch%2Fchartsearch.page%3FreturnUrl%3D%2Fopenmrs-standalone%2Fcoreapps%2Fclinicianfacing%2Fpatient.page%3FpatientId%3Ddd8fb35c-1691-11df-97a5-7038c432aabf%26%26patientId%3D5859%26"

from Ajax.

Error:

    SEVERE: Servlet.service() for servlet openmrs threw exception
java.lang.NullPointerException
	at org.openmrs.module.chartsearch.page.controller.ChartsearchPageController.searchAndReturnResults(ChartsearchPageController.java:78)
	at org.openmrs.module.chartsearch.fragment.controller.TopAreaFragmentController.getResultsFromTheServer(TopAreaFragmentController.java:41)

Investigation shows that patient fails to be passed from the view.