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
Attachments (Visit Documents) are uploaded from the main page, you would have to click on either of those links:
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.
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
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
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
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:
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?