use of org.akaza.openclinica.domain.user.UserAccount in project OpenClinica by OpenClinica.
the class OpenRosaServices method getUserXml.
private String getUserXml(ServletContext context) throws Exception {
HashMap<String, String> value = getSubjectContextCacheValue(context);
String studySubjectOid = value.get("studySubjectOID");
StudySubject ssBean = ssDao.findByOcOID(studySubjectOid);
StudyBean study = getStudy(ssBean.getStudy().getOc_oid());
StudyBean parentStudy = getParentStudy(ssBean.getStudy().getOc_oid());
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element root = doc.createElement("root");
doc.appendChild(root);
List<UserAccount> users = userAccountDao.findNonRootNonParticipateUsersByStudyId(study.getId(), parentStudy.getId());
for (UserAccount userAccount : users) {
Element item = doc.createElement("item");
Element userName = doc.createElement("user_name");
userName.appendChild(doc.createTextNode(userAccount.getUserName()));
Element firstName = doc.createElement("first_name");
firstName.appendChild(doc.createTextNode(userAccount.getFirstName()));
Element lastName = doc.createElement("last_name");
lastName.appendChild(doc.createTextNode(userAccount.getLastName()));
item.appendChild(userName);
item.appendChild(firstName);
item.appendChild(lastName);
root.appendChild(item);
}
DOMSource dom = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(dom, result);
String userXml = writer.toString();
return userXml;
}
use of org.akaza.openclinica.domain.user.UserAccount in project OpenClinica by OpenClinica.
the class OpenRosaSubmissionController method isParticipantSubmission.
private boolean isParticipantSubmission(HashMap<String, String> subjectContext) {
boolean isParticipant = true;
String userAccountId = subjectContext.get("userAccountID");
if (StringUtils.isNotEmpty(userAccountId)) {
UserAccount user = userAccountDao.findByUserId(Integer.valueOf(userAccountId));
// user name.
if (user != null && !user.getUserName().contains("."))
return false;
}
return isParticipant;
}
use of org.akaza.openclinica.domain.user.UserAccount in project OpenClinica by OpenClinica.
the class OpenRosaSubmissionController method markComplete.
// @RequestMapping(value = "/{studyOID}/fieldsubmission/complete", method = RequestMethod.POST)
public ResponseEntity<String> markComplete(HttpServletRequest request, HttpServletResponse response, @PathVariable("studyOID") String studyOID, @RequestParam(FORM_CONTEXT) String ecid) throws Exception {
HashMap<String, String> subjectContext = null;
PFormCache cache = PFormCache.getInstance(context);
subjectContext = cache.getSubjectContext(ecid);
int studyEventDefinitionID = Integer.valueOf(subjectContext.get("studyEventDefinitionID"));
int userAccountID = Integer.valueOf(subjectContext.get("userAccountID"));
String studySubjectOID = subjectContext.get("studySubjectOID");
String formLayoutOID = subjectContext.get("formLayoutOID");
int studyEventOrdinal = Integer.valueOf(subjectContext.get("studyEventOrdinal"));
UserAccount userAccount = userAccountDao.findById(userAccountID);
StudySubject studySubject = studySubjectDao.findByOcOID(studySubjectOID);
Study study = studyDao.findByOcOID(studyOID);
StudyEventDefinition sed = studyEventDefinitionDao.findById(studyEventDefinitionID);
FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOID);
CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
StudyEvent studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinalTransactional(sed.getOc_oid(), studyEventOrdinal, studySubject.getStudySubjectId());
EventCrf eventCrf = eventCrfDao.findByStudyEventIdStudySubjectIdFormLayoutId(studyEvent.getStudyEventId(), studySubject.getStudySubjectId(), formLayout.getFormLayoutId());
if (eventCrf == null) {
eventCrf = createEventCrf(formLayout, studyEvent, studySubject, userAccount);
List<Item> items = itemDao.findAllByCrfVersion(crfVersion.getCrfVersionId());
createItemData(items.get(0), "", eventCrf, userAccount);
}
eventCrf.setStatusId(org.akaza.openclinica.domain.Status.UNAVAILABLE.getCode());
eventCrf.setUserAccount(userAccount);
eventCrf.setUpdateId(userAccount.getUserId());
eventCrf.setDateUpdated(new Date());
eventCrfDao.saveOrUpdate(eventCrf);
List<EventCrf> eventCrfs = eventCrfDao.findByStudyEventIdStudySubjectId(studyEvent.getStudyEventId(), studySubject.getOcOid());
List<EventDefinitionCrf> eventDefinitionCrfs = eventDefinitionCrfDao.findAvailableByStudyEventDefStudy(sed.getStudyEventDefinitionId(), study.getStudyId());
int count = 0;
for (EventCrf evCrf : eventCrfs) {
if (evCrf.getStatusId() == org.akaza.openclinica.domain.Status.UNAVAILABLE.getCode() || evCrf.getStatusId() == org.akaza.openclinica.domain.Status.DELETED.getCode() || evCrf.getStatusId() == org.akaza.openclinica.domain.Status.AUTO_DELETED.getCode()) {
for (EventDefinitionCrf eventDefinitionCrf : eventDefinitionCrfs) {
if (eventDefinitionCrf.getCrf().getCrfId() == evCrf.getFormLayout().getCrf().getCrfId()) {
count++;
break;
}
}
}
}
if (count == eventDefinitionCrfs.size()) {
studyEvent.setSubjectEventStatusId(SubjectEventStatus.COMPLETED.getCode());
studyEvent.setUserAccount(userAccount);
studyEventDao.saveOrUpdate(studyEvent);
} else if (studyEvent.getSubjectEventStatusId() == SubjectEventStatus.SCHEDULED.getCode()) {
studyEvent.setSubjectEventStatusId(SubjectEventStatus.DATA_ENTRY_STARTED.getCode());
studyEvent.setUserAccount(userAccount);
studyEventDao.saveOrUpdate(studyEvent);
}
String responseMessage = "<OpenRosaResponse xmlns=\"http://openrosa.org/http/response\">" + "<message>success</message>" + "</OpenRosaResponse>";
return new ResponseEntity<String>(responseMessage, HttpStatus.CREATED);
}
use of org.akaza.openclinica.domain.user.UserAccount in project OpenClinica by OpenClinica.
the class StudySubjectProcessor method createSubject.
private Subject createSubject(Date currentDate) {
UserAccount rootUser = userAccountDao.findByUserId(1);
Subject subject = new Subject();
subject.setUserAccount(rootUser);
subject.setStatus(Status.AVAILABLE);
subject.setDobCollected(false);
subject.setDateCreated(currentDate);
subject.setUniqueIdentifier("");
subject = subjectDao.saveOrUpdate(subject);
return subject;
}
use of org.akaza.openclinica.domain.user.UserAccount in project OpenClinica by OpenClinica.
the class OdmImportServiceImpl method importOdmToOC.
@Transactional
public void importOdmToOC(ODM odm) {
UserAccount userAccount = getCurrentUser();
// TODO add validation to all entities
ODMcomplexTypeDefinitionStudy odmStudy = odm.getStudy().get(0);
Study study = saveOrUpdateStudy(odm, userAccount, odmStudy);
ParticipantPortalRegistrar portal = new ParticipantPortalRegistrar();
portal.registerStudy(study.getOc_oid(), study.getOc_oid(), study.getName());
StudyParameterValue spv = getStudyParameterValueDao().findByStudyIdParameter(study.getStudyId(), "participantPortal");
// Update OC Study configuration
if (spv == null) {
spv = new StudyParameterValue();
spv.setStudy(study);
}
spv.setValue("enabled");
spv = getStudyParameterValueDao().saveOrUpdate(spv);
StudyUserRole studyUserRole = null;
StudyUserRoleId studyUserRoleId = null;
Form[] fmCrfs = getAllCrfsByProtIdFromFormManager(study);
ArrayList<StudyUserRole> surRoles = getStudyUserRoleDao().findAllUserRolesByUserAccount(userAccount, study.getStudyId(), study.getStudyId());
if (surRoles.size() == 0) {
studyUserRoleId = new StudyUserRoleId();
studyUserRole = new StudyUserRole();
studyUserRole = getStudyUserRoleDao().saveOrUpdate(populateUserRole(study, userAccount, studyUserRole, studyUserRoleId));
}
StudyEventDefinition studyEventDefinition = null;
List<ODMcomplexTypeDefinitionMetaDataVersion> odmMetadataVersions = odmStudy.getMetaDataVersion();
List<ODMcomplexTypeDefinitionStudyEventDef> odmStudyEventDefs = saveOrUpdateEvent(userAccount, study, odmMetadataVersions);
CrfBean crf = null;
FormLayout formLayout = null;
saveOrUpdateCrf(userAccount, study, odmMetadataVersions, fmCrfs);
List<ODMcomplexTypeDefinitionStudyEventRef> odmStudyEventRefs = odmMetadataVersions.get(0).getProtocol().getStudyEventRef();
for (ODMcomplexTypeDefinitionStudyEventRef odmStudyEventRef : odmStudyEventRefs) {
for (ODMcomplexTypeDefinitionStudyEventDef odmStudyEventDef : odmStudyEventDefs) {
if (odmStudyEventDef.getOID().equals(odmStudyEventRef.getStudyEventOID())) {
studyEventDefinition = getStudyEventDefDao().findByOcOID(odmStudyEventDef.getOID());
studyEventDefinition.setOrdinal(odmStudyEventRef.getOrderNumber().intValue());
studyEventDefinition = getStudyEventDefDao().saveOrUpdate(studyEventDefinition);
List<EventDefinitionCrf> jsonEventDefCrfList = new ArrayList<>();
EventDefinitionCrf eventDefinitionCrf = null;
for (ODMcomplexTypeDefinitionFormRef odmFormRef : odmStudyEventDef.getFormRef()) {
crf = getCrfDao().findByOcOID(odmFormRef.getFormOID());
eventDefinitionCrf = getEventDefinitionCrfDao().findByStudyEventDefinitionIdAndCRFIdAndStudyId(studyEventDefinition.getStudyEventDefinitionId(), crf.getCrfId(), study.getStudyId());
String defaultVersionName = null;
OCodmComplexTypeDefinitionConfigurationParameters conf = odmFormRef.getConfigurationParameters();
List<OCodmComplexTypeDefinitionFormLayoutRef> formLayoutRefs = odmFormRef.getFormLayoutRef();
if (formLayoutRefs.size() == 1 && formLayoutRefs.get(0).getIsDefaultVersion() == null) {
defaultVersionName = formLayoutRefs.get(0).getOID();
} else {
for (OCodmComplexTypeDefinitionFormLayoutRef formLayoutRef : formLayoutRefs) {
if (formLayoutRef.getIsDefaultVersion().equalsIgnoreCase("Yes")) {
defaultVersionName = formLayoutRef.getOID();
}
}
}
if (defaultVersionName == null) {
defaultVersionName = formLayoutRefs.get(0).getOID();
}
formLayout = getFormLayoutDao().findByNameCrfId(defaultVersionName, crf.getCrfId());
EventDefinitionCrfDTO edcObj = new EventDefinitionCrfDTO();
edcObj.setUserAccount(userAccount);
edcObj.setConf(conf);
edcObj.setCrf(crf);
edcObj.setEventDefinitionCrf(eventDefinitionCrf);
edcObj.setOdmFormRef(odmFormRef);
edcObj.setStudy(study);
edcObj.setFormLayout(formLayout);
edcObj.setStudyEventDefinition(studyEventDefinition);
EDCTagDTO populateEDCTagParameter = new EDCTagDTO();
populateEDCTagParameter.setConf(conf);
populateEDCTagParameter.setConf(conf);
populateEDCTagParameter.setEventDefinitionCrf(eventDefinitionCrf);
populateEDCTagParameter.setUserAccount(userAccount);
eventDefinitionCrf = saveOrUpdateEventDefnCrf(new EventDefinitionCrfDTO(edcObj));
saveOrUpdateEDCTag(new EDCTagDTO(populateEDCTagParameter), studyEventDefinition, crf);
jsonEventDefCrfList.add(eventDefinitionCrf);
}
List<EventDefinitionCrf> ocEventDefCrfList = getEventDefinitionCrfDao().findAvailableByStudyEventDefStudy(studyEventDefinition.getStudyEventDefinitionId(), study.getStudyId());
for (EventDefinitionCrf ocEventDefCrf : ocEventDefCrfList) {
if (!jsonEventDefCrfList.contains(ocEventDefCrf)) {
ocEventDefCrf.setStatusId(Status.DELETED.getCode());
getEventDefinitionCrfDao().saveOrUpdate(ocEventDefCrf);
}
}
}
}
}
}
Aggregations