Wiki Spaces
Documentation
Projects
Resources
Get Help from Others
Q&A: Ask OpenMRS
Discussion: OpenMRS Talk
Real-Time: IRC Chat | Slack
This page describes the changes to OpenMRS to support Complex Observations. See ticket:656 and ticket:107.*
Complex Obs Support gives OpenMRS the ability to store observations (Obs) on a patient with complex values such as an x-ray image, a document, or a media file. These complex data are large and so are stored on the file system outside of the OpenMRS database. In order to do this, a few things are necessary:
Save a complex obs and data:ConceptComplex conceptComplex = Context.getConceptService().getConceptComplex(1867); // this is assumed to have happened // conceptComplex.setHandler("ImageHandler"); // Set the required properties. Obs obs = new Obs(new Person(48609), conceptComplex, new Date(), new Location()); BufferedImage img = ImageIO.read(new File("/home/bmckown/Desktop/test/logo.png")); // or: // InputStream img = new FileInputStream(new File("folder", "filename")); ComplexData complexData = new ComplexData("test-image.jpg", img); obs.setComplexData(complexData); Context.getObsService().saveObs(obs, null); // obs.getComplexData() will be null here Retrieve a complex obs and its dataInteger obsId = obs.getObsId(); Obs complexObs = Context.getObsService().getComplexObs(obsId, OpenmrsConstants.RAW_VIEW); ComplexData complexData = complexObs.getComplexData(); Object object = complexData.getData(); // object will be a BufferedImage object
Obs complexObs = Context.getObsService().getComplexObs(videoObsId, OpenmrsConstants.RAW_VIEW); ComplexData complexData = complexObs.getComplexData(); byte[] videoObjectData = ((byte[]) complexData.getData()); // cast Object --to--> byte array object
Provides hyperlink to ComplexObsServlet instead of the heavyweight data.
public class WebImageHandler extends ImageHandler { public Obs getComplexData(Obs obs, String view) { if (Webutils.HYPERLINK_VIEW.equals(view)) { String link = "/ComplexObsServlet?obsId=" + obs.getObsId(); obs.set(new ComplexData("some title", link); return obs; } return super.getComplexObs(obs, view); } }
Or alternatively, for a module register in ModuleApplicationContext.xml
<bean parent="obsServiceTarget" > <property name="handlers"> <map> <entry> <key><value>ImageHandler</value></key> <bean class="org.openmrs.web.controller.observation.handler.WebImageHandler"/> </entry> </map> </property> </bean>