use of org.akaza.openclinica.domain.datamap.FormLayout 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.datamap.FormLayout in project OpenClinica by OpenClinica.
the class EventProcessor method process.
public ProcessorEnum process(SubmissionContainer container) throws Exception {
logger.info("Executing Event Processor.");
Errors errors = container.getErrors();
StudySubject studySubject = container.getSubject();
StudyEventDefinition studyEventDefinition = studyEventDefinitionDao.findByStudyEventDefinitionId(Integer.valueOf(container.getSubjectContext().get("studyEventDefinitionID")));
FormLayout formLayout = formLayoutDao.findByOcOID(container.getSubjectContext().get("formLayoutOID"));
container.setFormLayout(formLayout);
CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
container.setCrfVersion(crfVersion);
boolean isAnonymous = false;
if (container.getSubjectContext().get("studySubjectOID") == null)
isAnonymous = true;
// Create study event if it doesn't exist
if (isAnonymous)
processAnonymous(container, errors, studySubject, studyEventDefinition);
else
processParticipant(container, errors, studySubject, studyEventDefinition);
// TODO: May need to move this to a new processor that runs at the end
// Update the EventCrf and StudyEvent to the proper status.
// Don't do it in the initial save so it will have the expected audit trail entries.
Study study = null;
if (container.getSubjectContext().get("studyOID") != null)
study = studyDao.findByOcOID(container.getSubjectContext().get("studyOID"));
else
study = container.getStudy();
container.setEventCrf(updateEventCrf(container.getEventCrf(), study, studySubject, container.getUser(), isAnonymous));
container.setStudyEvent(updateStudyEvent(container.getStudyEvent(), studyEventDefinition, study, studySubject, container.getUser(), isAnonymous));
return ProcessorEnum.PROCEED;
}
use of org.akaza.openclinica.domain.datamap.FormLayout 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);
}
}
}
}
}
}
use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.
the class FormLayoutDao method findByOcOID.
public FormLayout findByOcOID(String OCOID) {
getSessionFactory().getStatistics().logSummary();
Query q = getCurrentSession().createQuery(findByOcIdQuery);
q.setParameter("OCOID", OCOID);
return (FormLayout) q.uniqueResult();
}
use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.
the class OpenRosaServices method getManifest.
/**
* @api {get} /rest2/openrosa/:studyOID/manifest Get Form Manifest
* @apiName getManifest
* @apiPermission admin
* @apiVersion 3.8.0
* @apiParam {String} studyOID Study Oid.
* @apiGroup Form
* @apiDescription Gets additional information on a particular Form, including links to associated media.
*/
@GET
@Path("/{studyOID}/manifest")
@Produces(MediaType.TEXT_XML)
public String getManifest(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formId") String uniqueId, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
if (!mayProceedPreview(studyOID))
return null;
String formLayoutOid = getFormLayoutOid(uniqueId);
FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOid);
Manifest manifest = new Manifest();
List<FormLayoutMedia> mediaList = formLayoutMediaDao.findByFormLayoutIdForNoteTypeMedia(formLayout.getFormLayoutId());
String urlBase = getCoreResources().getDataInfo().getProperty("sysURL").split("/MainMenu")[0];
if (mediaList != null && mediaList.size() > 0) {
for (FormLayoutMedia media : mediaList) {
MediaFile mediaFile = new MediaFile();
mediaFile.setFilename(media.getName());
File image = new File(Utils.getCrfMediaSysPath() + media.getPath() + media.getName());
mediaFile.setHash(DigestUtils.md5Hex(media.getName()) + Double.toString(image.length()));
mediaFile.setDownloadUrl(urlBase + "/rest2/openrosa/" + studyOID + "/downloadMedia?formLayoutMediaId=" + media.getFormLayoutMediaId());
manifest.add(mediaFile);
}
}
// Add user list
MediaFile userList = new MediaFile();
LinkedHashMap<String, Object> subjectContextCache = (LinkedHashMap<String, Object>) context.getAttribute("subjectContextCache");
if (subjectContextCache != null) {
String userXml = getUserXml(context);
userList.setHash((DigestUtils.md5Hex(userXml)));
}
userList.setFilename("users.xml");
userList.setDownloadUrl(urlBase + "/rest2/openrosa/" + studyOID + "/downloadUsers");
manifest.add(userList);
try {
// Create the XML manifest using a Castor mapping file.
XMLContext xmlContext = new XMLContext();
Mapping mapping = xmlContext.createMapping();
mapping.loadMapping(getCoreResources().getURL("openRosaManifestMapping.xml"));
xmlContext.addMapping(mapping);
Marshaller marshaller = xmlContext.createMarshaller();
StringWriter writer = new StringWriter();
marshaller.setWriter(writer);
marshaller.marshal(manifest);
// Set response headers
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
Date currentDate = new Date();
cal.setTime(currentDate);
SimpleDateFormat format = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss zz");
format.setCalendar(cal);
response.setHeader("Content-Type", "text/xml; charset=UTF-8");
response.setHeader("Date", format.format(currentDate));
response.setHeader("X-OpenRosa-Version", "1.0");
return writer.toString();
} catch (Exception e) {
LOGGER.error(e.getMessage());
LOGGER.error(ExceptionUtils.getStackTrace(e));
return "<Error>" + e.getMessage() + "</Error>";
}
}
Aggregations