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;
}
}
|