Search in sources :

Example 6 with FullReportBean

use of org.akaza.openclinica.bean.extract.odm.FullReportBean in project OpenClinica by OpenClinica.

the class OdmFileCreation method createODMFile.

public HashMap<String, Integer> createODMFile(String odmVersion, long sysTimeBegin, String generalFileDir, DatasetBean datasetBean, StudyBean currentStudy, String generalFileDirCopy, ExtractBean eb, Integer currentStudyId, Integer parentStudyId, String studySubjectNumber, boolean zipped, boolean saveToDB, boolean deleteOld, String odmType, UserAccountBean userBean) {
    Integer ssNumber = getStudySubjectNumber(studySubjectNumber);
    MetaDataCollector mdc = new MetaDataCollector(dataSource, datasetBean, currentStudy, ruleSetRuleDao);
    AdminDataCollector adc = new AdminDataCollector(dataSource, datasetBean, currentStudy);
    ClinicalDataCollector cdc = new ClinicalDataCollector(dataSource, datasetBean, currentStudy);
    MetaDataCollector.setTextLength(200);
    if (deleteOld) {
        File file = new File(generalFileDir);
        if (file.isDirectory()) {
            files = file.listFiles();
            oldFiles = Arrays.asList(files);
        }
    }
    if (odmVersion != null) {
        // by default odmVersion is 1.2
        if ("1.3".equals(odmVersion)) {
            ODMBean odmb = new ODMBean();
            odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 ODM1-3-0.xsd");
            ArrayList<String> xmlnsList = new ArrayList<String>();
            xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.3\"");
            odmb.setXmlnsList(xmlnsList);
            odmb.setODMVersion("1.3");
            mdc.setODMBean(odmb);
            adc.setOdmbean(odmb);
            cdc.setODMBean(odmb);
        } else if ("oc1.2".equals(odmVersion)) {
            ODMBean odmb = new ODMBean();
            // odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.2 OpenClinica-ODM1-2-1.xsd");
            odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.2 OpenClinica-ODM1-2-1-OC1.xsd");
            ArrayList<String> xmlnsList = new ArrayList<String>();
            xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.2\"");
            // xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/openclinica_odm/v1.2\"");
            xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/odm_ext_v121/v3.1\"");
            xmlnsList.add("xmlns:OpenClinicaRules=\"http://www.openclinica.org/ns/rules/v3.1\"");
            odmb.setXmlnsList(xmlnsList);
            odmb.setODMVersion("oc1.2");
            mdc.setODMBean(odmb);
            adc.setOdmbean(odmb);
            cdc.setODMBean(odmb);
        } else if ("oc1.3".equals(odmVersion)) {
            ODMBean odmb = mdc.getODMBean();
            // odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0.xsd");
            // odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0-OC1.xsd");
            odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0-OC2-0.xsd");
            ArrayList<String> xmlnsList = new ArrayList<String>();
            xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.3\"");
            // xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/openclinica_odm/v1.3\"");
            xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/odm_ext_v130/v3.1\"");
            xmlnsList.add("xmlns:OpenClinicaRules=\"http://www.openclinica.org/ns/rules/v3.1\"");
            odmb.setXmlnsList(xmlnsList);
            odmb.setODMVersion("oc1.3");
            odmb.setOdmType(odmType);
            mdc.setODMBean(odmb);
            adc.setOdmbean(odmb);
            cdc.setODMBean(odmb);
        }
    }
    // ////////////////////////////////////////
    // //////// MetaData Extraction //////////
    mdc.collectFileData();
    MetaDataReportBean metaReport = new MetaDataReportBean(mdc.getOdmStudyMap(), coreResources);
    metaReport.setODMVersion(odmVersion);
    metaReport.setOdmBean(mdc.getODMBean());
    metaReport.createChunkedOdmXml(Boolean.TRUE);
    long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
    String ODMXMLFileName = mdc.getODMBean().getFileOID() + ".xml";
    int fId = createFileK(ODMXMLFileName, generalFileDir, metaReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    if (!"".equals(generalFileDirCopy)) {
        int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, metaReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    }
    // ////////////////////////////////////////
    // //////// AdminData Extraction //////////
    adc.collectFileData();
    AdminDataReportBean adminReport = new AdminDataReportBean(adc.getOdmAdminDataMap());
    adminReport.setODMVersion(odmVersion);
    adminReport.setOdmBean(mdc.getODMBean());
    adminReport.createChunkedOdmXml(Boolean.TRUE);
    sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
    fId = createFileK(ODMXMLFileName, generalFileDir, adminReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    if (!"".equals(generalFileDirCopy)) {
        int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, adminReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    }
    // ////////////////////////////////////////
    // //////// ClinicalData Extraction ///////
    DatasetDAO dsdao = new DatasetDAO(dataSource);
    String sql = eb.getDataset().getSQLStatement();
    String st_sed_in = dsdao.parseSQLDataset(sql, true, true);
    String st_itemid_in = dsdao.parseSQLDataset(sql, false, true);
    int datasetItemStatusId = eb.getDataset().getDatasetItemStatus().getId();
    String ecStatusConstraint = dsdao.getECStatusConstraint(datasetItemStatusId);
    String itStatusConstraint = dsdao.getItemDataStatusConstraint(datasetItemStatusId);
    Iterator<OdmStudyBase> it = cdc.getStudyBaseMap().values().iterator();
    while (it.hasNext()) {
        JobTerminationMonitor.check();
        OdmStudyBase u = it.next();
        ArrayList newRows = dsdao.selectStudySubjects(u.getStudy().getId(), 0, st_sed_in, st_itemid_in, dsdao.genDatabaseDateConstraint(eb), ecStatusConstraint, itStatusConstraint);
        // /////////////
        int fromIndex = 0;
        boolean firstIteration = true;
        while (fromIndex < newRows.size()) {
            JobTerminationMonitor.check();
            int toIndex = fromIndex + ssNumber < newRows.size() ? fromIndex + ssNumber : newRows.size() - 1;
            List x = newRows.subList(fromIndex, toIndex + 1);
            fromIndex = toIndex + 1;
            String studySubjectIds = "";
            for (int i = 0; i < x.size(); i++) {
                StudySubjectBean sub = new StudySubjectBean();
                sub = (StudySubjectBean) x.get(i);
                studySubjectIds += "," + sub.getId();
            }
            // for
            studySubjectIds = studySubjectIds.replaceFirst(",", "");
            ClinicalDataUnit cdata = new ClinicalDataUnit(dataSource, datasetBean, cdc.getOdmbean(), u.getStudy(), cdc.getCategory(), studySubjectIds);
            cdata.setCategory(cdc.getCategory());
            cdata.collectOdmClinicalData();
            FullReportBean report = new FullReportBean();
            report.setClinicalData(cdata.getOdmClinicalData());
            report.setOdmStudyMap(mdc.getOdmStudyMap());
            report.setODMVersion(odmVersion);
            // report.setOdmStudy(mdc.getOdmStudy());
            report.setOdmBean(mdc.getODMBean());
            if (firstIteration && fromIndex >= newRows.size()) {
                report.createChunkedOdmXml(Boolean.TRUE, true, true);
                firstIteration = false;
            } else if (firstIteration) {
                report.createChunkedOdmXml(Boolean.TRUE, true, false);
                firstIteration = false;
            } else if (fromIndex >= newRows.size()) {
                report.createChunkedOdmXml(Boolean.TRUE, false, true);
            } else {
                report.createChunkedOdmXml(Boolean.TRUE, false, false);
            }
            fId = createFileK(ODMXMLFileName, generalFileDir, report.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
            if (!"".equals(generalFileDirCopy)) {
                int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, report.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
            }
        }
    }
    sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
    fId = createFileK(ODMXMLFileName, generalFileDir, "</ODM>", datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, saveToDB, zipped, deleteOld, userBean);
    if (!"".equals(generalFileDirCopy)) {
        int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, "</ODM>", datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    }
    // ////////////////////////////////////////
    // //////// pre pagination extraction /////
    /*
        mdc.collectFileData();
        adc.collectOdmAdminDataMap();
        cdc.collectOdmClinicalDataMap();
        FullReportBean report = new FullReportBean();
        report.setClinicalDataMap(cdc.getOdmClinicalDataMap());
        report.setAdminDataMap(adc.getOdmAdminDataMap());
        report.setOdmStudyMap(mdc.getOdmStudyMap());
        report.setOdmBean(mdc.getODMBean());
        report.setODMVersion(odmVersion);
        report.createOdmXml(Boolean.TRUE);
        long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
        String ODMXMLFileName = mdc.getODMBean().getFileOID() + ".xml";
        int fId = this.createFile(ODMXMLFileName, generalFileDir, report.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, true);
        if (!"".equals(generalFileDirCopy)) {
            int fId2 = this.createFile(ODMXMLFileName, generalFileDirCopy, report.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false);
        } */
    HashMap answerMap = new HashMap<String, Integer>();
    // JN: Zipped in the next stage as thats where the ODM file is named and copied over in default categories.
    // if(zipped)
    // { try {
    // zipFile(ODMXMLFileName,generalFileDir);
    // 
    // } catch (IOException e) {
    // // TODO Auto-generated catch block
    // logger.error(e.getMessage());
    // e.printStackTrace();
    // }
    // 
    // }   // return ODMXMLFileName;
    answerMap.put(ODMXMLFileName, new Integer(fId));
    return answerMap;
}
Also used : ClinicalDataCollector(org.akaza.openclinica.logic.odmExport.ClinicalDataCollector) ClinicalDataUnit(org.akaza.openclinica.logic.odmExport.ClinicalDataUnit) HashMap(java.util.HashMap) AdminDataCollector(org.akaza.openclinica.logic.odmExport.AdminDataCollector) ArrayList(java.util.ArrayList) OdmStudyBase(org.akaza.openclinica.logic.odmExport.OdmStudyBase) MetaDataReportBean(org.akaza.openclinica.bean.extract.odm.MetaDataReportBean) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) FullReportBean(org.akaza.openclinica.bean.extract.odm.FullReportBean) AdminDataReportBean(org.akaza.openclinica.bean.extract.odm.AdminDataReportBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ODMBean(org.akaza.openclinica.bean.odmbeans.ODMBean) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MetaDataCollector(org.akaza.openclinica.logic.odmExport.MetaDataCollector) File(java.io.File)

Example 7 with FullReportBean

use of org.akaza.openclinica.bean.extract.odm.FullReportBean in project OpenClinica by OpenClinica.

the class ODMClinicaDataResource method getODMMetadata.

/**
 * @api {get} /rest/clinicaldata/xml/view/:study/:subject/:event/:form Retrieve case report forms - XML
 * @apiVersion 3.8.0
 * @apiName getODMMetadata
 * @apiGroup Subject
 * @apiPermission user
 *
 * @apiDescription Annotated case report forms in printable HTML format. Use asterisks in place of OIDs as wildcards
 *
 * @apiParam {String} study Study or Site OID.
 * @apiParam {String} subject Subject Key or ID.
 * @apiParam {String} event Study Event Definition OID. Use '*' for all.
 * @apiParam {String} form Case Report Form Version OID. Use '*' for all.
 *
 * @apiError NoAccessRight Only authenticated users can access the data.
 * @apiError NotFound   The resource was not found.
 *
 * @apiErrorExample Response (example):
 *     HTTP/1.1 401 Not Authenticated
 *     {
 *       "error": "NoAccessRight"
 *     }
 */
@GET
@Path("/xml/view/{studyOID}/{studySubjectIdentifier}/{studyEventOID}/{formVersionOID}")
@Produces(MediaType.TEXT_XML)
public String getODMMetadata(@PathParam("studyOID") String studyOID, @PathParam("formVersionOID") String formVersionOID, @PathParam("studySubjectIdentifier") String studySubjectIdentifier, @PathParam("studyEventOID") String studyEventOID, @DefaultValue("n") @QueryParam("includeDNs") String includeDns, @DefaultValue("n") @QueryParam("includeAudits") String includeAudits, @Context HttpServletRequest request) {
    LOGGER.debug("Requesting clinical data resource");
    boolean includeDN = false;
    boolean includeAudit = false;
    int userId = ((UserAccountBean) request.getSession().getAttribute("userBean")).getId();
    if (includeDns.equalsIgnoreCase("no") || includeDns.equalsIgnoreCase("n"))
        includeDN = false;
    if (includeAudits.equalsIgnoreCase("no") || includeAudits.equalsIgnoreCase("n"))
        includeAudit = false;
    if (includeDns.equalsIgnoreCase("yes") || includeDns.equalsIgnoreCase("y"))
        includeDN = true;
    if (includeAudits.equalsIgnoreCase("yes") || includeAudits.equalsIgnoreCase("y"))
        includeAudit = true;
    FullReportBean report = getMetadataCollectorResource().collectODMMetadataForClinicalData(studyOID, formVersionOID, getClinicalDataCollectorResource().generateClinicalData(studyOID, getStudySubjectOID(studySubjectIdentifier, studyOID), studyEventOID, formVersionOID, includeDN, includeAudit, request.getLocale(), userId));
    report.createOdmXml(true);
    LOGGER.debug(report.getXmlOutput().toString().trim());
    return report.getXmlOutput().toString().trim();
}
Also used : UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) FullReportBean(org.akaza.openclinica.bean.extract.odm.FullReportBean) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with FullReportBean

use of org.akaza.openclinica.bean.extract.odm.FullReportBean in project OpenClinica by OpenClinica.

the class ODMClinicaDataResource method getODMClinicaldata.

/**
 * @api {get} /rest/clinicaldata/json/view/:study/:subject/:event/:form Retrieve case report forms - JSON
 * @apiVersion 3.8.0
 * @apiName getODMClinicaldataJSON
 * @apiGroup Subject
 * @apiPermission user
 *
 * @apiDescription Annotated case report forms in printable HTML format. Use asterisks in place of OIDs as wildcards
 *
 * @apiParam {String} study Study or Site OID.
 * @apiParam {String} subject Subject Key or ID.
 * @apiParam {String} event Study Event Definition OID. Use '*' for all.
 * @apiParam {String} form Case Report Form Version OID. Use '*' for all.
 *
 * @apiError NoAccessRight Only authenticated users can access the data.
 * @apiError NotFound   The resource was not found.
 */
@GET
@Path("/json/view/{studyOID}/{studySubjectIdentifier}/{studyEventOID}/{formVersionOID}")
@Produces(MediaType.APPLICATION_JSON)
public String getODMClinicaldata(@PathParam("studyOID") String studyOID, @PathParam("formVersionOID") String formVersionOID, @PathParam("studyEventOID") String studyEventOID, @PathParam("studySubjectIdentifier") String studySubjectIdentifier, @DefaultValue("n") @QueryParam("includeDNs") String includeDns, @DefaultValue("n") @QueryParam("includeAudits") String includeAudits, @Context HttpServletRequest request) {
    LOGGER.debug("Requesting clinical data resource");
    boolean includeDN = false;
    boolean includeAudit = false;
    if (includeDns.equalsIgnoreCase("no") || includeDns.equalsIgnoreCase("n"))
        includeDN = false;
    if (includeAudits.equalsIgnoreCase("no") || includeAudits.equalsIgnoreCase("n"))
        includeAudit = false;
    if (includeDns.equalsIgnoreCase("yes") || includeDns.equalsIgnoreCase("y"))
        includeDN = true;
    if (includeAudits.equalsIgnoreCase("yes") || includeAudits.equalsIgnoreCase("y"))
        includeAudit = true;
    int userId = ((UserAccountBean) request.getSession().getAttribute("userBean")).getId();
    XMLSerializer xmlSerializer = new XMLSerializer();
    FullReportBean report = getMetadataCollectorResource().collectODMMetadataForClinicalData(studyOID, formVersionOID, getClinicalDataCollectorResource().generateClinicalData(studyOID, getStudySubjectOID(studySubjectIdentifier, studyOID), studyEventOID, formVersionOID, includeDN, includeAudit, request.getLocale(), userId));
    if (report.getClinicalDataMap() == null)
        return null;
    report.createOdmXml(true);
    // xmlSerializer.setForceTopLevelObject(true);
    xmlSerializer.setTypeHintsEnabled(true);
    JSON json = xmlSerializer.read(report.getXmlOutput().toString().trim());
    JSONClinicalDataPostProcessor processor = new JSONClinicalDataPostProcessor(request.getLocale());
    processor.process((JSONObject) json);
    return json.toString(INDENT_LEVEL);
}
Also used : XMLSerializer(net.sf.json.xml.XMLSerializer) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) JSON(net.sf.json.JSON) FullReportBean(org.akaza.openclinica.bean.extract.odm.FullReportBean) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with FullReportBean

