Visit Documents Module does not display images saved as complex obs from another module

Thanks. Found it.

Great. I will make out time to look at them :slight_smile:

I’m having a small problem. The module documentation says

Additionally it encompasses files uploaded elsewhere within OpenMRS as long as they are saved as complex obs.

But this does not seem to be so. I uploaded a file during patient registration which is been saved as a complex obs. See code below

final InputStream in = file.getInputStream();
final ComplexData complexData = new ComplexData(file.getOriginalFilename(), in);
final Concept concept = RegistrationUtils.getComplexConceptForPatientFiles();
final Obs obs = new Obs(encounter.getPatient(), concept, encounter.getEncounterDatetime(), encounter.getLocation());
obs.setComplexData(complexData);
obs.setEncounter(encounter);
Context.getObsService().saveObs(obs, "");

I see this file when I search for this observation on the Manage observations page but on the patient dashboard from the referenceapplication, it shows no visit documents

Is there something I’m missing?

Also, I don’t see an option to upload files from the dashboard.

You will need to specify the UUID of the concept complex that you want on the radar through this GP: visitdocumentsui.conceptComplexUuidList

Let me know how it goes, we have only ever used the default ones so far.

I’ve done that. Now it’s detecting the file but it cannot read the file. See

And I get this exception from the console SEVERE: Servlet.service() for servlet [openmrs] in context with path [/openmrs] - Pastebin.com

Also about this. I still don’t see an option to upload a document from the Visit Documents patient dashboard section

Attachments (Visit Documents) are uploaded from the main page, you would have to click on either of those links:

image


The NPE comes from here (assuming you’re on VDUI 1.3). So basically complexObs is null.

What’s the content of the valueComplex member for that specific obs?
Also which complex obs handler was used to save it?

We would need to debug this guy to find out why the complex version of the obs can’t be fetched. Would you be in a position to do that?

I could imagine that things go wrong if the valueComplex member is formatted in a completely unexpected way. Attachments does use a specific format, when this format isn’t recognised then it falls back on the Core handler defined as a parent.

Oh, I should have mentioned that I did click on that link and still didn’t see an option to upload a file

Yes I’m on 1.3, downloaded from addons.openmrs.org

Below is the code that creates the specific obs

final InputStream in = file.getInputStream();
final ComplexData complexData = new ComplexData(file.getOriginalFilename(), in);
final Concept concept = RegistrationUtils.getComplexConceptForPatientFiles();
final Obs obs = new Obs(encounter.getPatient(), concept, encounter.getEncounterDatetime(), encounter.getLocation());
obs.setComplexData(complexData);
obs.setEncounter(encounter);
Context.getObsService().saveObs(obs, "");

Is there something missing there? FYI, viewing the obs from the Manage observations from the administration page shows my complex value is set to the image uploaded and it displays fine

ImageHandler

Ah sorry, by default the upload widget is disabled outside of a visit. See this GP to toggle this off.

From the top of my head I’m not sure why the complex obs is not properly fetched, could you debug the method I pointed you to in my last reply?

1 Like

Ok I will look into that. But will be leaving the office soon (in about 45 minutes) and still have to make uploading of multiple files during patient registration work. I will debug the visit ui module tomorrow first thing in the morning. Thanks :slight_smile:

Should I create a ticket for it too?

Yes it seems that you have uncovered a bug. Let’s see what you find out upon debugging, but yes it looks like it.

“Backward compatibility” (so to say) with any complex obs was always desired, and the module was designed in that way. But as you can see, it was never really tested :wink:

As an fyi, not sure what version of OpenMRS you are running, but we recently found an issue with running against 2.1.x that I haven’t had time to look into yet:

Take care, Mark

Obs obs = context.getObsService().getObsByUuid(obsUuid);
Obs complexObs = context.getObsService().getComplexObs(obs.getObsId(), view);
ComplexData complexData = complexObs.getComplexData();

The obs returned in the first line contains the observation that was created by my code during the file upload. I got that from their IDs. But it’s complexData property is null even though value complex is set to the name of the uploaded file prepended with png image |

In the second line ObsService.getComplexObs returns null. I’m still not sure why. I’ve tried stepping into the implementation of the method and see what’s happening. InteliJ shows me 3 implementations openmrs-api-1.10.5.jar, openmrs-api-1.11.4.jar, openmrs-api-2.0.0. I’m not sure which of them is been used but I placed a break point in all 3 and it’s never hit when the method ObsService.getComplexObs is called. Also seems the method does not have much documentation so I’m unable to see what’s happening inside and why it’s returning null.

I evaluated a few expressions

obs.getConcept.isComplex // returns true

Context.getConceptService().getConceptComplex(obs.getConcept().getConceptId())
		        .getHandler(); // returns the string "ImageHandler"

 Context.getObsService().getHandler("ImageHandler"); // returns an object that is not null, see image below

Until I am able to step into the implementation of ObsService().getComplexObs used in the code, I may not be able to know why it’s returning null.

@mksd can you explain to me what the second parameter in ObsService.getComplexObs is supposed to do?

Also another think I could not figure out is how the call to that controller method originates. What code makes the call. Visiting the patient dashboard automatically makes a call to AttachmentsController.downloadDocument with some parameters passed. Where are those parameters from and who(which code) is making that call?

And if you set our module for debugging, can you just put a breakpoint here and see what happens? Already understanding what happens in this method will help a lot.

Re: debugging the Core, well it’s always better to remote-debug in your IDE starting from the same version of the Core than the one you’re using at runtime. Which one is it?

Ok. Let me do that.

2.0.5

Thanks. Let me look into this.

I was not aware of it until now :slight_smile:

2 posts were merged into an existing topic: Uploading multiple files from page controllers