use of org.akaza.openclinica.service.crfdata.xform.EnketoAPI in project OpenClinica by OpenClinica.
the class PFormCache method getPFormURL.
public String getPFormURL(String studyOID, String formLayoutOID, boolean isOffline) throws Exception {
Study study = enketoCredentials.getParentStudy(studyOID);
studyOID = study.getOc_oid();
EnketoAPI enketo = new EnketoAPI(EnketoCredentials.getInstance(studyOID));
HashMap<String, String> studyURLs = null;
if (isOffline)
studyURLs = offlineUrlCache.get(studyOID);
else
studyURLs = urlCache.get(studyOID);
if (studyURLs == null) {
studyURLs = new HashMap<String, String>();
String url = null;
if (isOffline)
url = enketo.getOfflineFormURL(formLayoutOID);
else
url = enketo.getFormURL(formLayoutOID);
if (url.equals("")) {
throw new Exception("Unable to get enketo form url.");
}
studyURLs.put(formLayoutOID, url);
if (isOffline)
offlineUrlCache.put(studyOID, studyURLs);
else
urlCache.put(studyOID, studyURLs);
return url;
} else if (studyURLs.get(formLayoutOID) == null) {
String url = null;
if (isOffline)
url = enketo.getOfflineFormURL(formLayoutOID);
else
url = enketo.getFormURL(formLayoutOID);
studyURLs.put(formLayoutOID, url);
return url;
} else
return studyURLs.get(formLayoutOID);
}
use of org.akaza.openclinica.service.crfdata.xform.EnketoAPI 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;
}
use of org.akaza.openclinica.service.crfdata.xform.EnketoAPI in project OpenClinica by OpenClinica.
the class EnketoUrlService method getInitialDataEntryUrl.
public String getInitialDataEntryUrl(String subjectContextKey, PFormCacheSubjectContextEntry subjectContext, String studyOid, String flavor) throws Exception {
// Call Enketo api to get edit url
Study study = enketoCredentials.getParentStudy(studyOid);
studyOid = study.getOc_oid();
EnketoAPI enketo = new EnketoAPI(EnketoCredentials.getInstance(studyOid));
return enketo.getFormURL(subjectContext.getFormLayoutOid() + flavor) + "?ecid=" + subjectContextKey;
}
use of org.akaza.openclinica.service.crfdata.xform.EnketoAPI in project OpenClinica by OpenClinica.
the class ParticipantFormServlet method processRequest.
@Override
protected void processRequest() throws Exception {
String crf_oid = request.getParameter(CRF_ID);
String formURL = null;
// Build Enketo URL for CRF version.
if (currentStudy.getStudyParameterConfig().getParticipantPortal().equals("enabled")) {
EnketoCredentials credentials = getCredentials();
EnketoAPI enketo = new EnketoAPI(credentials);
formURL = enketo.getFormPreviewURL(crf_oid);
if (!formURL.equals("")) {
response.sendRedirect(formURL);
} else {
if (credentials.getServerUrl() == null) {
addPageMessage(respage.getString("pform_preview_missing_url"));
} else {
if ((credentials.getApiKey() != null) && (credentials.getOcInstanceUrl() != null)) {
addPageMessage(respage.getString("pform_preview_forbidden"));
} else {
addPageMessage(respage.getString("participate_not_available"));
}
}
forwardPage(Page.MENU_SERVLET);
}
}
}
Aggregations