use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class ListEventsForSubjectTableFactory method setDataAndLimitVariables.
@SuppressWarnings("unchecked")
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
Limit limit = tableFacade.getLimit();
ListEventsForSubjectFilter eventsForSubjectFilter = getListEventsForSubjectFilter(limit);
if (!limit.isComplete()) {
int totalRows = getStudySubjectDAO().getCountWithFilter(eventsForSubjectFilter, getStudyBean());
tableFacade.setTotalRows(totalRows);
}
ListEventsForSubjectSort eventsForSubjectSort = getListEventsForSubjectSort(limit);
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<StudySubjectBean> items = getStudySubjectDAO().getWithFilterAndSort(getStudyBean(), eventsForSubjectFilter, eventsForSubjectSort, rowStart, rowEnd);
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
for (StudySubjectBean studySubjectBean : items) {
HashMap<Object, Object> theItem = new HashMap<Object, Object>();
theItem.put("studySubject", studySubjectBean);
theItem.put("studySubject.label", studySubjectBean.getLabel());
theItem.put("studySubject.status", studySubjectBean.getStatus());
theItem.put("enrolledAt", ((StudyBean) getStudyDAO().findByPK(studySubjectBean.getStudyId())).getIdentifier());
SubjectBean subjectBean = (SubjectBean) getSubjectDAO().findByPK(studySubjectBean.getSubjectId());
theItem.put("subject", subjectBean);
theItem.put("subject.charGender", subjectBean.getGender());
// study group classes
SubjectGroupMapBean subjectGroupMapBean = new SubjectGroupMapBean();
for (StudyGroupClassBean studyGroupClass : getStudyGroupClasses()) {
subjectGroupMapBean = getSubjectGroupMapDAO().findAllByStudySubjectAndStudyGroupClass(studySubjectBean.getId(), studyGroupClass.getId());
if (null != subjectGroupMapBean) {
theItem.put("sgc_" + studyGroupClass.getId(), subjectGroupMapBean.getStudyGroupId());
theItem.put("grpName_sgc_" + studyGroupClass.getId(), subjectGroupMapBean.getStudyGroupName());
}
}
subjectGroupMapBean = null;
// Get EventCrfs for study Subject
List<EventCRFBean> eventCrfs = getEventCRFDAO().findAllByStudySubject(studySubjectBean.getId());
HashMap<String, EventCRFBean> crfAsKeyEventCrfAsValue = new HashMap<String, EventCRFBean>();
for (EventCRFBean eventCRFBean : eventCrfs) {
CRFBean crf = getCrfDAO().findByVersionId(eventCRFBean.getCRFVersionId());
crfAsKeyEventCrfAsValue.put(crf.getId() + "_" + eventCRFBean.getStudyEventId(), eventCRFBean);
}
// Get the event Status
List<StudyEventBean> eventsForStudySubjectAndEventDefinitions = getStudyEventDAO().findAllByDefinitionAndSubject(selectedStudyEventDefinition, studySubjectBean);
List<DisplayBean> events = new ArrayList<DisplayBean>();
// study event size < 1
if (eventsForStudySubjectAndEventDefinitions.size() < 1) {
DisplayBean d = new DisplayBean();
d.getProps().put("event", null);
d.getProps().put("event.status", SubjectEventStatus.NOT_SCHEDULED);
d.getProps().put("studySubject.createdDate", null);
for (int i = 0; i < getCrfs(selectedStudyEventDefinition).size(); i++) {
CRFBean crf = getCrfs(selectedStudyEventDefinition).get(i);
d.getProps().put("crf_" + crf.getId(), DataEntryStage.UNCOMPLETED);
d.getProps().put("crf_" + crf.getId() + "_eventCrf", null);
d.getProps().put("crf_" + crf.getId() + "_crf", crf);
// d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", eventDefinitionCrfs.get(i));
d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", getEventDefinitionCRFBean(selectedStudyEventDefinition.getId(), crf, studySubjectBean));
theItem.put("crf_" + crf.getId(), "");
}
events.add(d);
}
// study event size >0
for (StudyEventBean studyEventBean : eventsForStudySubjectAndEventDefinitions) {
DisplayBean d = new DisplayBean();
d.getProps().put("event", studyEventBean);
d.getProps().put("event.status", studyEventBean.getSubjectEventStatus());
d.getProps().put("studySubject.createdDate", studyEventBean.getDateStarted());
for (int i = 0; i < getCrfs(selectedStudyEventDefinition).size(); i++) {
CRFBean crf = getCrfs(selectedStudyEventDefinition).get(i);
EventCRFBean eventCRFBean = crfAsKeyEventCrfAsValue.get(crf.getId() + "_" + studyEventBean.getId());
if (eventCRFBean != null) {
d.getProps().put("crf_" + crf.getId(), eventCRFBean.getStage());
d.getProps().put("crf_" + crf.getId() + "_eventCrf", eventCRFBean);
} else {
d.getProps().put("crf_" + crf.getId(), DataEntryStage.UNCOMPLETED);
d.getProps().put("crf_" + crf.getId() + "_eventCrf", null);
}
d.getProps().put("crf_" + crf.getId() + "_crf", crf);
// d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", eventDefinitionCrfs.get(i));
d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", getEventDefinitionCRFBean(selectedStudyEventDefinition.getId(), crf, studySubjectBean));
theItem.put("crf_" + crf.getId(), "");
}
events.add(d);
}
theItem.put("events", events);
theItem.put("event.status", "");
theItem.put("studySubject.createdDate", "");
theItem.put("webappContext", tableFacade.getWebContext().getContextPath());
theItems.add(theItem);
}
// Do not forget to set the items back on the tableFacade.
tableFacade.setItems(theItems);
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class StudyAuditLogTableFactory method setDataAndLimitVariables.
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
// initialize i18n
resword = ResourceBundleProvider.getWordsBundle(getLocale());
resformat = ResourceBundleProvider.getFormatBundle(getLocale());
Limit limit = tableFacade.getLimit();
StudyAuditLogFilter auditLogStudyFilter = getAuditLogStudyFilter(limit);
if (!limit.isComplete()) {
int totalRows = getStudySubjectDao().getCountWithFilter(auditLogStudyFilter, getCurrentStudy());
tableFacade.setTotalRows(totalRows);
}
StudyAuditLogSort auditLogStudySort = getAuditLogStudySort(limit);
/*
* if (auditLogStudySort.getSorts().size() == 0) {
* auditLogStudySort.addSort("loginAttemptDate", "desc"); }
*/
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<StudySubjectBean> items = getStudySubjectDao().getWithFilterAndSort(getCurrentStudy(), auditLogStudyFilter, auditLogStudySort, rowStart, rowEnd);
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
for (StudySubjectBean studySubjectBean : items) {
SubjectBean subject = (SubjectBean) getSubjectDao().findByPK(studySubjectBean.getSubjectId());
UserAccountBean owner = (UserAccountBean) getUserAccountDao().findByPK(studySubjectBean.getOwnerId());
HashMap<Object, Object> h = new HashMap<Object, Object>();
h.put("studySubject", studySubjectBean);
h.put("studySubject.label", studySubjectBean.getLabel());
h.put("studySubject.secondaryLabel", studySubjectBean.getSecondaryLabel());
h.put("studySubject.oid", studySubjectBean.getOid());
h.put("studySubject.owner", owner);
h.put("studySubject.status", studySubjectBean.getStatus());
h.put("subject", subject);
h.put("subject.dateOfBirth", resolveBirthDay(subject.getDateOfBirth(), subject.isDobCollected(), getLocale()));
h.put("subject.uniqueIdentifier", subject.getUniqueIdentifier());
theItems.add(h);
}
tableFacade.setItems(theItems);
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class StudySubjectEndpoint method createSubject.
private String createSubject(SubjectTransferBean subjectTransfer) {
SubjectBean subject = new SubjectBean();
subject.setUniqueIdentifier(subjectTransfer.getPersonId());
subject.setLabel(subjectTransfer.getStudySubjectId());
subject.setDateOfBirth(subjectTransfer.getDateOfBirth());
// below added tbh 04/2011
if (subject.getDateOfBirth() != null) {
subject.setDobCollected(true);
} else {
subject.setDobCollected(false);
}
// >> above added tbh 04/2011, mantis issue having to
// deal with not being able to change DOB after a submit
subject.setGender(subjectTransfer.getGender());
if (subjectTransfer.getOwner() != null) {
subject.setOwner(subjectTransfer.getOwner());
}
subject.setCreatedDate(new Date());
return this.subjectService.createSubject(subject, subjectTransfer.getStudy(), subjectTransfer.getEnrollmentDate(), subjectTransfer.getSecondaryId());
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class StudySubjectEndpoint method mapListStudySubjectsInStudyResponse.
/**
* Build the response for listStudySubjectsInStudy method
*
* @param study
* @param message
* @param studyRef
* @return ListAllByStudyResponse
* @throws Exception
*/
private ListAllByStudyResponse mapListStudySubjectsInStudyResponse(StudyBean study, String message, StudyRefType studyRef) throws Exception {
ListAllByStudyResponse response = new ListAllByStudyResponse();
response.setResult(message);
StudySubjectsType studySubjectsType = new StudySubjectsType();
response.setStudySubjects(studySubjectsType);
List<StudySubjectBean> studySubjects = this.subjectService.getStudySubject(study);
for (StudySubjectBean studySubjectBean : studySubjects) {
StudySubjectWithEventsType studySubjectType = new StudySubjectWithEventsType();
SubjectType subjectType = new SubjectType();
studySubjectType.setLabel(studySubjectBean.getLabel());
studySubjectType.setSecondaryLabel(studySubjectBean.getSecondaryLabel());
if (studySubjectBean.getEnrollmentDate() != null) {
studySubjectType.setEnrollmentDate(getXMLGregorianCalendarDate(studySubjectBean.getEnrollmentDate()));
}
SubjectBean subjectBean = (SubjectBean) getSubjectDao().findByPK(studySubjectBean.getSubjectId());
subjectType.setUniqueIdentifier(subjectBean.getUniqueIdentifier());
String genderStr = String.valueOf(subjectBean.getGender());
if (!"".equals(genderStr.trim())) {
subjectType.setGender(GenderType.fromValue(genderStr));
}
if (subjectBean.getDateOfBirth() != null) {
subjectType.setDateOfBirth(getXMLGregorianCalendarDate(subjectBean.getDateOfBirth()));
}
studySubjectType.setSubject(subjectType);
// studySubjectType.setStudyRef(studyRef);
logger.debug(studySubjectBean.getLabel());
studySubjectType.setEvents(getEvents(studySubjectBean));
studySubjectsType.getStudySubject().add(studySubjectType);
}
return response;
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class SubjectTransferValidator method validate.
@Override
public void validate(Object obj, Errors e) {
SubjectTransferBean subjectTransferBean = (SubjectTransferBean) obj;
if (subjectTransferBean.getStudyOid() == null) {
e.reject("studyEventTransferValidator.study_does_not_exist");
return;
}
Status[] included_status = new Status[] { Status.AVAILABLE };
StudyBean study = helper.verifyStudy(getStudyDAO(), subjectTransferBean.getStudyOid(), included_status, e);
if (study == null)
return;
StudyBean site = null;
int site_id = -1;
subjectTransferBean.setStudy(study);
if (subjectTransferBean.getSiteIdentifier() != null) {
site = helper.verifySite(getStudyDAO(), subjectTransferBean.getStudyOid(), subjectTransferBean.getSiteIdentifier(), included_status, e);
if (site == null) {
return;
}
site_id = site.getId();
subjectTransferBean.setStudy(site);
}
boolean isRoleVerified = helper.verifyRole(subjectTransferBean.getOwner(), study.getId(), site_id, Role.MONITOR, e);
if (!isRoleVerified) {
return;
}
// StudyBean study = null;
// if ( subjectTransferBean.getStudyOid() != null)
// {
// study = getStudyDAO().findByUniqueIdentifier(subjectTransferBean.getStudyOid());
// if (study == null) {
// e.reject("subjectTransferValidator.study_does_not_exist", new Object[] { subjectTransferBean.getStudyOid() }, "Study identifier you specified "
// + subjectTransferBean.getStudyOid() + " does not correspond to a valid study.");
// return;
// }
// //validate study status
// if (study != null && !study.getStatus().isAvailable()) {
// e.reject("subjectTransferValidator.study_status_wrong", new Object[] { subjectTransferBean.getStudyOid() }, "Study "
// + subjectTransferBean.getStudyOid() +" has wrong status. Subject can be added to an 'AVAILABLE' study only.");
// return;
// }
// subjectTransferBean.setStudy(study);
// }
// UserAccountBean ua = subjectTransferBean.getOwner();
// StudyUserRoleBean role = ua.getRoleByStudy(subjectTransferBean.getStudy());
// if (role.getId() == 0 || role.getRole().equals(Role.MONITOR)) {
// e.reject("subjectTransferValidator.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
// return;
// }
// StudyBean site = null;
// if (subjectTransferBean.getSiteIdentifier() != null) {
// site = getStudyDAO().findSiteByUniqueIdentifier(subjectTransferBean.getStudyOid(), subjectTransferBean.getSiteIdentifier());
// if (site == null) {
// e.reject("subjectTransferValidator.site_does_not_exist", new Object[] { subjectTransferBean.getSiteIdentifier() },
// "Site identifier you specified does not correspond to a valid site.");
// return;
// }
// //validate site status
// if ( ! site.getStatus().isAvailable()) {
//
// e.reject("subjectTransferValidator.site_status_wrong", new Object[] { subjectTransferBean.getSiteIdentifier() }, "Site "
// + site.getName() +" has wrong status. Subject can be added to an 'AVAILABLE' site only.");
// return;
// }
// subjectTransferBean.setStudy(site);//???????????
// }
// role = ua.getRoleByStudy(site);
// if (role.getId() == 0 || role.getRole().equals(Role.MONITOR)) {
// e.reject("subjectTransferValidator.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
// return;
// }
//
int handleStudyId = study.getParentStudyId() > 0 ? study.getParentStudyId() : study.getId();
StudyParameterValueBean studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectPersonIdRequired");
String personId = subjectTransferBean.getPersonId();
if (personId.contains("<") || personId.contains(">")) {
e.reject("subjectTransferValidator.person_id_can_not_contain_html_lessthan_or_greaterthan_elements");
return;
}
if ("required".equals(studyParameter.getValue()) && (personId == null || personId.length() < 1)) {
e.reject("subjectTransferValidator.personId_required", new Object[] { study.getName() }, "personId is required for the study: " + study.getName());
return;
}
if ("not used".equals(studyParameter.getValue()) && !(personId == null || personId.length() < 1)) {
e.reject("subjectTransferValidator.personId_not_used", new Object[] { study.getName() }, "personId is not used for the study: " + study.getName());
return;
}
if (personId != null && personId.length() > 255) {
e.reject("subjectTransferValidator.personId_invalid_length", new Object[] { personId }, "personId: " + personId + " cannot be longer than 255 characters.");
return;
}
// verify that personId is unique
if (subjectTransferBean.getPersonId() != null && subjectTransferBean.getPersonId().length() > 0) {
// SubjectBean subjectWithSamePersonId = getSubjectDao().findByUniqueIdentifierAndStudy( subjectTransferBean.getPersonId(), study.getId());
SubjectBean subjectWithSamePersonId = getSubjectDao().findByUniqueIdentifierAndAnyStudy(subjectTransferBean.getPersonId(), study.getId());
if (subjectWithSamePersonId.getId() != 0) {
e.reject("subjectTransferValidator.personId_duplicated", new Object[] { personId }, "A subject with the Person ID: " + personId + " is already enrolled in this study. ");
return;
}
}
StudyParameterValueBean subjectIdGenerationParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectIdGeneration");
String idSetting = subjectIdGenerationParameter.getValue();
if (!(idSetting.equals("auto editable") || idSetting.equals("auto non-editable"))) {
String studySubjectId = subjectTransferBean.getStudySubjectId();
if (studySubjectId == null || studySubjectId.length() < 1) {
e.reject("subjectTransferValidator.studySubjectId_required");
return;
} else if (studySubjectId.length() > 30) {
e.reject("subjectTransferValidator.studySubjectId_invalid_length", new Object[] { studySubjectId }, "studySubjectId: " + studySubjectId + " cannot be longer than 30 characters.");
return;
} else {
// checks whether there is a subject with same id inside current study
StudySubjectBean subjectWithSame = getStudySubjectDAO().findByLabelAndStudy(studySubjectId, study);
if (subjectWithSame.getLabel().equals(studySubjectId)) {
e.reject("subjectTransferValidator.subject_duplicated_label", new Object[] { studySubjectId, study.getIdentifier() }, "studySubjectId: " + studySubjectId + " already exists for " + study.getIdentifier() + " study .");
return;
}
}
if (studySubjectId.contains("<") || studySubjectId.contains(">")) {
e.reject("subjectTransferValidator.study_subject_id_can_not_contain_html_lessthan_or_greaterthan_elements");
return;
}
}
String secondaryId = subjectTransferBean.getSecondaryId();
if (secondaryId != null && secondaryId.length() > 30) {
e.reject("subjectTransferValidator.secondaryId_invalid_length", new Object[] { secondaryId }, "secondaryId: " + secondaryId + " cannot be longer than 30 characters.");
return;
}
if (secondaryId.contains("<") || secondaryId.contains(">")) {
e.reject("subjectTransferValidator.secondary_id_can_not_contain_html_lessthan_or_greaterthan_elements");
return;
}
String gender = String.valueOf(subjectTransferBean.getGender());
studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "genderRequired");
if ("true".equals(studyParameter.getValue())) {
if (gender == null || gender.length() < 1) {
e.reject("subjectTransferValidator.gender_required", new Object[] { study.getName() }, "Gender is required for the study: " + study.getName());
return;
}
if (!"m".equals(gender) && !"f".equals(gender)) {
e.reject("subjectTransferValidator.gender_is_m_or_f");
return;
}
} else {
if (gender.trim().length() > 0 && !("m".equals(gender) || "f".equals(gender))) {
e.reject("subjectTransferValidator.gender_is_m_or_f");
return;
}
}
Date dateOfBirth = subjectTransferBean.getDateOfBirth();
String yearOfBirth = subjectTransferBean.getYearOfBirth();
studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "collectDob");
if ("1".equals(studyParameter.getValue()) && (dateOfBirth == null)) {
e.reject("subjectTransferValidator.dateOfBirth_required", new Object[] { study.getName() }, "Date of birth is required for the study " + study.getName());
return;
} else if ("2".equals(studyParameter.getValue()) && (yearOfBirth == null)) {
e.reject("subjectTransferValidator.yearOfBirth_required", new Object[] { study.getName() }, "Year of birth is required for the study " + study.getName());
return;
} else if ("2".equals(studyParameter.getValue()) && (yearOfBirth != null)) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
subjectTransferBean.setDateOfBirth(sdf.parse(subjectTransferBean.getYearOfBirth()));
} catch (ParseException xe) {
e.reject("subjectTransferValidator.yearOfBirth_invalid", new Object[] { yearOfBirth }, "Year of birth: " + yearOfBirth + " is not valid");
return;
}
//not used
} else if ("3".equals(studyParameter.getValue())) {
if (dateOfBirth != null || !(yearOfBirth == null || yearOfBirth.length() < 1)) {
e.reject("subjectTransferValidator.date_of_birth_notused", new Object[] { study.getName() }, "Date of Birth is not used for the study " + study.getName());
return;
}
}
Date enrollmentDate = subjectTransferBean.getEnrollmentDate();
if (enrollmentDate == null) {
e.reject("subjectTransferValidator.enrollmentDate_required");
return;
} else {
if ((new Date()).compareTo(enrollmentDate) < 0) {
e.reject("subjectTransferValidator.enrollmentDate_should_be_in_past");
return;
}
}
}
Aggregations