This module will contain a Complex Observation Handler used to store unstructured data in the form of a complex observation to any storage systems suited for the purpose. The handler will be able to select a storage DAO according to the MIME type of the data that it's passed. So, for instance, a serialized object can be saved to a NoSQL database and large binary data can be saved to a distributed file/storage system.
It should be noted that there is no such thing in OpenMRS-core as a Complex Note as yet. We propose to get a ComplexData field included in the Note object and for the core to provide a ComplexNoteHandler interface. Any note with a non-null ComplexData property will be handled by a complexNoteHandler.
Design
Implementing the ComplexObsHandler (and ComplexNoteHandler in the future)
public class UnstructuredDataHandler extends AbstractHandler implements ComplexObsHandler { @Override public Obs saveObs(Obs obs) throws APIException { String contentType = getContentType(obs.getComplexData().getTitle()); if (UnstructuredDAOUnstructuredDataHandler.getUnstructuredDAO(contentType).saveObs(obs)){ obs.setComplexData(null); obs.setValueComplex(obs.getTitle()); } else { throw new UnstructuredDataStorageException(); } return obs; } @Override public boolean purgeComplexData(Obs obs) { String contentType = getContentType(obs.getComplexData().getTitle()); return UnstructuredDAOUnstructuredDataHandler.getUnstructuredDAO(contentType).purgeObs(obs); } @Override public Obs getObs(Obs obs, String view) { String contentType = getContentType(obs.getComplexData().getTitle()); return UnstructuredDAOUnstructuredDataHandler.getUnstructuredDAO(contentType).getObs(obs); } String getContentType(String title){ //do parsing here } }
Interfaces
public interface UnstructuredDataHandler { /** To be called by the ComplexObsHandler/ComplexNoteHandler */ UnstructuredDAO getUnstructuredDAO(String contentType); /** For each DAO a call to this method will be added in the ModuleActivator willStart() method */ void RegisterUnstructuredDAO (String contentType, UnstructuredDAO prototype) throws AlreadyRegisteredException; /** For each DAO a call to this method will be added in the ModuleActivator willStop() method */ void DeregisterUnstructuredDAO(String contentType); }
public interface UnstructuredDAO { Boolean saveObs(Obs obs); Boolean saveNote(Note note); Boolean purgeObs(Obs obs); Boolean purgeNote(Note note); Note getNote(Note note); Obs getObs(Obs obs); }
THIS PAGE IS A WORK IN PROGRESS