Search in sources :

Example 1 with UserAccount

use of org.akaza.openclinica.domain.user.UserAccount in project OpenClinica by OpenClinica.

the class QueryServiceImpl method createQuery.

private DiscrepancyNote createQuery(QueryServiceHelperBean helperBean, QueryBean queryBean) throws Exception {
    DiscrepancyNote dn = new DiscrepancyNote();
    dn.setStudy(helperBean.getContainer().getStudy());
    dn.setEntityType("itemData");
    dn.setDescription("description");
    dn.setDetailedNotes(queryBean.getComment());
    dn.setDiscrepancyNoteType(new DiscrepancyNoteType(3));
    String user = queryBean.getUser();
    if (user == null) {
        dn.setUserAccountByOwnerId(helperBean.getContainer().getUser());
    } else {
        UserAccount userAccountByOwnerId = userAccountDao.findByUserName(user);
        dn.setUserAccountByOwnerId(userAccountByOwnerId);
    }
    setResolutionStatus(queryBean, dn);
    String assignedTo = "";
    if (queryBean.getComment().startsWith("Automatic query for:")) {
        assignedTo = helperBean.getContainer().getUser().getUserName();
    } else {
        assignedTo = queryBean.getAssigned_to();
    }
    if (!StringUtils.isEmpty(assignedTo)) {
        UserAccount userAccount = userAccountDao.findByUserName(assignedTo);
        helperBean.setUserAccount(userAccount);
        dn.setUserAccount(userAccount);
    }
    // create itemData when a query is created without an autosaved itemdata
    if (helperBean.getItemData() == null) {
        helperBean.setItemData(createBlankItemData(helperBean));
    }
    dn.setDateCreated(new Date());
    return dn;
}
Also used : DiscrepancyNote(org.akaza.openclinica.domain.datamap.DiscrepancyNote) DiscrepancyNoteType(org.akaza.openclinica.domain.datamap.DiscrepancyNoteType) UserAccount(org.akaza.openclinica.domain.user.UserAccount) Date(java.util.Date)

Example 2 with UserAccount

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;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) StringWriter(java.io.StringWriter) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) DocumentBuilder(javax.xml.parsers.DocumentBuilder) UserAccount(org.akaza.openclinica.domain.user.UserAccount)

Example 3 with UserAccount

use of org.akaza.openclinica.domain.user.UserAccount in project OpenClinica by OpenClinica.

the class IdtViewController method postSDVedItemDataAndEventCrfWorkflow.

@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity postSDVedItemDataAndEventCrfWorkflow(@RequestBody ArrayList<HashMap<String, String>> maps) throws Exception {
    int tagId = 1;
    UserAccount userAccount = null;
    HashSet<String> listOfEventCrfPaths = new HashSet();
    for (HashMap map : maps) {
        String eventCrfPath = map.get("ssOid") + "." + map.get("sedOid") + "." + map.get("eventOrdinal") + "." + map.get("crfOid");
        String itemDataPath = eventCrfPath + "." + map.get("groupOid") + "." + map.get("groupOrdinal") + "." + map.get("itemOid");
        String workflowStatus = (String) map.get("itemDataWorkflowStatus");
        listOfEventCrfPaths.add(eventCrfPath);
        saveOrUpdateItemDataFlag(tagId, itemDataPath, workflowStatus);
    }
    for (String eventCrfPath : listOfEventCrfPaths) {
        saveOrUpdateEventCrfFlag(tagId, eventCrfPath, userAccount);
    }
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) UserAccount(org.akaza.openclinica.domain.user.UserAccount) HashSet(java.util.HashSet)

Example 4 with UserAccount

use of org.akaza.openclinica.domain.user.UserAccount in project OpenClinica by OpenClinica.

the class StudySubjectProcessor method process.

