use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class RandomizeService method getRandomizationCode.
// Rest Call to OCUI to get Randomization
public String getRandomizationCode(EventCRFBean eventCrfBean, List<StratificationFactorBean> stratificationFactorBeans, RuleSetBean ruleSet) throws JSONException {
StudySubjectDAO ssdao = new StudySubjectDAO<>(ds);
StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
// study subject oid
String identifier = ssBean.getOid();
StudyDAO sdao = new StudyDAO<>(ds);
StudyBean sBean = (StudyBean) sdao.findByPK(ssBean.getStudyId());
// site or study oid
String siteIdentifier = sBean.getOid();
// site or study name
String name = sBean.getName();
UserAccountDAO udao = new UserAccountDAO(ds);
int userId = 0;
if (eventCrfBean.getUpdaterId() == 0) {
userId = eventCrfBean.getOwnerId();
} else {
userId = eventCrfBean.getUpdaterId();
}
UserAccountBean uBean = (UserAccountBean) udao.findByPK(userId);
String user = uBean.getName();
// sBean should be parent study
// put randomization object in cache
StudyBean study = getParentStudy(sBean.getOid());
SeRandomizationDTO randomization = null;
try {
randomization = getCachedRandomizationDTOObject(study.getOid(), false);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String randomiseUrl = randomization.getUrl();
String username = randomization.getUsername();
String password = randomization.getPassword();
String timezone = "America/New_York";
// String randomiseUrl = "https://evaluation.sealedenvelope.com/redpill/seti2";
// String username = "oc";
// String password = "secret";
HttpHeaders headers = createHeaders(username, password);
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// retrieve json object if Randomization exist ,otherwise return a null object
JSONObject jsonRandObject = retrieveARandomisation(randomiseUrl, ssBean, headers);
if (jsonRandObject != null) {
return (String) jsonRandObject.get("code");
} else {
// if Site identifier exists ,then update otherwise create new Site identifier
addOrUpdateASite(randomiseUrl, sBean, headers, timezone);
// send for Randomization
JSONObject jsonRandomisedObject = randomiseSubject(randomiseUrl, ssBean, sBean, headers, user, stratificationFactorBeans, eventCrfBean, ruleSet);
if (jsonRandomisedObject != null)
return (String) jsonRandomisedObject.get("code");
else
return "";
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class DiscrepancyNoteUtil method getStudySubjectIdForDiscNote.
public int getStudySubjectIdForDiscNote(DiscrepancyNoteBean discrepancyNoteBean, DataSource dataSource, int studyId) {
if (discrepancyNoteBean == null)
return 0;
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
List<StudySubjectBean> studySubjectBeans = new ArrayList<StudySubjectBean>();
if ("subject".equalsIgnoreCase(discrepancyNoteBean.getEntityType())) {
studySubjectBeans = studySubjectDAO.findAllBySubjectId(discrepancyNoteBean.getEntityId());
for (StudySubjectBean bean : studySubjectBeans) {
if (bean.getStudyId() == studyId) {
return bean.getId();
} else {
if (((StudyBean) new StudyDAO(dataSource).findByPK(bean.getStudyId())).getParentStudyId() == studyId) {
return bean.getId();
}
}
}
} else if ("studySub".equalsIgnoreCase(discrepancyNoteBean.getEntityType())) {
return discrepancyNoteBean.getEntityId();
}
return 0;
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class DiscrepancyNoteUtil method injectDiscNotesIntoStudyEvents.
/**
* This method links discrepancy notes to the study event and study subject
* associated with those notes
*
* @param studyBeans
* A List of StudyEventBeans.
* @param allDiscNotes
* A List of DiscrepancyNoteBeans associated with a single study.
* @param dataSource
* A DataSource used to get from the database a study subject
* associated with a study event.
*/
public void injectDiscNotesIntoStudyEvents(List<StudyEventBean> studyBeans, List<DiscrepancyNoteBean> allDiscNotes, DataSource dataSource) {
if (studyBeans == null || allDiscNotes == null) {
return;
}
StudySubjectDAO studySubjDAO = new StudySubjectDAO(dataSource);
StudySubjectBean studySubjBean = new StudySubjectBean();
for (StudyEventBean sbean : studyBeans) {
// Get the StudySubjectBean associated with the study event
studySubjBean = (StudySubjectBean) studySubjDAO.findByPK(sbean.getStudySubjectId());
// equals the StudySubjectBean's name
for (DiscrepancyNoteBean discBean : allDiscNotes) {
if (sbean.getStudyEventDefinition().getName().equalsIgnoreCase(discBean.getEventName()) && studySubjBean.getLabel().equalsIgnoreCase(discBean.getSubjectName())) {
// add discrepancy note to the study event list of notes
// Each study bean has a List property containing its
// associated
// DiscrepancyNoteBeans
sbean.getDiscBeanList().add(discBean);
}
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class ClinicalDataCollector method collectOdmClinicalDataMap.
public void collectOdmClinicalDataMap() {
Iterator<OdmStudyBase> it = this.getStudyBaseMap().values().iterator();
while (it.hasNext()) {
JobTerminationMonitor.check();
OdmStudyBase u = it.next();
ClinicalDataUnit cdata = new ClinicalDataUnit(this.ds, this.dataset, this.getOdmbean(), u.getStudy(), this.getCategory());
cdata.setCategory(this.getCategory());
StudySubjectDAO ssdao = new StudySubjectDAO(this.ds);
cdata.setStudySubjectIds(ssdao.findStudySubjectIdsByStudyIds(u.getStudy().getId() + ""));
cdata.collectOdmClinicalData();
odmClinicalDataMap.put(u.getStudy().getOid(), cdata.getOdmClinicalData());
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class DeleteCRFVersionServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int versionId = fp.getInt(VERSION_ID, true);
String action = request.getParameter("action");
if (versionId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_version_to_delete"));
forwardPage(Page.CRF_LIST_SERVLET);
} else {
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDAO seDao = new StudyEventDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId);
// find definitions using this version
ArrayList definitions = edcdao.findByDefaultVersion(version.getId());
for (Object edcBean : definitions) {
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(((EventDefinitionCRFBean) edcBean).getStudyEventDefinitionId());
((EventDefinitionCRFBean) edcBean).setEventName(sedBean.getName());
}
// find event crfs using this version
ArrayList<ItemDataBean> idBeans = iddao.findByCRFVersion(version);
ArrayList<EventCRFBean> eCRFs = ecdao.findAllByCRF(version.getCrfId());
for (EventCRFBean eCRF : eCRFs) {
StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eCRF.getStudySubjectId());
eCRF.setStudySubject(ssBean);
StudyEventBean seBean = (StudyEventBean) seDao.findByPK(eCRF.getStudyEventId());
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(seBean.getStudyEventDefinitionId());
seBean.setStudyEventDefinition(sedBean);
eCRF.setStudyEvent(seBean);
}
ArrayList eventCRFs = ecdao.findAllByCRFVersion(versionId);
boolean canDelete = true;
if (!definitions.isEmpty()) {
// used in definition
canDelete = false;
request.setAttribute("definitions", definitions);
addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_definitions_cannot_delete"));
} else if (!idBeans.isEmpty()) {
canDelete = false;
request.setAttribute("eventCRFs", eCRFs);
request.setAttribute("itemDataForVersion", idBeans);
addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_item_data_cannot_delete"));
} else if (!eventCRFs.isEmpty()) {
canDelete = false;
request.setAttribute("eventsForVersion", eventCRFs);
addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_cannot_delete"));
}
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute(VERSION_TO_DELETE, version);
forwardPage(Page.DELETE_CRF_VERSION);
} else {
// submit
if (canDelete) {
ArrayList items = cvdao.findNotSharedItemsByVersion(versionId);
NewCRFBean nib = new NewCRFBean(sm.getDataSource(), version.getCrfId());
nib.setDeleteQueries(cvdao.generateDeleteQueries(versionId, items));
nib.deleteFromDB();
addPageMessage(respage.getString("the_CRF_version_has_been_deleted_succesfully"));
} else {
addPageMessage(respage.getString("the_CRF_version_cannot_be_deleted"));
}
forwardPage(Page.CRF_LIST_SERVLET);
}
}
}
Aggregations