Getting Diagnoses Summary Using Rest API

How can I get this list using rest API. I am using bellow url for vitals.

http://localhost:8081/openmrs-standalone/ws/rest/v1/encounter?patient=4f069ddc-1274-4dd4-8aa3-190b66a2434a&v=full&encounterType=“Vital UUID”

For diagnosis summery what encounterType should I use and How do I extract Diagnoses summery.

Unfortunately we don’t have a REST resource for this in the OpenMRS reference application.

(The Bahmni distro has added one here, and perhaps someone could port this into the emrapi module.)

What you’d have to do to get this from the standard reference application is to get from the concept resource for the given patient and the “Visit Diagnoses” concept (uuid=159947AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA), and parse these obs groups.

PS- If someone creates a ticket for adding a “diagnosis” REST resource via the emrapi module we should definitely mark this as a community priority.

Hi Darius, I have created an issue here. I would do that myself but not enough confident yet.:blush:

@jaks80 attempting to do it is what will develop your confidence! :smile:

2 Likes

@darius I have just forked emrapi module in my github and cloned it. In org.openmrs.module.emrapi.diagnosis.DiagnosisService I can see List getDiagnoses(Patient patient, Date fromDate) method to get diagnosis. I am little bit confused where exactly I will add rest web service.

@jaks80 can you start by hitting the “Claim Issue” button on the ticket? You could add the REST controller at https://github.com/openmrs/openmrs-module-emrapi/tree/master/omod/src/main/java/org/openmrs/module/emrapi/web/controller For an example, take a look at BahmniDiagnosisController and those in the above folder. Hopefully you saw this: https://wiki.openmrs.org/display/docs/Pull+Request+Tips

This is the usual url I was using for playing around rest apis.

http://localhost:8084/openmrs/ws/rest/v1/session/

What is the URL for emapi’s. I tried http://localhost:8084/openmrs/ws/rest/emrapi/conditionhistory?patientUuid=6afdb2e5-28ea-11e7-bf5c-28d244b594c0 http://localhost:8084/openmrs/ws/rest/emrapi/diagnosis?patientUuid=6afdb2e5-28ea-11e7-bf5c-28d244b594c0

What happened when you tried out those urls?

When I tried emrapi url give gave me unknown resource error message. I will send you exact error message when I go to my desk.

