use of org.akaza.openclinica.bean.managestudy.SubjectTransferBean in project OpenClinica by OpenClinica.
the class StudySubjectEndpoint method unMarshallToSubjectTransfer.
/**
* Process createStudySubject request by creating SubjectTransferBean from received payload.
*
* @param subjectElement
* @return SubjectTransferBean
* @throws ParseException
*/
private SubjectTransferBean unMarshallToSubjectTransfer(Element subjectElement) throws ParseException, Exception {
Element studySubjectIdElement = DomUtils.getChildElementByTagName(subjectElement, "label");
Element secondaryIdElement = DomUtils.getChildElementByTagName(subjectElement, "secondaryLabel");
Element enrollmentDateElement = DomUtils.getChildElementByTagName(subjectElement, "enrollmentDate");
Element subject = DomUtils.getChildElementByTagName(subjectElement, "subject");
Element personIdElement = DomUtils.getChildElementByTagName(subject, "uniqueIdentifier");
Element genderElement = DomUtils.getChildElementByTagName(subject, "gender");
Element dateOfBirthElement = DomUtils.getChildElementByTagName(subject, "dateOfBirth");
Element yearOfBirthElement = DomUtils.getChildElementByTagName(subject, "yearOfBirth");
Element study = DomUtils.getChildElementByTagName(subjectElement, "studyRef");
Element studyIdentifierElement = DomUtils.getChildElementByTagName(study, "identifier");
Element site = DomUtils.getChildElementByTagName(study, "siteRef");
Element siteIdentifierElement = site == null ? null : DomUtils.getChildElementByTagName(site, "identifier");
String personIdValue = personIdElement == null ? "" : DomUtils.getTextValue(personIdElement).trim();
String studySubjectIdValue = studySubjectIdElement == null ? "" : DomUtils.getTextValue(studySubjectIdElement).trim();
String genderValue = genderElement == null ? null : DomUtils.getTextValue(genderElement).trim();
String secondaryIdValue = secondaryIdElement == null ? null : DomUtils.getTextValue(secondaryIdElement).trim();
String enrollmentDateValue = DomUtils.getTextValue(enrollmentDateElement).trim();
String dateOfBirthValue = dateOfBirthElement == null ? null : DomUtils.getTextValue(dateOfBirthElement).trim();
String yearOfBirthValue = yearOfBirthElement == null ? null : DomUtils.getTextValue(yearOfBirthElement).trim();
String studyIdentifier = studyIdentifierElement == null ? null : DomUtils.getTextValue(studyIdentifierElement).trim();
String siteIdentifier = siteIdentifierElement == null ? null : DomUtils.getTextValue(siteIdentifierElement).trim();
SubjectTransferBean subjectTransferBean = new SubjectTransferBean();
subjectTransferBean.setStudyOid(studyIdentifier);
subjectTransferBean.setSiteIdentifier(siteIdentifier);
subjectTransferBean.setPersonId(personIdValue);
subjectTransferBean.setStudySubjectId(studySubjectIdValue);
if (genderValue == null || genderValue.length() < 1) {
// Do nothing
} else {
subjectTransferBean.setGender(genderValue.toCharArray()[0]);
}
subjectTransferBean.setDateOfBirth((dateOfBirthValue == null || dateOfBirthValue.length() == 0) ? null : getDate(dateOfBirthValue));
subjectTransferBean.setSecondaryId(secondaryIdValue == null ? "" : secondaryIdValue);
subjectTransferBean.setYearOfBirth(yearOfBirthValue);
subjectTransferBean.setEnrollmentDate(getDate(enrollmentDateValue));
return subjectTransferBean;
}
use of org.akaza.openclinica.bean.managestudy.SubjectTransferBean 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;
}
}
}
use of org.akaza.openclinica.bean.managestudy.SubjectTransferBean in project OpenClinica by OpenClinica.
the class StudySubjectEndpoint method createStudySubject.
/**
* Use this method to create new study subjects in OpenClinica.
*
* @param subject
* @return Source
* @throws Exception
*/
@PayloadRoot(localPart = "createRequest", namespace = NAMESPACE_URI_V1)
public Source createStudySubject(@XPathParam("//studySubject:studySubject") NodeList subject) throws Exception {
Errors errors = null;
try {
ResourceBundleProvider.updateLocale(locale);
Element subjectElement = (Element) subject.item(0);
SubjectTransferBean subjectTransferBean = unMarshallToSubjectTransfer(subjectElement);
DataBinder dataBinder = new DataBinder((subjectTransferBean));
errors = dataBinder.getBindingResult();
subjectTransferBean.setOwner(getUserAccount());
SubjectTransferValidator subjectTransferValidator = new SubjectTransferValidator(dataSource);
subjectTransferValidator.validate((subjectTransferBean), errors);
if (!errors.hasErrors()) {
String label = create(subjectTransferBean);
return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.success", null, "Success", locale), label, errors));
} else {
return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.fail", null, "Fail", locale), null, errors));
}
} catch (NullPointerException npe) {
npe.printStackTrace();
return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.fail", null, "Null Pointer Exception", locale), null, errors));
} catch (Exception e) {
List<String> error_messages = new ArrayList<String>();
error_messages.add(e.getMessage());
return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.fail", null, "Fail", locale), null, errors, "label", error_messages));
}
}
use of org.akaza.openclinica.bean.managestudy.SubjectTransferBean in project OpenClinica by OpenClinica.
the class CctsSubjectEndpoint method unMarshallToSubjectTransfer.
/**
* UnMarshall SubjectTransferBean, aka create SubjectTransferBean from XML
* @param gridId
* @param subjectElement
* @param studyOidValue
* @return
* @throws ParseException
*/
private SubjectTransferBean unMarshallToSubjectTransfer(String gridId, Element subjectElement, String studyOidValue) throws ParseException {
Element personIdElement = DomUtils.getChildElementByTagName(subjectElement, "personId");
Element studySubjectIdElement = DomUtils.getChildElementByTagName(subjectElement, "studySubjectId");
Element secondaryIdElement = DomUtils.getChildElementByTagName(subjectElement, "secondaryId");
Element enrollmentDateElement = DomUtils.getChildElementByTagName(subjectElement, "enrollmentDate");
Element genderElement = DomUtils.getChildElementByTagName(subjectElement, "gender");
Element dateOfBirthElement = DomUtils.getChildElementByTagName(subjectElement, "dateOfBirth");
String personIdValue = DomUtils.getTextValue(personIdElement);
String studySubjectIdValue = DomUtils.getTextValue(studySubjectIdElement);
String genderValue = DomUtils.getTextValue(genderElement);
String secondaryIdValue = DomUtils.getTextValue(secondaryIdElement);
String enrollmentDateValue = DomUtils.getTextValue(enrollmentDateElement);
String dateOfBirthValue = DomUtils.getTextValue(dateOfBirthElement);
SubjectTransferBean subjectTransferBean = new SubjectTransferBean();
subjectTransferBean.setStudyOid(studyOidValue);
subjectTransferBean.setPersonId(personIdValue);
subjectTransferBean.setStudySubjectId(studySubjectIdValue);
subjectTransferBean.setGender(genderValue.toCharArray()[0]);
subjectTransferBean.setDateOfBirth(getDate(dateOfBirthValue));
// subjectTransferBean.setSecondaryId(secondaryIdValue);
subjectTransferBean.setEnrollmentDate(getDate(enrollmentDateValue));
return subjectTransferBean;
}
use of org.akaza.openclinica.bean.managestudy.SubjectTransferBean in project OpenClinica by OpenClinica.
the class CctsService method autoCommit.
public void autoCommit() {
List<SubjectTransferBean> subjectTransfers = getAllSubjectsInQueue();
for (SubjectTransferBean subjectTransferBean : subjectTransfers) {
if (isSubjectInQueueForMoreThanXSeconds(subjectTransferBean)) {
// TODO: 2. Create Subject , StudySubject then save
removeSubjectFromQueue(subjectTransferBean);
}
}
logger.debug("The time is : " + new Date());
}
Aggregations