Search in sources :

Example 1 with EnketoURLResponse

use of org.akaza.openclinica.service.crfdata.xform.EnketoURLResponse 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)1 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)1 FormLayoutMedia (org.akaza.openclinica.domain.datamap.FormLayoutMedia)1 Study (org.akaza.openclinica.domain.datamap.Study)1 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)1 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)1 EnketoAPI (org.akaza.openclinica.service.crfdata.xform.EnketoAPI)1 EnketoURLResponse (org.akaza.openclinica.service.crfdata.xform.EnketoURLResponse)1