use of org.akaza.openclinica.bean.extract.odm.FullReportBean in project OpenClinica by OpenClinica.

the class MetadataCollectorResource method collectODMMetadataForClinicalData.

public FullReportBean collectODMMetadataForClinicalData(String studyOID, String formVersionOID, LinkedHashMap<String, OdmClinicalDataBean> clinicalDataMap) {
    StudyBean studyBean = getStudyDao().findByOid(studyOID);
    if (studyBean != null)
        studyBean = populateStudyBean(studyBean);
    MetaDataCollector mdc = new MetaDataCollector(this.dataSource, studyBean, getRuleSetRuleDao());
    AdminDataCollector adc = new AdminDataCollector(this.dataSource, studyBean);
    MetaDataCollector.setTextLength(200);
    ODMBean odmb = mdc.getODMBean();
    odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0-OC2-0.xsd");
    ArrayList<String> xmlnsList = new ArrayList<String>();
    xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.3\"");
    // xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/openclinica_odm/v1.3\"");
    xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/odm_ext_v130/v3.1\"");
    xmlnsList.add("xmlns:OpenClinicaRules=\"http://www.openclinica.org/ns/rules/v3.1\"");
    odmb.setXmlnsList(xmlnsList);
    odmb.setODMVersion("oc1.3");
    mdc.setODMBean(odmb);
    adc.setOdmbean(odmb);
    if (studyBean == null)
        mdc.collectFileData(formVersionOID);
    else
        mdc.collectFileData();
    adc.collectFileData();
    FullReportBean report = new FullReportBean();
    report.setAdminDataMap(adc.getOdmAdminDataMap());
    report.setOdmStudyMap(mdc.getOdmStudyMap());
    report.setCoreResources(getCoreResources());
    report.setOdmBean(mdc.getODMBean());
    // report.setClinicalData(odmClinicalDataBean);
    report.setClinicalDataMap(clinicalDataMap);
    report.setODMVersion("oc1.3");
    return report;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) AdminDataCollector(org.akaza.openclinica.logic.odmExport.AdminDataCollector) ArrayList(java.util.ArrayList) ODMBean(org.akaza.openclinica.bean.odmbeans.ODMBean) MetaDataCollector(org.akaza.openclinica.logic.odmExport.MetaDataCollector) FullReportBean(org.akaza.openclinica.bean.extract.odm.FullReportBean)

Aggregations

FullReportBean (org.akaza.openclinica.bean.extract.odm.FullReportBean)9 ArrayList (java.util.ArrayList)7 ODMBean (org.akaza.openclinica.bean.odmbeans.ODMBean)7 AdminDataCollector (org.akaza.openclinica.logic.odmExport.AdminDataCollector)7 MetaDataCollector (org.akaza.openclinica.logic.odmExport.MetaDataCollector)7 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)4 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AdminDataReportBean (org.akaza.openclinica.bean.extract.odm.AdminDataReportBean)2 MetaDataReportBean (org.akaza.openclinica.bean.extract.odm.MetaDataReportBean)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Locale (java.util.Locale)1 JSON (net.sf.json.JSON)1 XMLSerializer (net.sf.json.xml.XMLSerializer)1