@Override
public void process(SubmissionContainer container) throws Exception {
    logger.info("Executing study subject processor.");
    String studySubjectOid = container.getSubjectContext().get("studySubjectOID");
    String embeddedStudySubjectId = getEmbeddedStudySubjectOid(container);
    Date currentDate = new Date();
    UserAccount rootUser = userAccountDao.findByUserId(1);
    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd.HHmmss");
    // Standard Participant Dashboard submission
    if (studySubjectOid != null) {
        StudySubject studySubject = studySubjectDao.findByOcOID(studySubjectOid);
        container.setSubject(studySubject);
        if (studySubject.getStatus() != Status.AVAILABLE) {
            container.getErrors().reject("value.incorrect.STATUS");
            throw new Exception("StudySubject status is not Available.");
        }
    // Embedded Study Subject ID in form.  An offline submission.
    } else if (embeddedStudySubjectId != null) {
        Study study = studyDao.findByOcOID(container.getSubjectContext().get("studyOID"));
        StudySubject embeddedStudySubject = studySubjectDao.findByLabelAndStudyOrParentStudy(embeddedStudySubjectId, study);
        // If Study Subject exists in current study and is available use that
        if (embeddedStudySubject != null && embeddedStudySubject.getStatus() == Status.AVAILABLE) {
            container.setSubject(embeddedStudySubject);
        // If it exists but is in the wrong status, throw an exception
        } else if (embeddedStudySubject != null && embeddedStudySubject.getStatus() != Status.AVAILABLE) {
            container.getErrors().reject("value.incorrect.STATUS");
            throw new Exception("Embedded StudySubject status is not Available");
        // If Study Subject exists in a parent/sibling study, create study subject with 'FIXME-<timestamp>' label to avoid data loss and mark it
        } else if (subjectExistsInParentSiblingStudy(embeddedStudySubjectId, study)) {
            String subjectLabel = "FIXME-" + dateFormatter.format(currentDate);
            Subject subject = createSubject(currentDate, rootUser);
            StudySubject studySubject = createStudySubject(subjectLabel, subject, study, rootUser, currentDate, embeddedStudySubjectId);
            container.setSubject(studySubject);
        // Study Subject does not exist. Create it
        } else {
            Subject subject = createSubject(currentDate, rootUser);
            StudySubject studySubject = createStudySubject(embeddedStudySubjectId, subject, study, rootUser, currentDate, null);
            container.setSubject(studySubject);
        }
    // Anonymous submission or offline submission with no embedded Study Subject ID
    } else {
        // create Subject & Study Subject
        Study study = studyDao.findByOcOID(container.getSubjectContext().get("studyOID"));
        // Need to pass parent study Id if this is a site
        Integer studyId = study.getStudy() != null ? study.getStudy().getStudyId() : study.getStudyId();
        int nextLabel = studySubjectDao.findTheGreatestLabelByStudy(studyId) + 1;
        Subject subject = createSubject(currentDate, rootUser);
        StudySubject studySubject = createStudySubject(Integer.toString(nextLabel), subject, study, rootUser, currentDate, null);
        container.setSubject(studySubject);
    }
}
Also used : Study(org.akaza.openclinica.domain.datamap.Study) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) UserAccount(org.akaza.openclinica.domain.user.UserAccount) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) Subject(org.akaza.openclinica.domain.datamap.Subject)

Example 5 with UserAccount

use of org.akaza.openclinica.domain.user.UserAccount in project OpenClinica by OpenClinica.

the class UserProcessor method process.

