use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class DataEntryServlet method markCRFComplete.
/**
* The following methods are for 'mark CRF complete'
* @param request TODO
*
* @return
*/
protected boolean markCRFComplete(HttpServletRequest request) throws Exception {
locale = LocaleResolver.getLocale(request);
HttpSession session = request.getSession();
UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
// < respage =
// ResourceBundle.getBundle("org.akaza.openclinica.i18n.page_messages",
// locale);
// < restext =
// ResourceBundle.getBundle("org.akaza.openclinica.i18n.notes",locale);
// <
// resexception=ResourceBundle.getBundle(
// "org.akaza.openclinica.i18n.exceptions",locale);
getEventCRFBean(request);
getEventDefinitionCRFBean(request);
DataEntryStage stage = ecb.getStage();
// request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN,
// ecb);
// request.setAttribute(INPUT_EVENT_CRF_ID, new Integer(ecb.getId()));
LOGGER.trace("inout_event_crf_id:" + ecb.getId());
if (stage.equals(DataEntryStage.UNCOMPLETED) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.LOCKED)) {
addPageMessage(respage.getString("not_mark_CRF_complete1"), request);
return false;
}
if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
if (!edcb.isDoubleEntry()) {
addPageMessage(respage.getString("not_mark_CRF_complete2"), request);
return false;
}
}
if (isEachRequiredFieldFillout(request) == false) {
addPageMessage(respage.getString("not_mark_CRF_complete4"), request);
return false;
}
/*
* if (ecb.getInterviewerName().trim().equals("")) { throw new InconsistentStateException(errorPage, "You may not mark this Event CRF complete, because
* the interviewer name is blank."); }
*/
Status newStatus = ecb.getStatus();
boolean ide = true;
if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && edcb.isDoubleEntry()) {
newStatus = Status.PENDING;
ecb.setUpdaterId(ub.getId());
ecb.setUpdater(ub);
ecb.setUpdatedDate(new Date());
ecb.setDateCompleted(new Date());
} else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && !edcb.isDoubleEntry()) {
newStatus = Status.UNAVAILABLE;
ecb.setUpdaterId(ub.getId());
ecb.setUpdater(ub);
ecb.setUpdatedDate(new Date());
ecb.setDateCompleted(new Date());
ecb.setDateValidateCompleted(new Date());
} else if (stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) && edcb.isDoubleEntry()) {
newStatus = Status.UNAVAILABLE;
ecb.setUpdaterId(ub.getId());
ecb.setUpdater(ub);
ecb.setUpdatedDate(new Date());
ecb.setDateCompleted(new Date());
ecb.setDateValidateCompleted(new Date());
ide = false;
} else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
newStatus = Status.UNAVAILABLE;
ecb.setDateValidateCompleted(new Date());
ecb.setUpdaterId(ub.getId());
ecb.setUpdater(ub);
ide = false;
}
// create them
if (!isEachSectionReviewedOnce(request)) {
boolean canSave = saveItemsToMarkComplete(newStatus, request);
if (canSave == false) {
addPageMessage(respage.getString("not_mark_CRF_complete3"), request);
return false;
}
}
ecb.setStatus(newStatus);
/*
* Marking the data entry as signed if the corresponding EventDefinitionCRF is being enabled for electronic signature.
*/
if (edcb.isElectronicSignature()) {
ecb.setElectronicSignatureStatus(true);
}
ecb = (EventCRFBean) ecdao.update(ecb);
// note the below statement only updates the DATES, not the STATUS
ecdao.markComplete(ecb, ide);
// update all the items' status to complete
iddao.updateStatusByEventCRF(ecb, newStatus);
// change status for study event
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
seb.setUpdatedDate(new Date());
seb.setUpdater(ub);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
ArrayList allCRFs = ecdao.findAllByStudyEventAndStatus(seb, Status.UNAVAILABLE);
StudyBean study = (StudyBean) session.getAttribute("study");
ArrayList allEDCs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, seb.getStudyEventDefinitionId());
CRFVersionDAO crfversionDao = new CRFVersionDAO(getDataSource());
boolean eventCompleted = true;
boolean allRequired = true;
// JN Adding another flag
boolean allCrfsCompleted = false;
int allEDCsize = allEDCs.size();
ArrayList nonRequiredCrfIds = new ArrayList();
ArrayList requiredCrfIds = new ArrayList();
if (allCRFs.size() == allEDCs.size()) {
// was
// JN: all crfs are completed and then set the subject event status as complete
seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
}
seb = (StudyEventBean) sedao.update(seb);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
return true;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class ImportCRFDataService method fetchEventCRFStatuses.
/*
* purpose: Build a map of EventCRFs and the statuses they should have post-import. Assumes EventCRFs have been
* created for "Not Started" forms.
*/
public HashMap<Integer, String> fetchEventCRFStatuses(ODMContainer odmContainer) {
HashMap<Integer, String> eventCRFStatuses = new HashMap<Integer, String>();
EventCRFDAO eventCrfDAO = new EventCRFDAO(ds);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
StudyDAO studyDAO = new StudyDAO(ds);
StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
String studyOID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
StudyBean studyBean = studyDAO.findByOid(studyOID);
ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
for (SubjectDataBean subjectDataBean : subjectDataBeans) {
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
String sampleOrdinal = studyEventDataBean.getStudyEventRepeatKey() == null ? "1" : studyEventDataBean.getStudyEventRepeatKey();
StudyEventDefinitionBean studyEventDefinitionBean = studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), studyBean.getParentStudyId());
logger.info("find all by def and subject " + studyEventDefinitionBean.getName() + " study subject " + studySubjectBean.getName());
StudyEventBean studyEventBean = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), studyEventDefinitionBean.getId(), Integer.parseInt(sampleOrdinal));
for (FormDataBean formDataBean : formDataBeans) {
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
for (CRFVersionBean crfVersionBean : crfVersionBeans) {
ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersionBean);
for (EventCRFBean ecb : eventCrfBeans) {
Integer ecbId = new Integer(ecb.getId());
if (!eventCRFStatuses.keySet().contains(ecbId) && formDataBean.getEventCRFStatus() != null) {
eventCRFStatuses.put(ecb.getId(), formDataBean.getEventCRFStatus());
}
}
}
}
}
}
return eventCRFStatuses;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class OpenRosaServices method getManifest.
/**
* @api {get} /rest2/openrosa/:studyOID/manifest Get Form Manifest
* @apiName getManifest
* @apiPermission admin
* @apiVersion 3.8.0
* @apiParam {String} studyOID Study Oid.
* @apiGroup Form
* @apiDescription Gets additional information on a particular Form, including links to associated media.
*/
@GET
@Path("/{studyOID}/manifest")
@Produces(MediaType.TEXT_XML)
public String getManifest(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formId") String crfOID, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
if (!mayProceedPreview(studyOID))
return null;
CRFVersionDAO cVersionDao = new CRFVersionDAO(getDataSource());
CrfVersionMediaDao mediaDao = (CrfVersionMediaDao) SpringServletAccess.getApplicationContext(context).getBean("crfVersionMediaDao");
CRFVersionBean crfVersion = cVersionDao.findByOid(crfOID);
List<MediaFile> mediaFiles = new ArrayList<MediaFile>();
Manifest manifest = new Manifest();
List<CrfVersionMedia> mediaList = mediaDao.findByCrfVersionId(crfVersion.getId());
if (mediaList != null && mediaList.size() > 0) {
for (CrfVersionMedia media : mediaList) {
String urlBase = getCoreResources().getDataInfo().getProperty("sysURL").split("/MainMenu")[0];
MediaFile mediaFile = new MediaFile();
mediaFile.setFilename(media.getName());
File image = new File(media.getPath() + media.getName());
mediaFile.setHash(DigestUtils.md5Hex(media.getName()) + Double.toString(image.length()));
mediaFile.setDownloadUrl(urlBase + "/rest2/openrosa/" + studyOID + "/downloadMedia?crfVersionMediaId=" + media.getCrfVersionMediaId());
manifest.add(mediaFile);
}
}
try {
// Create the XML manifest using a Castor mapping file.
XMLContext xmlContext = new XMLContext();
Mapping mapping = xmlContext.createMapping();
mapping.loadMapping(getCoreResources().getURL("openRosaManifestMapping.xml"));
xmlContext.addMapping(mapping);
Marshaller marshaller = xmlContext.createMarshaller();
StringWriter writer = new StringWriter();
marshaller.setWriter(writer);
marshaller.marshal(manifest);
// Set response headers
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
Date currentDate = new Date();
cal.setTime(currentDate);
SimpleDateFormat format = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss zz");
format.setCalendar(cal);
response.setHeader("Content-Type", "text/xml; charset=UTF-8");
response.setHeader("Date", format.format(currentDate));
response.setHeader("X-OpenRosa-Version", "1.0");
return writer.toString();
} catch (Exception e) {
LOGGER.error(e.getMessage());
LOGGER.error(ExceptionUtils.getStackTrace(e));
return "<Error>" + e.getMessage() + "</Error>";
}
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class OpenRosaServices method getFormXml.
/**
* @api {get} /rest2/openrosa/:studyOID/formXml Get Form XML
* @apiName getFormXml
* @apiPermission admin
* @apiVersion 3.8.0
* @apiParam {String} studyOID Study Oid.
* @apiGroup Form
* @apiDescription Downloads the contents of a form
*/
@GET
@Path("/{studyOID}/formXml")
@Produces(MediaType.APPLICATION_XML)
public String getFormXml(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formID") String crfOID, @RequestHeader("Authorization") String authorization) throws Exception {
if (!mayProceedPreview(studyOID))
return null;
String xform = null;
// get parameters
String formId = request.getParameter("formId");
if (formId == null) {
return "<error>formID is null :(</error>";
}
try {
CRFVersionDAO versionDAO = new CRFVersionDAO(dataSource);
CRFVersionBean crfVersion = versionDAO.findByOid(formId);
if (crfVersion.getXform() != null && !crfVersion.getXform().equals("")) {
xform = updateRepeatGroupsWithOrdinal(crfVersion.getXform());
} else {
OpenRosaXmlGenerator generator = new OpenRosaXmlGenerator(coreResources, dataSource, ruleActionPropertyDao);
xform = generator.buildForm(formId);
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(ExceptionUtils.getStackTrace(e));
LOGGER.error(e.getMessage());
LOGGER.error(ExceptionUtils.getStackTrace(e));
return "<error>" + e.getMessage() + "</error>";
}
response.setHeader("Content-Type", "text/xml; charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=\"" + crfOID + ".xml" + "\";");
response.setContentType("text/xml; charset=utf-8");
return xform;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class UpdateStudyEventServlet method getUncompletedCRFs.
private ArrayList getUncompletedCRFs(ArrayList eventDefinitionCRFs, ArrayList eventCRFs) {
int i;
HashMap completed = new HashMap();
HashMap startedButIncompleted = new HashMap();
ArrayList answer = new ArrayList();
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edcrf = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
completed.put(new Integer(edcrf.getCrfId()), Boolean.FALSE);
startedButIncompleted.put(new Integer(edcrf.getCrfId()), new EventCRFBean());
}
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecrf = (EventCRFBean) eventCRFs.get(i);
int crfId = cvdao.getCRFIdFromCRFVersionId(ecrf.getCRFVersionId());
ArrayList idata = iddao.findAllByEventCRFId(ecrf.getId());
if (!idata.isEmpty()) {
// this crf has data already
completed.put(new Integer(crfId), Boolean.TRUE);
} else {
// event crf got created, but no data entered
startedButIncompleted.put(new Integer(crfId), ecrf);
}
}
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
DisplayEventDefinitionCRFBean dedc = new DisplayEventDefinitionCRFBean();
EventDefinitionCRFBean edcrf = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
dedc.setEdc(edcrf);
Boolean b = (Boolean) completed.get(new Integer(edcrf.getCrfId()));
EventCRFBean ev = (EventCRFBean) startedButIncompleted.get(new Integer(edcrf.getCrfId()));
if (b == null || !b.booleanValue()) {
dedc.setEventCRF(ev);
answer.add(dedc);
}
}
return answer;
}
Aggregations