Search in sources :

Example 11 with CrfVersion

use of org.akaza.openclinica.domain.datamap.CrfVersion in project OpenClinica by OpenClinica.

the class EnketoUrlService method getEditUrl.

public String getEditUrl(String subjectContextKey, PFormCacheSubjectContextEntry subjectContext, String studyOid, FormLayout formLayout, StudyEvent studyEvent, String flavor) throws Exception {
    Study study = enketoCredentials.getParentStudy(studyOid);
    studyOid = study.getOc_oid();
    String editURL = null;
    StudyEventDefinition eventDef;
    StudySubject subject;
    String goTo = null;
    if (subjectContext.getItemName() != null) {
        goTo = (subjectContext.isItemInRepeatingGroup()) ? "//" + subjectContext.getItemRepeatGroupName() + "[" + subjectContext.getItemRepeatOrdinal() + "]//" + subjectContext.getItemName() : "//" + subjectContext.getItemName();
    }
    if (studyEvent == null) {
        // Lookup relevant data
        eventDef = studyEventDefinitionDao.findByStudyEventDefinitionId(subjectContext.getStudyEventDefinitionId());
        subject = studySubjectDao.findByOcOID(subjectContext.getStudySubjectOid());
        studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinal(eventDef.getOc_oid(), Integer.valueOf(subjectContext.getOrdinal()), subject.getStudySubjectId());
    } else {
        eventDef = studyEvent.getStudyEventDefinition();
        subject = studyEvent.getStudySubject();
    }
    if (formLayout == null) {
        formLayout = formLayoutDao.findByOcOID(subjectContext.getFormLayoutOid());
    }
    EventCrf eventCrf = eventCrfDao.findByStudyEventIdStudySubjectIdFormLayoutId(studyEvent.getStudyEventId(), subject.getStudySubjectId(), formLayout.getFormLayoutId());
    CrfVersion crfVersion = eventCrf.getCrfVersion();
    // Load populated instance
    String populatedInstance = populateInstance(crfVersion, formLayout, eventCrf, studyOid, flavor);
    // Call Enketo api to get edit url
    EnketoAPI enketo = new EnketoAPI(EnketoCredentials.getInstance(studyOid));
    // Build redirect url
    String redirectUrl = getRedirectUrl(subject.getOcOid(), studyOid);
    boolean markComplete = true;
    if (eventCrf.getStatusId() == Status.UNAVAILABLE.getCode()) {
        markComplete = false;
    }
    // Return Enketo URL
    List<FormLayoutMedia> mediaList = formLayoutMediaDao.findByEventCrfId(eventCrf.getEventCrfId());
    EnketoURLResponse eur = enketo.getEditURL(formLayout, flavor, populatedInstance, subjectContextKey, redirectUrl, markComplete, studyOid, mediaList, goTo);
    editURL = eur.getEdit_url();
    int hashIndex = editURL.lastIndexOf("#");
    String part1 = "";
    String part2 = "";
    if (hashIndex != -1) {
        part1 = editURL.substring(0, hashIndex);
        part2 = editURL.substring(hashIndex);
        editURL = part1 + "&ecid=" + subjectContextKey + part2;
    } else {
        editURL = editURL + "&ecid=" + subjectContextKey;
    }
    logger.debug("Generating Enketo edit url for form: " + editURL);
    return editURL;
}
Also used : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) Study(org.akaza.openclinica.domain.datamap.Study) EnketoAPI(org.akaza.openclinica.service.crfdata.xform.EnketoAPI) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) FormLayoutMedia(org.akaza.openclinica.domain.datamap.FormLayoutMedia) EnketoURLResponse(org.akaza.openclinica.service.crfdata.xform.EnketoURLResponse)

Aggregations

CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)11 Date (java.util.Date)5 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)4 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)4 Study (org.akaza.openclinica.domain.datamap.Study)3 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)3 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)3 FormLayoutMedia (org.akaza.openclinica.domain.datamap.FormLayoutMedia)2 Item (org.akaza.openclinica.domain.datamap.Item)2 Query (org.hibernate.query.Query)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Errors (org.springframework.validation.Errors)2 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)1 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)1