NPE in patient registration

I am trying to setup openmrs in advanced mode. I have set the spa.remote.enabled global setting to true and able see the openmrs 3.x front end components and able to login. When I try to create a new patient record I am getting the following exception.

The modules being used:

  1. spa-1.0.8.omod
  2. webservices.rest-2.32.0.omod
  3. fhir2-1.2.2.omod
  4. referenceapplication-2.12.0-SNAPSHOT.omod

The Browser logs:

openmrs-esm-form-entry-app.js:1 Uncaught Stacktrace for outgoing request: Error: Server responded with 500 () for url /openmrs/ws/rest/v1/patient/. Check err.responseBody or network tab in dev tools for more info

Server logs:

18-Jul-2022 22:16:24.197 SEVERE [http-nio-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [openmrs] in context with path [/openmrs] threw exception [Request processing failed; nested exception is org.openmrs.module.webservices.rest.web.response.ConversionException: attributes on class org.openmrs.Person] with root cause java.lang.NullPointerException at org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PersonAttributeResource1_8.setAttributeType(PersonAttributeResource1_8.java:222) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setProperty(BaseDelegatingResource.java:787) at org.openmrs.module.webservices.rest.web.ConversionUtil.convertMap(ConversionUtil.java:322) at org.openmrs.module.webservices.rest.web.ConversionUtil.convert(ConversionUtil.java:272) at org.openmrs.module.webservices.rest.web.ConversionUtil.convert(ConversionUtil.java:213) at org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setProperty(BaseDelegatingResource.java:786) at org.openmrs.module.webservices.rest.web.ConversionUtil.convertMap(ConversionUtil.java:322) at org.openmrs.module.webservices.rest.web.ConversionUtil.convert(ConversionUtil.java:272) at org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8.getPatient(PatientResource1_8.java:237) at org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8.create(PatientResource1_8.java:222) at org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController.create(MainResourceController.java:91) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.openmrs.module.web.filter.ForcePasswordChangeFilter.doFilter(ForcePasswordChangeFilter.java:60) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:368) at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:174) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:73) at org.openmrs.web.filter.GZIPFilter.doFilterInternal(GZIPFilter.java:65) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:71) at org.openmrs.module.webservices.rest.web.filter.AuthorizationFilter.doFilter(AuthorizationFilter.java:105) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:71) at org.openmrs.module.webservices.rest.web.filter.ContentTypeFilter.doFilter(ContentTypeFilter.java:64) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:71) at org.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:106) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:71) at org.openmrs.module.owa.filter.OwaFilter.doFilter(OwaFilter.java:93) at org.openmrs.module.owa.filter.OwaFilter.doFilter(OwaFilter.java:61) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:71) at org.openmrs.module.spa.filter.SpaFilter.doFilter(SpaFilter.java:53) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:71) at org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:57) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:105) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.orm.hibernate5.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:156) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:108) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:108) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:108) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:367) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:639) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:882) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1647) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

Are you able to reproduce that here? https://dev3.openmrs.org/

@dkayiwa I see a different exception on https://dev3.openmrs.org/

openmrs-esm-form-entry-app.js:1 POST https://dev3.openmrs.org/openmrs/ws/rest/v1/patient/ 400 (Bad Request)

In my case I was getting 500 internal server error.

Along with the previous exception I see the cors errors in browser logs.

Access to fetch at ‘https://spa-modules.nyc3.cdn.digitaloceanspaces.com/@openmrs/esm-home-app/2022-06-29_0284a104d3346f82a8393a8141ba5be0d08d68e3/574.openmrs-esm-home-app.js’ from origin ‘https://dev3.openmrs.org’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

On your local machine, do you have these person attribute types? OpenMRS - Login

I do have the following attributes.

Are they the same as on dev3?

In my local setup we see the following diff

  1. We do not have the email field
  2. Instead of “unknown patient” we have “test patient”