/ws/rest/v1/* is working perfectly.

Only /ws/rest//emrapi/* is giving error message:

{ “error”: { “message”: “Resource does not exist. Please check documentation for implemented resources and their paths [null]”, “code”: “org.openmrs.module.webservices.rest.web.v1_0.controller.UnknownResourceController:35”, “detail”: “org.openmrs.module.webservices.rest.web.response.UnknownResourceException\r\n\tat org.openmrs.module.webservices.rest.web.v1_0.controller.UnknownResourceController.handleUnknownResource(UnknownResourceController.java:35)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:497)\r\n\tat org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)\r\n\tat org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)\r\n\tat org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)\r\n\tat org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:622)\r\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:729)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:72)\r\n\tat org.openmrs.web.filter.GZIPFilter.doFilterInternal(GZIPFilter.java:64)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\r\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70)\r\n\tat org.openmrs.module.webservices.rest.web.filter.AuthorizationFilter.doFilter(AuthorizationFilter.java:104)\r\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70)\r\n\tat org.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:82)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\r\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70)\r\n\tat org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:54)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:108)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)\r\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)\r\n\tat org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)\r\n\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)\r\n\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\r\n\tat java.lang.Thread.run(Thread.java:745)\r\n” } }

What do you intend to use the “/ws/rest//emrapi/*” url for?

To get Diagnoses of a patient. Please check starting of this thread.

The emrapi module provides much more than just diagnosis. Are you sure you want to use the url “”/ws/rest//emrapi/*" for diagnosis? Did you get a chance to look at a few other urls in this or restwebservices module to get the pattern? You could take a look at this: https://demo.openmrs.org/openmrs/module/webservices/rest/apiDocs.htm

@jaks80

(1) First off, try doing

GET https://demo.openmrs.org/openmrs/ws/rest/v1/obs?patient=1b9d0dc0-3212-4ad9-b840-13ba80e5c2c1&concept=159947AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 

This will actually return you:

{
  "results": [
    {
      "uuid": "572b6c6b-bfab-4bb2-9157-f99f83546754",
      "display": "Visit Diagnoses: Presumed diagnosis, G0P0000, Primary",
      "links": [
        {
          "rel": "self",
          "uri": "http:\/\/127.0.0.1:8080\/openmrs\/ws\/rest\/v1\/obs\/572b6c6b-bfab-4bb2-9157-f99f83546754"
        }
      ]
    }
  ]
}

If you add &v=default or &v=full to the response, it will be more verbose. Perhaps this will give you some of what you’re looking for.

(2) If you’re looking to add a REST resource that gives you the diagnoses for the patient, then the simplest way is to add a new Controller, that handles a request like “/emrapi/patientdiagnoses” that you annotate with @ResponseBody and you have it return a List<Diagnosis>. (I’m not sure this will actually work, and you might have to simplify the Diagnosis object to something that can be automatically converted to JSON.

@dkayiwa I have added a rest resource in emrapi module exactly the way Darius have described in point (2). My question is how do I test this url.

If I use url like this: http://localhost:8084/openmrs/ws/rest/emrapi/patientdiagnoses?patientUuid=6afdb2e5-28ea-11e7-bf5c-28d244b594c0

If gives me unknown resource error: “message”: “Resource does not exist. Please check documentation for implemented resources and their paths [null]”,

All other apis, apart from emrapi has this urls pattern: http://localhost:8084/openmrs/ws/rest/v1/* which is working perfectly fine.

Only emrapi rest resource seems to have different url pattern. So What will be the url for emrapi rest resources.

(Its midnight here, I will catch you up tomorrow again)

@jaks80 if you do a Spring MVC controller (e.g. annotated with @Controller) then you don’t use the /ws/rest/ prefix.

If you want to do things “right” from the perspective of the OpenMRS REST API then instead of @Controller you should do something like:

@Resource
public class ... implements Searchable { ... }

I am trying to get the diagnosis of a patient using this url https://demo.openmrs.org/openmrs/ws/rest/emrapi/patientuniquediagnoses&patient=c72bdb90-ae11-4ed4-85ac-92c8af1a3452 but in the reply I got this response. “message”: “Resource does not exist. Please check documentation for implemented resources and their paths [null]” @dkayiwa @jaks80

@naveed1228 does this work for you? https://qa-refapp.openmrs.org/openmrs/ws/rest/emrapi/patientdiagnoses?patient=fedaa0cb-974c-4258-ba6c-379653c66ab5

At your provided link it work fine.I looked at the module version and install this one 1.24.1 because the emr api module you are using 1.24.2-SNAPSHOT is not available at the openmrs module repository.By doing so I am getting this error.One thing more it also does not work on openmrs.demo.org thanks

The Following Error I got in response: [Could not write JSON: Direct self-reference leading to cycle (through reference chain: java.util.ArrayList[0]->org.openmrs.module.emrapi.diagnosis.Diagnosis["diagnosis"]->org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer["codedAnswer"]->org.openmrs.Concept_$$jvstcc9_49["retiredBy"]->org.openmrs.User$$jvstcc9_50["creator"]); nested exception is org.codehaus.jackson.map.JsonMappingException: Direct self-reference leading to cycle (through reference chain: java.util.ArrayList[0]->org.openmrs.module.emrapi.diagnosis.Diagnosis["diagnosis"]->org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer["codedAnswer"]->org.openmrs.Concept$$jvstcc9_49["retiredBy"]->org.openmrs.User$$_jvstcc9_50["creator"])]",

   "code": "org.springframework.http.converter.json.MappingJacksonHttpMessageConverter:204",

dkayiwa: while trying out your provided link using postman got the same error as I got in my case.Added the error on pastebin https://paste.ee/p/x31OC