use of org.cdisc.ns.odm.v130_api.ODMcomplexTypeDefinitionFormData in project OpenClinica by OpenClinica.
the class OdmController method getODM.
private ODM getODM(String studyOID, String subjectKey) {
ODM odm = new ODM();
String ssoid = subjectKey;
if (ssoid == null) {
return null;
}
CRFVersionDAO versionDAO = new CRFVersionDAO(dataSource);
StudyDAO studyDAO = new StudyDAO(dataSource);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
ItemDataDAO itemDataDAO = new ItemDataDAO(dataSource);
CRFDAO crfDAO = new CRFDAO(dataSource);
List<ODMcomplexTypeDefinitionFormData> formDatas = new ArrayList<>();
try {
// Retrieve crfs for next event
StudySubjectBean studySubjectBean = studySubjectDAO.findByOid(ssoid);
ParticipantEventService participantEventService = new ParticipantEventService(dataSource);
StudyEventBean nextEvent = participantEventService.getNextParticipantEvent(studySubjectBean);
if (nextEvent != null) {
logger.debug("Found event: " + nextEvent.getName() + " - ID: " + nextEvent.getId());
List<EventCRFBean> eventCrfs = eventCRFDAO.findAllByStudyEvent(nextEvent);
StudyBean study = studyDAO.findByOid(studyOID);
if (!mayProceed(studyOID, studySubjectBean))
return odm;
List<EventDefinitionCRFBean> eventDefCrfs = participantEventService.getEventDefCrfsForStudyEvent(studySubjectBean, nextEvent);
for (EventDefinitionCRFBean eventDefCrf : eventDefCrfs) {
if (eventDefCrf.isParticipantForm()) {
EventCRFBean eventCRF = participantEventService.getExistingEventCRF(studySubjectBean, nextEvent, eventDefCrf);
boolean itemDataExists = false;
boolean validStatus = true;
CRFVersionBean crfVersion = null;
if (eventCRF != null) {
if (eventCRF.getStatus().getId() != 1 && eventCRF.getStatus().getId() != 2)
validStatus = false;
if (itemDataDAO.findAllByEventCRFId(eventCRF.getId()).size() > 0)
itemDataExists = true;
crfVersion = (CRFVersionBean) versionDAO.findByPK(eventCRF.getCRFVersionId());
} else
crfVersion = (CRFVersionBean) versionDAO.findByPK(eventDefCrf.getDefaultVersionId());
if (validStatus) {
String formUrl = null;
if (!itemDataExists)
formUrl = createEnketoUrl(studyOID, crfVersion, nextEvent, ssoid);
else
formUrl = createEditUrl(studyOID, crfVersion, nextEvent, ssoid);
formDatas.add(getFormDataPerCrf(crfVersion, nextEvent, eventCrfs, crfDAO, formUrl, itemDataExists));
}
}
}
return createOdm(study, studySubjectBean, nextEvent, formDatas);
} else {
logger.debug("Unable to find next event for subject.");
}
} catch (Exception e) {
logger.error(e.getMessage());
logger.error(ExceptionUtils.getStackTrace(e));
}
return odm;
}
use of org.cdisc.ns.odm.v130_api.ODMcomplexTypeDefinitionFormData in project OpenClinica by OpenClinica.
the class OdmController method generateFormData.
private ODMcomplexTypeDefinitionFormData generateFormData(CRFVersionBean crfVersionBean, StudyEventBean nextEvent, EventCRFBean eventCRFBean, CRFBean crfBean, String formUrl, boolean itemDataExists) {
ODMcomplexTypeDefinitionFormData formData = new ODMcomplexTypeDefinitionFormData();
formData.setFormOID(crfVersionBean.getOid());
formData.setFormName(crfBean.getName());
formData.setVersionDescription(crfVersionBean.getDescription());
formData.setUrl(formUrl);
if (eventCRFBean == null) {
formData.setStatus("Not Started");
} else {
EventCrf eventCrf = eventCrfDao.findById(eventCRFBean.getId());
if (!itemDataExists) {
formData.setStatus("Not Started");
} else {
formData.setStatus(eventCRFBean.getStatus().getName());
}
if (eventCrf.getDateUpdated() != null) {
// returns time as UTC
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
formData.setStatusChangeTimeStamp(sdf.format(eventCrf.getDateUpdated()));
}
}
return formData;
}
Aggregations