Can you ensure that you have exactly the same as on dev3?

even after making my local setup to have same set of attributes as dev3 I still see the same exception

19-Jul-2022 22:06:04.401 SEVERE [http-nio-8080-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [openmrs] in context with path [/openmrs] threw exception [Request processing failed; nested exception is org.openmrs.module.webservices.rest.web.response.ConversionException: attributes on class org.openmrs.Person] with root cause java.lang.NullPointerException at org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PersonAttributeResource1_8.setAttributeType(PersonAttributeResource1_8.java:222) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setProperty(BaseDelegatingResource.java:787) at org.openmrs.module.webservices.rest.web.ConversionUtil.convertMap(ConversionUtil.java:322) at org.openmrs.module.webservices.rest.web.ConversionUtil.convert(ConversionUtil.java:272) at org.openmrs.module.webservices.rest.web.ConversionUtil.convert(ConversionUtil.java:213) at org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setProperty(BaseDelegatingResource.java:786) at org.openmrs.module.webservices.rest.web.ConversionUtil.convertMap(ConversionUtil.java:322) at org.openmrs.module.webservices.rest.web.ConversionUtil.convert(ConversionUtil.java:272) at org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8.getPatient(PatientResource1_8.java:237) at org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8.create(PatientResource1_8.java:222) at org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController.create(MainResourceController.java:91)

here is the request being submitted to the server {“uuid”:“c446cc4a-b8c9-4ddd-883a-8052c143bc7c”,“person”:{“uuid”:“c446cc4a-b8c9-4ddd-883a-8052c143bc7c”,“names”:[{“preferred”:true,“givenName”:“test”,“middleName”:“test”,“familyName”:“test”}],“gender”:“F”,“birthdate”:“1990-1-1”,“birthdateEstimated”:false,“attributes”:[{“attributeType”:“14d4f066-15f5-102d-96e4-000c29c2a5d7”,“value”:“5108153143”},{“attributeType":“ac7d7773-fe9f-11ec-8b9b-0242ac1b0002”,“value”:"test@test.com”}],“addresses”:[{“postalCode”:“75063”,“address2”:“MacArthur Blvd”,“address1”:“8605”,“country”:“usa”,“stateProvince”:“”,“cityVillage”:“irving”}],“dead”:false},“identifiers”:[{“identifier”:“1001A7”,“identifierType”:“05a29f94-c0ed-11e2-94be-8c13b969e334”,“preferred”:true}]}

Does your database have person attribute types with the uuids in your submission?

We did not change any database schema, this is the default schema we have.

patient table schema:

image

person table schema:

image

This is what i mean:

Do you have a person attribute type with this uuid? 14d4f066-15f5-102d-96e4-000c29c2a5d7

Do you also have another person attribute type with this uuid? ac7d7773-fe9f-11ec-8b9b-0242ac1b0002

@dkayiwa The email uuid is not matching to the one available on database. I have a query, how the ui able to pick a wrong uuid?

Change the one in your database to match the one in the query.

Thank you for the direction @dkayiwa. That works. It looks the integrity between the 3.x ui and the database scripts is not maintained. Please let me know, If I can do something to fix it.

I see a similar follow up exception on the appointments

It is again pointing to unavailable patientUuid. the database records are having a different uuids.

for the request

{patientUuid: “0e2d4a9f-0d4d-47a9-af4a-c9d59bd04a70”, startDate: “2022-01-20T18:39:36.597Z”}

Am I missing something in my setup process? Can you please help?

The exception:

org.openmrs.module.webservices.rest.web.response.UnknownResourceException: Unknown resource: v1/appointments org.openmrs.module.webservices.rest.web.api.impl.RestServiceImpl.getResourceByName(RestServiceImpl.java:416) sun.reflect.GeneratedMethodAccessor717.invoke(Unknown Source)

I think 3.x is going to be shipping metadata that includes the expected person attributes with the required uuids.