use of org.akaza.openclinica.domain.datamap.CrfBean 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.CrfBean in project OpenClinica by OpenClinica.
the class GenerateClinicalDataServiceImpl method listOfHiddenCrfs.
private List<CrfBean> listOfHiddenCrfs(Integer siteId, Integer parentStudyId, List<EventDefinitionCrf> edcs, EventCrf ecrf) {
boolean found = false;
int crfId = ecrf.getCrfVersion().getCrf().getCrfId();
List<CrfBean> hiddenCrfs = new ArrayList<CrfBean>();
LOGGER.info("The study subject is at the site/study " + siteId);
for (EventDefinitionCrf eventDefCrf : edcs) {
if (eventDefCrf.getCrf().getCrfId() == crfId && eventDefCrf.getStudy().getStudyId() == siteId) {
found = true;
if (eventDefCrf.getHideCrf()) {
hiddenCrfs.add(eventDefCrf.getCrf());
}
}
}
if (!found) {
for (EventDefinitionCrf eventDefCrf : edcs) {
if (eventDefCrf.getCrf().getCrfId() == crfId && eventDefCrf.getStudy().getStudyId() == parentStudyId && eventDefCrf.getHideCrf()) {
hiddenCrfs.add(eventDefCrf.getCrf());
}
}
}
return hiddenCrfs;
}
use of org.akaza.openclinica.domain.datamap.CrfBean in project OpenClinica by OpenClinica.
the class CreateXformCRFVersionServlet method processRequest.
// public final String FM_BASEURL = "http://oc.local:8090/api/protocol/";
@Override
protected void processRequest() throws Exception {
CrfDao crfDao = (CrfDao) SpringServletAccess.getApplicationContext(context).getBean("crfDao");
XformMetaDataService xformService = (XformMetaDataService) SpringServletAccess.getApplicationContext(context).getBean("xformService");
Locale locale = LocaleResolver.getLocale(request);
ResourceBundleProvider.updateLocale(locale);
resword = ResourceBundleProvider.getWordsBundle(locale);
// Retrieve submission data from multipart request
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);
String crfName = retrieveFormFieldValue(items, "crfName");
DataBinder dataBinder = new DataBinder(new FormVersion());
Errors errors = dataBinder.getBindingResult();
int crfId = Integer.valueOf(retrieveFormFieldValue(items, "crfId"));
if (crfId != 0) {
CrfBean crfBean = crfDao.findByCrfId(crfId);
crfName = crfBean.getName();
}
FormArtifactTransferObj transferObj = getFormArtifactsFromFM(items, currentStudy.getOid(), crfName);
if (transferObj.getErr().size() != 0) {
for (ErrorObj er : transferObj.getErr()) {
errors.rejectValue("name", er.getCode(), er.getMessage());
}
} else {
List<OCodmComplexTypeDefinitionFormLayoutDef> formLayoutDefs = new ArrayList<>();
OCodmComplexTypeDefinitionFormLayoutDef formLayoutDef;
for (FormVersion version : transferObj.getForm().getVersions()) {
formLayoutDef = new OCodmComplexTypeDefinitionFormLayoutDef();
formLayoutDef.setOID(version.getName());
formLayoutDef.setURL(version.getArtifactURL());
formLayoutDefs.add(formLayoutDef);
}
ExecuteIndividualCrfObject eicObj = new ExecuteIndividualCrfObject(transferObj.getForm(), formLayoutDefs, errors, currentStudy, ub, false, null);
xformService.executeIndividualCrf(eicObj);
}
if (errors.hasErrors()) {
request.setAttribute("errorList", errors.getAllErrors());
}
forwardPage(Page.CREATE_XFORM_CRF_VERSION_SERVLET);
}
use of org.akaza.openclinica.domain.datamap.CrfBean in project OpenClinica by OpenClinica.
the class OpenRosaServices method getFormXml.
/**
* @api {get} /rest2/openrosa/:studyOID/formXml Get Form XML
* @apiName getFormXml
* @apiPermission admin
* @apiVersion 3.8.0
* @apiParam {String} studyOID Study Oid.
* @apiGroup Form
* @apiDescription Downloads the contents of a form
*/
@GET
@Path("/{studyOID}/formXml")
@Produces(MediaType.APPLICATION_XML)
public String getFormXml(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formId") String uniqueId, @RequestHeader("Authorization") String authorization) throws Exception {
if (!mayProceedPreview(studyOID))
return null;
String xform = null;
// get parameters
String formId = request.getParameter("formId");
if (formId == null) {
return "<error>formID is null :(</error>";
}
String flavor = getQuerySet(uniqueId);
String formLayoutOid = getFormLayoutOid(uniqueId);
FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOid);
CrfBean crf = formLayout.getCrf();
String xformOutput = "";
String directoryPath = Utils.getCrfMediaFilePath(crf.getOcOid(), formLayout.getOcOid());
File dir = new File(directoryPath);
File[] directoryListing = dir.listFiles();
if (directoryListing != null) {
for (File child : directoryListing) {
if (flavor.equals(QUERY_FLAVOR) && child.getName().endsWith(QUERY_SUFFIX) || flavor.equals(NO_FLAVOR) && child.getName().endsWith(NO_SUFFIX)) {
xformOutput = new String(Files.readAllBytes(Paths.get(child.getPath())));
break;
}
}
}
try {
if (StringUtils.isNotEmpty(xformOutput)) {
xform = xformOutput;
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
LOGGER.error(ExceptionUtils.getStackTrace(e));
return "<error>" + e.getMessage() + "</error>";
}
response.setHeader("Content-Type", "text/xml; charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=\"" + formId + ".xml" + "\";");
response.setContentType("text/xml; charset=utf-8");
return xform;
}
Aggregations