use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO in project OpenClinica by OpenClinica.
the class DiscrepancyNoteUtil method generateDiscNoteSummaryRefactored.
/**
* Generate a summary of statistics for a collection of discrepancy notes.
*
* @param allDiscBeans
* A List of DiscrepancyNoteBeans.
* @return A Map mapping the name of each type of note (e.g., "Annotation")
* to another Map containing that type's statistics.
*/
public Map generateDiscNoteSummaryRefactored(DataSource ds, StudyBean currentStudy, Set<Integer> resolutionStatusIds, int discNoteType) {
DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(ds);
boolean filterDiscNotes = checkResolutionStatus(resolutionStatusIds);
boolean filterforDiscNoteType = discNoteType >= 1 && discNoteType <= 4;
//if (allDiscBeans == null || allDiscBeans.isEmpty())
// return new HashMap();
/*
* This container is a Map of Maps. e.g., Failed Validation Check -->
* Map [Total --> total number of Failed Validation Check type notes,
* Open --> total number of Failed Validation Check notes that are Open
* types, etc.]
*/
Map<String, Map> summaryMap = new HashMap<String, Map>();
// The internal Map, mapping the name of the status (e.g., Resolved) to
// the number of
// Notes that are Resolved for that particular discrepancy note type
// (e.g., Failed Validation Check).
Map<String, Integer> tempMap = null;
int tempType = 0;
int tempTotal = 0;
Set<String> p = new HashSet<String>();
if (filterforDiscNoteType) {
String[] discNoteTypeNames = { "Failed Validation Check", "Annotation", "Query", "Reason for Change" };
p.add(discNoteTypeNames[discNoteType - 1]);
} else {
p = TYPES.keySet();
}
String q = "";
if (filterDiscNotes) {
q += " AND ( ";
int i = 0;
for (Integer resolutionStatusId : resolutionStatusIds) {
if (i > 0) {
q += " OR ";
}
q += " dn.resolution_status_id = " + resolutionStatusId;
i++;
}
q += " ) ";
}
// initialize Map
for (String discNoteTypeName : p) {
tempMap = new HashMap<String, Integer>();
//String query = "";
// Create the summary or outer Map for each type name (e.g.,
// Incomplete)
summaryMap.put(discNoteTypeName, tempMap);
tempType = TYPES.get(discNoteTypeName);
//tempTotal = getNumberOfDiscNoteType(allDiscBeans, tempType);
tempTotal = discrepancyNoteDAO.getViewNotesCountWithFilter(q + " AND dn.discrepancy_note_type_id =" + tempType, currentStudy);
tempMap.put("Total", tempTotal);
if (tempTotal == 0)
continue;
for (String statusName : RESOLUTION_STATUS.keySet()) {
int number = discrepancyNoteDAO.getViewNotesCountWithFilter(q + " AND dn.discrepancy_note_type_id =" + tempType + " AND dn.resolution_status_id = " + RESOLUTION_STATUS.get(statusName), currentStudy);
tempMap.put(statusName, number);
}
}
return summaryMap;
}
use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO in project OpenClinica by OpenClinica.
the class DiscrepancyNoteUtil method injectDiscNotesIntoDisplayStudyEvents.
/**
* Add associated discrepancy notes to the appropriate StudyEventBean
* (contained by DisplayStudyBeans). A StudyEventBean has a List of
* DiscrepancyNoteBeans.
*
* @param displayStudyBeans
* A List of DisplayStudyEventBeans
* @param resolutionStatus
* An int representing the resolution status, if we are filtering
* the DiscrepancyNoteBeans based on their resolutionStatus id
* number.
* @param dataSource
* A DataSource used for the DAO methods.
* @param discNoteType
* An int representing the discrepancy note type, if we are
* filtering the DiscrepancyNoteBeans based on their
* discrepancyNoteTypeId number.
*/
public void injectDiscNotesIntoDisplayStudyEvents(List<DisplayStudyEventBean> displayStudyBeans, int resolutionStatus, DataSource dataSource, int discNoteType) {
if (displayStudyBeans == null) {
return;
}
// booleans representing whether this method should only get
// DiscrepancyNoteBeans with
// certain resolution status or discrepancyNoteTypeId number.
boolean hasResolutionStatus = resolutionStatus >= 1 && resolutionStatus <= 5;
boolean hasDiscNoteType = discNoteType >= 1 && discNoteType <= 4;
EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(dataSource);
StudyEventBean studyEventBean;
List<EventCRFBean> eventCRFBeans = new ArrayList<EventCRFBean>();
List<DiscrepancyNoteBean> foundDiscNotes = new ArrayList<DiscrepancyNoteBean>();
for (DisplayStudyEventBean dStudyEventBean : displayStudyBeans) {
studyEventBean = dStudyEventBean.getStudyEvent();
// All EventCRFs for a study event
eventCRFBeans = eventCRFDAO.findAllByStudyEvent(studyEventBean);
for (EventCRFBean eventCrfBean : eventCRFBeans) {
// Find ItemData type notes associated iwth an event crf
foundDiscNotes = discrepancyNoteDAO.findItemDataDNotesFromEventCRF(eventCrfBean);
// filter for any specified disc note type
if (!foundDiscNotes.isEmpty() && hasDiscNoteType) {
// only include disc notes that have the specified disc note
// type id
foundDiscNotes = filterforDiscNoteType(foundDiscNotes, discNoteType);
}
if (!foundDiscNotes.isEmpty()) {
if (!hasResolutionStatus) {
studyEventBean.getDiscBeanList().addAll(foundDiscNotes);
} else {
// the parameter passed to the servlet
for (DiscrepancyNoteBean discBean : foundDiscNotes) {
if (discBean.getResolutionStatusId() == resolutionStatus) {
studyEventBean.getDiscBeanList().add(discBean);
}
}
}
}
// Find EventCRF type notes
foundDiscNotes = discrepancyNoteDAO.findEventCRFDNotesFromEventCRF(eventCrfBean);
// filter for any specified disc note type
if (!foundDiscNotes.isEmpty() && hasDiscNoteType) {
foundDiscNotes = filterforDiscNoteType(foundDiscNotes, discNoteType);
}
if (!foundDiscNotes.isEmpty()) {
if (!hasResolutionStatus) {
studyEventBean.getDiscBeanList().addAll(foundDiscNotes);
} else {
// the parameter passed to the servlet
for (DiscrepancyNoteBean discBean : foundDiscNotes) {
if (discBean.getResolutionStatusId() == resolutionStatus) {
studyEventBean.getDiscBeanList().add(discBean);
}
}
}
}
// end if(! foundDiscNotes.isEmpty()){
}
// end for(EventCRFBean...
}
// end for (DisplayStudyEventBean
}
use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO in project OpenClinica by OpenClinica.
the class DeleteEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int studySubId = fp.getInt(STUDY_SUB_ID, true);
int eventCRFId = fp.getInt(EVENT_CRF_ID);
String action = request.getParameter("action");
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_delete"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
// construct info needed on view event crf page
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
int crfVersionId = eventCRF.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
eventCRF.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
eventCRF.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = eventCRF.getStudyEventId();
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
event.setStudyEventDefinition(sed);
request.setAttribute("event", event);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventCRF(eventCRF);
dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
// find all item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
ArrayList<ItemDataBean> itemData = iddao.findAllByEventCRFId(eventCRF.getId());
request.setAttribute("items", itemData);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("displayEventCRF", dec);
forwardPage(Page.DELETE_EVENT_CRF);
} else {
logger.info("submit to delete the event CRF from event");
// OC-6303 Deleting Event CRF resets Show / Hide logic
// delete records from DynamicItemForm and DynamicItemGroup
// getDynamicsItemFormMetadataDao().delete(eventCRFId);
// getDynamicsItemGroupMetadataDao().delete(eventCRFId);
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.RESET);
eventCRF.setUpdater(ub);
ecdao.update(eventCRF);
for (ItemDataBean itemdata : itemData) {
// OC-6343 Rule behaviour must be reset if an Event CRF is deleted
// delete the records from ruleActionRunLogDao
List<RuleActionRunLogBean> ruleActionRunLog = getRuleActionRunLogDao().findAllItemData(itemdata.getId());
if (ruleActionRunLog.size() != 0) {
getRuleActionRunLogDao().delete(itemdata.getId());
}
// OC-6344 Notes & Discrepancies must be set to "closed" when event CRF is deleted
// parentDiscrepancyNoteList is the list of the parent DNs records only
ArrayList<DiscrepancyNoteBean> parentDiscrepancyNoteList = getDnDao().findParentNotesOnlyByItemData(itemdata.getId());
for (DiscrepancyNoteBean parentDiscrepancyNote : parentDiscrepancyNoteList) {
if (parentDiscrepancyNote.getResolutionStatusId() != 4) {
// if the DN's resolution status is
// not set to Closed
String description = resword.getString("dn_auto-closed_description");
String detailedNotes = resword.getString("dn_auto_closed_detailed_notes");
// create new DN record , new DN Map record , also update the parent record
createDiscrepancyNoteBean(description, detailedNotes, itemdata.getId(), study, ub, parentDiscrepancyNote);
}
}
iddao = new ItemDataDAO(sm.getDataSource());
ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
ItemDataBean idBean = (ItemDataBean) iddao.findByPK(itemdata.getId());
ItemFormMetadataBean ifmBean = ifmdao.findByItemIdAndCRFVersionId(idBean.getItemId(), crfVersionId);
// Updating Dn_item_data_map actovated column into false for the existing DNs
ArrayList<DiscrepancyNoteBean> dnBeans = getDnDao().findExistingNotesForItemData(itemdata.getId());
if (dnBeans.size() != 0) {
DiscrepancyNoteBean dnBean = new DiscrepancyNoteBean();
dnBean.setEntityId(itemdata.getId());
dnBean.setActivated(false);
getDnDao().updateDnMapActivation(dnBean);
}
// Default Values are not addressed
itemdata.setValue("");
itemdata.setOldStatus(itemdata.getStatus());
itemdata.setOwner(ub);
itemdata.setStatus(Status.AVAILABLE);
itemdata.setUpdater(ub);
iddao.updateUser(itemdata);
iddao.update(itemdata);
}
// OC-6291 event_crf status change
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
ecdao.update(eventCRF);
if (event.getSubjectEventStatus().isCompleted() || event.getSubjectEventStatus().isSigned()) {
event.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
event.setUpdater(ub);
sedao = new StudyEventDAO(sm.getDataSource());
sedao.update(event);
}
String emailBody = respage.getString("the_event_CRF") + cb.getName() + respage.getString("has_been_deleted_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_deleted_from_the_event_cont");
addPageMessage(emailBody);
// sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO in project OpenClinica by OpenClinica.
the class UpdateSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
if (StringUtils.isBlank(fromResolvingNotes)) {
session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
checkStudyLocked(Page.LIST_SUBJECT_SERVLET, respage.getString("current_study_locked"));
checkStudyFrozen(Page.LIST_SUBJECT_SERVLET, respage.getString("current_study_frozen"));
}
int subjectId = fp.getInt("id", true);
int studySubId = fp.getInt("studySubId", true);
if (subjectId == 0) {
addPageMessage(respage.getString("please_choose_subject_to_edit"));
forwardPage(Page.LIST_SUBJECT_SERVLET);
} else {
String action = fp.getString("action", true);
if (StringUtils.isBlank("action")) {
addPageMessage(respage.getString("no_action_specified"));
forwardPage(Page.LIST_SUBJECT_SERVLET);
return;
}
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
if (action.equals("show") || action.equals("confirm")) {
request.setAttribute("studySubId", new Integer(studySubId));
request.setAttribute("id", new Integer(subjectId));
request.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
}
if ("show".equalsIgnoreCase(action)) {
//no DOB collected
request.setAttribute("localBirthDate", "");
if (!currentStudy.getStudyParameterConfig().getCollectDob().equals("3") && subject.getDateOfBirth() != null) {
setLocalDOB(subject);
}
discNotes = new FormDiscrepancyNotes();
request.setAttribute("genderDNFlag", "icon_noNote");
request.setAttribute("birthDNFlag", "icon_noNote");
request.setAttribute("subjectToUpdate", subject);
setDNFlag(subjectId);
forwardPage(Page.UPDATE_SUBJECT);
} else if ("confirm".equalsIgnoreCase(action)) {
confirm(subject, subjectId);
} else {
String gender = fp.getString("gender");
subject.setGender(gender.charAt(0));
if (currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("required") || currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("optional")) {
subject.setUniqueIdentifier(fp.getString("uniqueIdentifier"));
}
subject.setUpdater(ub);
if (!currentStudy.getStudyParameterConfig().getCollectDob().equals("3")) {
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
String d_date = fp.getString(DATE_DOB_TO_SAVE);
if (!(d_date == null || d_date.trim().length() == 0)) {
Date date_new = yformat.parse(fp.getString(DATE_DOB_TO_SAVE));
subject.setDateOfBirth(date_new);
}
}
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
Date date_new = local_df.parse(fp.getString(DATE_DOB_TO_SAVE));
subject.setDateOfBirth(date_new);
}
}
sdao.update(subject);
// save discrepancy notes into DB
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
AddNewSubjectServlet.saveFieldNotes("gender", fdn, dndao, subject.getId(), "subject", currentStudy);
AddNewSubjectServlet.saveFieldNotes(DATE_DOB, fdn, dndao, subject.getId(), "subject", currentStudy);
addPageMessage(respage.getString("subject_updated_succcesfully"));
if (studySubId > 0) {
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
forwardPage(Page.LIST_SUBJECT_SERVLET);
}
}
}
}
use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO in project OpenClinica by OpenClinica.
the class RuleExecutionBusinessObject method createDiscrepancyNote.
private void createDiscrepancyNote(String description, ItemDataBean targetItemDataBean, ItemDataBean sourceItemDataBean) {
DiscrepancyNoteBean note = new DiscrepancyNoteBean();
note.setDescription(description);
note.setDetailedNotes("");
note.setOwner(ub);
note.setCreatedDate(new Date());
note.setResolutionStatusId(1);
note.setDiscrepancyNoteTypeId(1);
// note.setParentDnId(parentId);
// note.setField(field);
note.setEntityId(targetItemDataBean.getId());
note.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
note.setColumn("value");
note.setStudyId(currentStudy.getId());
DiscrepancyNoteDAO discrepancyNoteDao = new DiscrepancyNoteDAO(sm.getDataSource());
note = (DiscrepancyNoteBean) discrepancyNoteDao.create(note);
discrepancyNoteDao.createMapping(note);
}
Aggregations