use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class RuleRunner method prepareEmailContents.
HashMap<String, String> prepareEmailContents(RuleSetBean ruleSet, RuleSetRuleBean ruleSetRule, StudyBean currentStudy, RuleActionBean ruleAction) {
// get the Study Event
StudyEventBean studyEvent = (StudyEventBean) getStudyEventDao().findByPK(Integer.valueOf(getExpressionService().getStudyEventDefenitionOrdninalCurated(ruleSet.getTarget().getValue())));
// get the Study Subject
StudySubjectBean studySubject = (StudySubjectBean) getStudySubjectDao().findByPK(studyEvent.getStudySubjectId());
// get Study/Site Associated with Subject
StudyBean theStudy = (StudyBean) getStudyDao().findByPK(studySubject.getStudyId());
String theStudyName, theSiteName = "";
if (theStudy.getParentStudyId() > 0) {
StudyBean theParentStudy = (StudyBean) getStudyDao().findByPK(theStudy.getParentStudyId());
theStudyName = theParentStudy.getName() + " / " + theParentStudy.getIdentifier();
theSiteName = theStudy.getName() + " / " + theStudy.getIdentifier();
} else {
theStudyName = theStudy.getName() + " / " + theStudy.getIdentifier();
}
// get the eventCrf & subsequently the CRF Version
//EventCRFBean eventCrf = (EventCRFBean) getEventCrfDao().findAllByStudyEvent(studyEvent).get(0);
EventCRFBean eventCrf = (EventCRFBean) getEventCrfDao().findAllByStudyEventAndCrfOrCrfVersionOid(studyEvent, getExpressionService().getCrfOid(ruleSet.getTarget().getValue())).get(0);
CRFVersionBean crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(eventCrf.getCRFVersionId());
CRFBean crf = (CRFBean) getCrfDao().findByPK(crfVersion.getCrfId());
String studyEventDefinitionName = getExpressionService().getStudyEventDefinitionFromExpression(ruleSet.getTarget().getValue(), currentStudy).getName();
studyEventDefinitionName += " [" + studyEvent.getSampleOrdinal() + "]";
String itemGroupName = getExpressionService().getItemGroupNameAndOrdinal(ruleSet.getTarget().getValue());
ItemGroupBean itemGroupBean = getExpressionService().getItemGroupExpression(ruleSet.getTarget().getValue());
ItemBean itemBean = getExpressionService().getItemExpression(ruleSet.getTarget().getValue(), itemGroupBean);
String itemName = itemBean.getName();
SectionBean section = (SectionBean) getSectionDAO().findByPK(getItemFormMetadataDAO().findByItemIdAndCRFVersionId(itemBean.getId(), crfVersion.getId()).getSectionId());
StringBuffer sb = new StringBuffer();
ResourceBundle respage = ResourceBundleProvider.getPageMessagesBundle();
sb.append(respage.getString("email_header_1"));
sb.append(" " + contextPath + " ");
sb.append(respage.getString("email_header_2"));
sb.append(" '" + currentStudy.getName() + "' ");
sb.append(respage.getString("email_header_3"));
sb.append(" \n\n ");
sb.append(respage.getString("email_body_1") + " " + theStudyName + " \n ");
sb.append(respage.getString("email_body_1_a") + " " + theSiteName + " \n ");
sb.append(respage.getString("email_body_2") + " " + studySubject.getName() + " \n ");
sb.append(respage.getString("email_body_3") + " " + studyEventDefinitionName + " \n ");
sb.append(respage.getString("email_body_4") + " " + crf.getName() + " " + crfVersion.getName() + " \n ");
sb.append(respage.getString("email_body_5") + " " + section.getTitle() + " \n ");
sb.append(respage.getString("email_body_6") + " " + itemGroupName + " \n ");
sb.append(respage.getString("email_body_7") + " " + itemName + " \n ");
sb.append(respage.getString("email_body_8") + " " + ruleAction.getCuratedMessage() + " \n ");
sb.append(" \n\n ");
sb.append(respage.getString("email_body_9"));
sb.append(" " + contextPath + " ");
sb.append(respage.getString("email_body_10"));
sb.append(" \n");
requestURLMinusServletPath = requestURLMinusServletPath == null ? "" : requestURLMinusServletPath;
sb.append(requestURLMinusServletPath + "/ViewSectionDataEntry?ecId=" + eventCrf.getId() + "§ionId=" + section.getId() + "&tabId=" + section.getOrdinal());
// &eventId="+ studyEvent.getId());
sb.append("\n\n");
sb.append(respage.getString("email_footer"));
String subject = contextPath + " - [" + currentStudy.getName() + "] ";
String ruleSummary = ruleAction.getSummary() != null ? ruleAction.getSummary() : "";
String message = ruleSummary.length() < 20 ? ruleSummary : ruleSummary.substring(0, 20) + " ... ";
subject += message;
HashMap<String, String> emailContents = new HashMap<String, String>();
emailContents.put("body", sb.toString());
emailContents.put("subject", subject);
return emailContents;
}
use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class RuleSetBulkRuleRunner method populateForRuleSetBasedView.
private List<RuleSetBasedViewContainer> populateForRuleSetBasedView(List<RuleSetBasedViewContainer> theList, RuleSetBean ruleSet, RuleBean rule, String akey, RuleActionBean ruleAction) {
StudyEventBean studyEvent = (StudyEventBean) getStudyEventDao().findByPK(Integer.valueOf(getExpressionService().getStudyEventDefenitionOrdninalCurated(ruleSet.getTarget().getValue())));
// for (String akey : actionsToBeExecuted.keySet()) {
// for (RuleActionBean ruleAction : actionsToBeExecuted.get(akey)) {
RuleSetBasedViewContainer container = new RuleSetBasedViewContainer(rule.getName(), rule.getOid(), rule.getExpression().getValue(), akey, ruleAction.getActionType().toString(), ruleAction.getSummary());
if (!theList.contains(container)) {
theList.add(container);
}
StudySubjectBean studySubject = (StudySubjectBean) getStudySubjectDao().findByPK(studyEvent.getStudySubjectId());
theList.get(theList.indexOf(container)).addSubject(studySubject.getLabel());
// }
return theList;
}
use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class DiscrepancyNoteUtil method filterDiscNotesBySubject.
/**
* Filter a List of DiscrepancyNoteBeans by subject id.
*
* @param allDiscNotes
* A List of DiscrepancyNoteBeans prior to filtering.
* @param subjectId
* An int subject id.
* @param dataSource
* A DataSource object used by DAO methods.
* @return The filtered List of DiscrepancyNoteBeans.
*/
public List<DiscrepancyNoteBean> filterDiscNotesBySubject(List<DiscrepancyNoteBean> allDiscNotes, int subjectId, DataSource dataSource) {
// Do not filter this List if the subjectId < 1
if (!(subjectId >= 1)) {
return allDiscNotes;
}
StudySubjectDAO studySubjDAO = new StudySubjectDAO(dataSource);
StudySubjectBean studySubjBean = new StudySubjectBean();
studySubjBean = (StudySubjectBean) studySubjDAO.findByPK(subjectId);
List<DiscrepancyNoteBean> newDiscNotes = new ArrayList<DiscrepancyNoteBean>();
for (DiscrepancyNoteBean dnBean : allDiscNotes) {
if (dnBean.getSubjectName().equalsIgnoreCase(studySubjBean.getLabel())) {
newDiscNotes.add(dnBean);
}
}
return newDiscNotes;
}
use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class RandomizeService method getStudySubjectAttrValue.
private String getStudySubjectAttrValue(String expr, EventCRFBean eventCrfBean, RuleSetBean ruleSet) {
String value = "";
StudySubjectDAO<String, ArrayList> ssdao = new StudySubjectDAO<>(ds);
SubjectDAO subdao = new SubjectDAO(ds);
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(ds);
StudyGroupDAO sgdao = new StudyGroupDAO(ds);
StudyDAO<String, ArrayList> sdao = new StudyDAO<>(ds);
StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
SubjectBean subjectBean = (SubjectBean) subdao.findByPK(ssBean.getSubjectId());
String prefix = "STUDYGROUPCLASSLIST";
String param = expr.split("\\.", -1)[1].trim();
if (param.equalsIgnoreCase("BIRTHDATE")) {
value = subjectBean.getDateOfBirth().toString();
} else if (param.equalsIgnoreCase("SEX")) {
if (String.valueOf(subjectBean.getGender()).equals("m"))
value = "Male";
else
value = "Female";
// value =String.valueOf(ssBean.getGender());
} else if (param.startsWith(prefix)) {
String gcName = param.substring(21, param.indexOf("\"]"));
StudyGroupBean sgBean = sgdao.findSubjectStudyGroup(ssBean.getId(), gcName);
if (sgBean != null)
value = sgBean.getName();
}
return value;
}
use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class OdmFileCreation method createODMFile.
public HashMap<String, Integer> createODMFile(String odmVersion, long sysTimeBegin, String generalFileDir, DatasetBean datasetBean, StudyBean currentStudy, String generalFileDirCopy, ExtractBean eb, Integer currentStudyId, Integer parentStudyId, String studySubjectNumber, boolean zipped, boolean saveToDB, boolean deleteOld, String odmType, UserAccountBean userBean) {
Integer ssNumber = getStudySubjectNumber(studySubjectNumber);
MetaDataCollector mdc = new MetaDataCollector(dataSource, datasetBean, currentStudy, ruleSetRuleDao);
AdminDataCollector adc = new AdminDataCollector(dataSource, datasetBean, currentStudy);
ClinicalDataCollector cdc = new ClinicalDataCollector(dataSource, datasetBean, currentStudy);
MetaDataCollector.setTextLength(200);
if (deleteOld) {
File file = new File(generalFileDir);
if (file.isDirectory()) {
files = file.listFiles();
oldFiles = Arrays.asList(files);
}
}
if (odmVersion != null) {
// by default odmVersion is 1.2
if ("1.3".equals(odmVersion)) {
ODMBean odmb = new ODMBean();
odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 ODM1-3-0.xsd");
ArrayList<String> xmlnsList = new ArrayList<String>();
xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.3\"");
odmb.setXmlnsList(xmlnsList);
odmb.setODMVersion("1.3");
mdc.setODMBean(odmb);
adc.setOdmbean(odmb);
cdc.setODMBean(odmb);
} else if ("oc1.2".equals(odmVersion)) {
ODMBean odmb = new ODMBean();
// odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.2 OpenClinica-ODM1-2-1.xsd");
odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.2 OpenClinica-ODM1-2-1-OC1.xsd");
ArrayList<String> xmlnsList = new ArrayList<String>();
xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.2\"");
// xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/openclinica_odm/v1.2\"");
xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/odm_ext_v121/v3.1\"");
xmlnsList.add("xmlns:OpenClinicaRules=\"http://www.openclinica.org/ns/rules/v3.1\"");
odmb.setXmlnsList(xmlnsList);
odmb.setODMVersion("oc1.2");
mdc.setODMBean(odmb);
adc.setOdmbean(odmb);
cdc.setODMBean(odmb);
} else if ("oc1.3".equals(odmVersion)) {
ODMBean odmb = mdc.getODMBean();
// odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0.xsd");
// odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0-OC1.xsd");
odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0-OC3-0.xsd");
ArrayList<String> xmlnsList = new ArrayList<String>();
xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.3\"");
// xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/openclinica_odm/v1.3\"");
xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/odm_ext_v130/v3.1\"");
xmlnsList.add("xmlns:OpenClinicaRules=\"http://www.openclinica.org/ns/rules/v3.1\"");
odmb.setXmlnsList(xmlnsList);
odmb.setODMVersion("oc1.3");
odmb.setOdmType(odmType);
mdc.setODMBean(odmb);
adc.setOdmbean(odmb);
cdc.setODMBean(odmb);
}
}
//////////////////////////////////////////
////////// MetaData Extraction //////////
mdc.collectFileData();
MetaDataReportBean metaReport = new MetaDataReportBean(mdc.getOdmStudyMap(), coreResources);
metaReport.setODMVersion(odmVersion);
metaReport.setOdmBean(mdc.getODMBean());
metaReport.createChunkedOdmXml(Boolean.TRUE);
long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
String ODMXMLFileName = mdc.getODMBean().getFileOID() + ".xml";
int fId = createFileK(ODMXMLFileName, generalFileDir, metaReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
if (!"".equals(generalFileDirCopy)) {
int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, metaReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
}
//////////////////////////////////////////
////////// AdminData Extraction //////////
adc.collectFileData();
AdminDataReportBean adminReport = new AdminDataReportBean(adc.getOdmAdminDataMap());
adminReport.setODMVersion(odmVersion);
adminReport.setOdmBean(mdc.getODMBean());
adminReport.createChunkedOdmXml(Boolean.TRUE);
sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
fId = createFileK(ODMXMLFileName, generalFileDir, adminReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
if (!"".equals(generalFileDirCopy)) {
int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, adminReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
}
//////////////////////////////////////////
////////// ClinicalData Extraction ///////
DatasetDAO dsdao = new DatasetDAO(dataSource);
String sql = eb.getDataset().getSQLStatement();
String st_sed_in = dsdao.parseSQLDataset(sql, true, true);
String st_itemid_in = dsdao.parseSQLDataset(sql, false, true);
int datasetItemStatusId = eb.getDataset().getDatasetItemStatus().getId();
String ecStatusConstraint = dsdao.getECStatusConstraint(datasetItemStatusId);
String itStatusConstraint = dsdao.getItemDataStatusConstraint(datasetItemStatusId);
Iterator<OdmStudyBase> it = cdc.getStudyBaseMap().values().iterator();
while (it.hasNext()) {
JobTerminationMonitor.check();
OdmStudyBase u = it.next();
ArrayList newRows = dsdao.selectStudySubjects(u.getStudy().getId(), 0, st_sed_in, st_itemid_in, dsdao.genDatabaseDateConstraint(eb), ecStatusConstraint, itStatusConstraint);
///////////////
int fromIndex = 0;
boolean firstIteration = true;
while (fromIndex < newRows.size()) {
JobTerminationMonitor.check();
int toIndex = fromIndex + ssNumber < newRows.size() ? fromIndex + ssNumber : newRows.size() - 1;
List x = newRows.subList(fromIndex, toIndex + 1);
fromIndex = toIndex + 1;
String studySubjectIds = "";
for (int i = 0; i < x.size(); i++) {
StudySubjectBean sub = new StudySubjectBean();
sub = (StudySubjectBean) x.get(i);
studySubjectIds += "," + sub.getId();
}
// for
studySubjectIds = studySubjectIds.replaceFirst(",", "");
ClinicalDataUnit cdata = new ClinicalDataUnit(dataSource, datasetBean, cdc.getOdmbean(), u.getStudy(), cdc.getCategory(), studySubjectIds);
cdata.setCategory(cdc.getCategory());
cdata.collectOdmClinicalData();
FullReportBean report = new FullReportBean();
report.setClinicalData(cdata.getOdmClinicalData());
report.setOdmStudyMap(mdc.getOdmStudyMap());
report.setODMVersion(odmVersion);
// report.setOdmStudy(mdc.getOdmStudy());
report.setOdmBean(mdc.getODMBean());
if (firstIteration && fromIndex >= newRows.size()) {
report.createChunkedOdmXml(Boolean.TRUE, true, true);
firstIteration = false;
} else if (firstIteration) {
report.createChunkedOdmXml(Boolean.TRUE, true, false);
firstIteration = false;
} else if (fromIndex >= newRows.size()) {
report.createChunkedOdmXml(Boolean.TRUE, false, true);
} else {
report.createChunkedOdmXml(Boolean.TRUE, false, false);
}
fId = createFileK(ODMXMLFileName, generalFileDir, report.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
if (!"".equals(generalFileDirCopy)) {
int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, report.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
}
}
}
sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
fId = createFileK(ODMXMLFileName, generalFileDir, "</ODM>", datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, saveToDB, zipped, deleteOld, userBean);
if (!"".equals(generalFileDirCopy)) {
int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, "</ODM>", datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
}
//////////////////////////////////////////
////////// pre pagination extraction /////
/*
* mdc.collectFileData();
* adc.collectOdmAdminDataMap();
* cdc.collectOdmClinicalDataMap();
* FullReportBean report = new FullReportBean();
* report.setClinicalDataMap(cdc.getOdmClinicalDataMap());
* report.setAdminDataMap(adc.getOdmAdminDataMap());
* report.setOdmStudyMap(mdc.getOdmStudyMap());
* report.setOdmBean(mdc.getODMBean());
* report.setODMVersion(odmVersion);
* report.createOdmXml(Boolean.TRUE);
* long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
* String ODMXMLFileName = mdc.getODMBean().getFileOID() + ".xml";
* int fId = this.createFile(ODMXMLFileName, generalFileDir, report.getXmlOutput().toString(), datasetBean,
* sysTimeEnd, ExportFormatBean.XMLFILE, true);
* if (!"".equals(generalFileDirCopy)) {
* int fId2 = this.createFile(ODMXMLFileName, generalFileDirCopy, report.getXmlOutput().toString(), datasetBean,
* sysTimeEnd, ExportFormatBean.XMLFILE, false);
* }
*/
HashMap answerMap = new HashMap<String, Integer>();
// JN: Zipped in the next stage as thats where the ODM file is named and copied over in default categories.
// if(zipped)
// { try {
// zipFile(ODMXMLFileName,generalFileDir);
//
// } catch (IOException e) {
// // TODO Auto-generated catch block
// logger.error(e.getMessage());
// e.printStackTrace();
// }
//
// } // return ODMXMLFileName;
answerMap.put(ODMXMLFileName, new Integer(fId));
return answerMap;
}
Aggregations