Reports saved a complex obs don't show up on obs section on patient dashboard

Was able to save report as complex obs using this

@Override
@Transactional
public synchronized RadiologyReport saveRadiologyReport(RadiologyReport radiologyReport, String content) {
    
    final Obs obs = new Obs();
    final ConceptComplex concept = radiologyProperties.getConceptForReport();
    obs.setConcept(concept);
    obs.setPerson(radiologyReport.getRadiologyOrder()
            .getPatient());
    obs.setObsDatetime(new Date());
    File tmpFile = null;
    InputStream complexDataInputStream = null;
    try {
        tmpFile = File.createTempFile("report", ".html");
        FileUtils.writeStringToFile(tmpFile, content);
        complexDataInputStream = new FileInputStream(tmpFile);
    }
    catch (IOException e) {
        throw new APIException(e.getMessage(), e);
    }
    final ComplexData complexData = new ComplexData(tmpFile.getName(), complexDataInputStream);
    obs.setComplexData(complexData);
    radiologyReport.setObs(obs);
    Context.getObsService()
            .saveObs(obs, "");
    return saveRadiologyReport(radiologyReport);
}

But when I visit thepatient dashboard under the obs section I don’t see any obs created but in the database there is an obs associated with the patient.

Screenshot of saved report

Screenshot of patient dashboard

But when I visit the database, there is an obs associated with the patient and the complex value has the name of the report file

cc @teleivo

That’s how complex Obs are saved, the ‘reference’ (file name) is saved in the DB and the actual contents are saved somewhere else which is left to the discretion of the handler. FYI, you shouldn’t be manually creating the complex Obs file, the ComplexObsHandler already does that for you and knows how to look it up unless you have a strong reason for doing so.

So I can just add a string as complex obs data and it will create a file?

Just create an instance of ComplexData which is where you set the title (filename) and the actual data, then set that on your Obs instance and call saveObs

The complex data constructor is like this ComplexData(String title, Object data)

Does that mean I can just call the constructor with ComplexData(reportTitle, reportContent) where reportContent is a string like "<h2>Hello World</h2> and it’ll work? I wanted to use an input stream because that’s what I saw from the obs controller.