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

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?