@Override
public void process(SubmissionContainer container) throws Exception {
    logger.info("Executing User Processor.");
    Errors errors = container.getErrors();
    String contextStudySubjectOid = container.getSubjectContext().get("studySubjectOID");
    String studySubjectOid = container.getSubject().getOcOid();
    String parentStudyOid = getParentStudy(container.getStudy().getOc_oid()).getOc_oid();
    // if study subject oid is not null, just look up user account
    if (contextStudySubjectOid != null) {
        String userName = parentStudyOid + "." + contextStudySubjectOid;
        UserAccount existingAccount = userAccountDao.findByUserName(userName);
        if (existingAccount == null) {
            logger.info("Could not find existing user account.  Aborting submission.");
            errors.reject("Could not find existing user account.  Aborting submission.");
            throw new Exception("Could not find existing user account.  Aborting submission.");
        }
        container.setUser(existingAccount);
    } else {
        String userName = parentStudyOid + "." + studySubjectOid;
        UserAccount existingAccount = userAccountDao.findByUserName(userName);
        if (existingAccount != null) {
            container.setUser(existingAccount);
            ;
        } else {
            // Create user account
            UserAccount rootUser = userAccountDao.findByUserId(1);
            UserAccount createdUser = new UserAccount();
            createdUser.setUserName(parentStudyOid + "." + container.getSubject().getOcOid());
            createdUser.setFirstName(INPUT_FIRST_NAME);
            createdUser.setLastName(INPUT_LAST_NAME);
            createdUser.setEmail(INPUT_EMAIL);
            createdUser.setInstitutionalAffiliation(INPUT_INSTITUTION);
            createdUser.setActiveStudy(container.getStudy());
            String passwordHash = UserAccountBean.LDAP_PASSWORD;
            createdUser.setPasswd(passwordHash);
            createdUser.setPasswdTimestamp(null);
            createdUser.setDateLastvisit(null);
            createdUser.setStatus(Status.DELETED);
            createdUser.setPasswdChallengeQuestion("");
            createdUser.setPasswdChallengeAnswer("");
            createdUser.setPhone("");
            createdUser.setUserAccount(rootUser);
            createdUser.setRunWebservices(false);
            createdUser.setActiveStudy(container.getStudy());
            UserType type = userTypeDao.findByUserTypeId(2);
            createdUser.setUserType(type);
            createdUser.setEnabled(true);
            createdUser.setAccountNonLocked(true);
            createdUser.setAccessCode("");
            createdUser.setApiKey("");
            createdUser = userAccountDao.saveOrUpdate(createdUser);
            container.setUser(createdUser);
            // Create study user role
            Date date = new Date();
            StudyUserRoleId studyUserRoleId = new StudyUserRoleId(Role.RESEARCHASSISTANT2.getName(), container.getStudy().getStudyId(), Status.AUTO_DELETED.getCode(), rootUser.getUserId(), date, createdUser.getUserName());
            StudyUserRole studyUserRole = new StudyUserRole(studyUserRoleId);
            studyUserRoleDao.saveOrUpdate(studyUserRole);
        // TODO: StudyUserRole object had to be heavily modified.  May need fixing.  Also roleName specified
        // doesn't exist in role table.  May need to fix that.
        // This table should also foreign key to user_account but doesn't.
        }
    }
}
Also used : Errors(org.springframework.validation.Errors) StudyUserRole(org.akaza.openclinica.domain.datamap.StudyUserRole) UserAccount(org.akaza.openclinica.domain.user.UserAccount) UserType(org.akaza.openclinica.domain.user.UserType) Date(java.util.Date) StudyUserRoleId(org.akaza.openclinica.domain.datamap.StudyUserRoleId)

Aggregations

UserAccount (org.akaza.openclinica.domain.user.UserAccount)12 Date (java.util.Date)5 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)5 Study (org.akaza.openclinica.domain.datamap.Study)4 StudyUserRole (org.akaza.openclinica.domain.datamap.StudyUserRole)3 ArrayList (java.util.ArrayList)2 DiscrepancyNote (org.akaza.openclinica.domain.datamap.DiscrepancyNote)2 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)2 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)2 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)2 StudyUserRoleId (org.akaza.openclinica.domain.datamap.StudyUserRoleId)2 Subject (org.akaza.openclinica.domain.datamap.Subject)2 ResponseEntity (org.springframework.http.ResponseEntity)2 StringWriter (java.io.StringWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1