Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleComplex Obs Handler
package org.openmrs.module.shr.unstructureddata.obs.handler;

import java.io.IOException;
import org.openmrs.Obs;
import org.openmrs.api.APIException;
import org.openmrs.obs.ComplexObsHandler;
import org.openmrs.obs.handler.AbstractHandler;

public class UnstructuredDataHandler extends AbstractHandler implements ComplexObsHandler {
	
	@Override
	public Obs saveObs(Obs obs) throws APIException {
		
		String contentType = getContentType(obs.getComplexData().getTitle());  
		
		if (UnstructuredDAOUnstructuredDataHandlerUnstructuredDAOHandler.getUnstructuredDAO(contentType).saveObs(obs)){
			obs.setComplexData(null);
			obs.setValueComplex(obs.getComplexData().getTitle());
		}	 else {
			throw new UnstructuredDataStorageExceptionIOException();
		}
		
		return obs;
	}
	
	@Override
	public boolean purgeComplexData(Obs obs) {
	
		String contentType = getContentType(obs.getComplexData().getTitle());	 
	
		return UnstructuredDAOUnstructuredDataHandlerUnstructuredDAOHandler.getUnstructuredDAO(contentType).purgeObs(obs);
	}

	@Override
	public Obs getObs(Obs obs, String view) {
	
		String contentType = getContentType(obs.getComplexData().getTitle()); 
		
		return UnstructuredDAOUnstructuredDataHandlerUnstructuredDAOHandler.getUnstructuredDAO(contentType).getObs(obs);
	}
 
	String getContentType(String title){
		//do parsing here
		return null;

	}
}

...

Code Block
languagejava
titleUnstructured Data Service Interface
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);
}

 

Interfaces


Code Block
titleUnstructured DAO Interface
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);
}

...