Example usage for org.apache.poi.hssf.usermodel HSSFCell setCellValue

List of usage examples for org.apache.poi.hssf.usermodel HSSFCell setCellValue

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFCell setCellValue.

Prototype

@SuppressWarnings("fallthrough")
public void setCellValue(boolean value) 

Source Link

Document

set a boolean value for the cell

Usage

From source file:gov.nih.nci.caBIOApp.report.HSSFExcelRow.java

License:BSD License

public Cell createCell(String s) {
    if (_row == null) {
        throw new IllegalStateException("row has not been set");
    }//from   w  w  w  . ja v  a 2s .  c o  m
    int numCells = getNumCells();
    short newCellNum = (short) (numCells);
    MessageLog.printInfo("HSSFExcelRow.createCell(): newCellNum = " + newCellNum);
    HSSFCell hc = _row.createCell(newCellNum);
    hc.setCellValue(s);
    return new HSSFExcelCell(hc);
}

From source file:gov.nih.nci.caBIOApp.report.HSSFExcelRow.java

License:BSD License

Cell createCell(int idx, String s) {
    HSSFCell hc = _row.createCell((short) idx);
    hc.setCellValue(s);
    return new HSSFExcelCell(hc);
}

From source file:gov.nih.nci.caBIOApp.report.HSSFExcelRow.java

License:BSD License

public void addCell(Cell c) {
    if (_row == null) {
        throw new IllegalStateException("row has not been set");
    }//from   www.  j ava2  s . co m
    int numCells = getNumCells();
    short newCellNum = (short) (numCells);
    HSSFCell hc = _row.createCell(newCellNum);
    hc.setCellValue((String) c.getCellValue());
}

From source file:gov.nih.nci.caintegrator.application.report.LevelOfExpressionIHCReport.java

License:BSD License

public static HSSFWorkbook getReportExcel(Finding finding, HashMap map) {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet(finding.getTaskId());

    ArrayList dFindings = new ArrayList(finding.getDomainFindings());
    ArrayList<LevelOfExpressionIHCFinding> domainFindings = new ArrayList<LevelOfExpressionIHCFinding>(
            dFindings);//from w  w  w  .j  ava 2 s . co  m
    ArrayList<LevelOfExpressionIHCFindingReportBean> results = new ArrayList<LevelOfExpressionIHCFindingReportBean>();
    for (LevelOfExpressionIHCFinding loef : domainFindings) {
        LevelOfExpressionIHCFindingReportBean reportBean = new LevelOfExpressionIHCFindingReportBean(loef);
        results.add(reportBean);
    }
    LevelOfExpressionIHCFindingCriteria criteria = (LevelOfExpressionIHCFindingCriteria) finding.getQueryDTO();

    if (!results.isEmpty()) {

        //SORT THE ARRAYLIST(RESULTS) BY PATIENT DID
        PatientComparator p = new PatientComparator();
        Collections.sort(results, p);

        //CREATE A HASHMAP SORTED BY PATIENT DID AS THE KEY AND THE ARRAYLIST OF REPORTBEANS AS THE VALUE                

        Map<String, ArrayList<LevelOfExpressionIHCFindingReportBean>> reportBeanMap = new HashMap<String, ArrayList<LevelOfExpressionIHCFindingReportBean>>();

        for (int i = 0; i < results.size(); i++) {
            if (i == 0) {
                reportBeanMap.put(
                        results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(),
                        new ArrayList<LevelOfExpressionIHCFindingReportBean>());
                reportBeanMap
                        .get(results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName())
                        .add(results.get(i));
            } else if (!results.get(i).getSpecimenIdentifier()
                    .equalsIgnoreCase(results.get(i - 1).getSpecimenIdentifier())) {
                reportBeanMap.put(
                        results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(),
                        new ArrayList<LevelOfExpressionIHCFindingReportBean>());
                reportBeanMap
                        .get(results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName())
                        .add(results.get(i));
            } else if (results.get(i).getSpecimenIdentifier()
                    .equalsIgnoreCase(results.get(i - 1).getSpecimenIdentifier())
                    && !results.get(i).getBiomarkerName()
                            .equalsIgnoreCase(results.get(i - 1).getBiomarkerName())) {
                reportBeanMap.put(
                        results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(),
                        new ArrayList<LevelOfExpressionIHCFindingReportBean>());
                reportBeanMap
                        .get(results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName())
                        .add(results.get(i));
            } else {
                reportBeanMap.get(results.get(i - 1).getSpecimenIdentifier() + "_"
                        + results.get(i - 1).getBiomarkerName()).add(results.get(i));
            }
        }

        //IF THE USER SELECTED TIMEPOINTS FOR WHICH THAT PATIENT DID DID NOT HAVE DATA, CREATE NULL BEANS SO AS TO RENDER A READABLE REPORT
        Set<String> b = reportBeanMap.keySet();
        for (String g : b) {
            while (reportBeanMap.get(g)
                    .size() < (reportBeanMap.get(g).get(0).getTimepointHeaders(criteria).size())) {
                reportBeanMap.get(g)
                        .add(new LevelOfExpressionIHCFindingReportBean(new LevelOfExpressionIHCFinding()));
            }
        }

        ArrayList<String> ntpHeaders = results.get(0).getNonTimepointHeaders();
        HSSFRow row = sheet.createRow((short) 0);

        //ADD HEADERS THAT ARE TIMEPOINT DEPENDENT
        ArrayList<String> headers = results.get(0).getHeaders();
        ArrayList<String> tpHeaders = results.get(0).getTimepointHeaders(criteria);
        TimepointStringComparator ts = new TimepointStringComparator();
        Collections.sort(tpHeaders, ts);
        ArrayList<String> combinedHeaders = new ArrayList<String>();
        for (int i = 0; i < headers.size(); i++) {
            for (int j = 0; j < tpHeaders.size(); j++) {
                combinedHeaders.add(headers.get(i) + tpHeaders.get(j));
            }
        }

        ntpHeaders.addAll(combinedHeaders);

        for (int i = 0; i < ntpHeaders.size(); i++) {
            HSSFCell cell = row.createCell((short) i);
            cell.setCellValue(ntpHeaders.get(i));
        }

        row = null;
        HSSFCell dataCell = null;
        Set<String> keysSet = reportBeanMap.keySet();
        ArrayList<String> keys = new ArrayList<String>(keysSet);
        int u = 0;
        // ADD DATA ROWS           
        for (int i = 0; i < keys.size(); i++) {
            String tp = reportBeanMap.get(keys.get(i)).get(0).getTimepoint();
            Collection<String> localizationCollection = criteria.getStainLocalizationCollection();
            Collection<String> intensityCollection = criteria.getStainIntensityCollection();

            String localization = reportBeanMap.get(keys.get(i)).get(0).getStainLocalization();
            String intensity = reportBeanMap.get(keys.get(i)).get(0).getStainIntensity();

            if (tpHeaders.contains(tp) && (localizationCollection == null
                    || (localizationCollection != null && localizationCollection.contains(localization)))
                    && (intensityCollection == null
                            || (intensityCollection != null && intensityCollection.contains(intensity)))) {

                sheet.createFreezePane(0, 1, 0, 1);
                row = sheet.createRow((short) u + 1);
                dataCell = row.createCell((short) 0);
                dataCell.setCellValue(reportBeanMap.get(keys.get(i)).get(0).getPatientDID());

                dataCell = row.createCell((short) 1);
                dataCell.setCellValue(reportBeanMap.get(keys.get(i)).get(0).getBiomarkerName());

                //GRAB EACH REPORT BEAN IN EACH ARRAYLIST AND MATCH UP TO THE APPROPRIATE TIMEPOINT AS A MAP WITH THE TIMEPOINT AS KEY AND REPORTBEAN THE VALUE
                ArrayList<LevelOfExpressionIHCFindingReportBean> myList = reportBeanMap.get(keys.get(i));
                Map<String, LevelOfExpressionIHCFindingReportBean> myMap = new HashMap<String, LevelOfExpressionIHCFindingReportBean>();
                ArrayList<LevelOfExpressionIHCFindingReportBean> mySortedMap = new ArrayList<LevelOfExpressionIHCFindingReportBean>();

                for (LevelOfExpressionIHCFindingReportBean ggg : myList) {
                    for (int j = 0; j < tpHeaders.size(); j++) {
                        if (ggg.getTimepoint().equalsIgnoreCase(tpHeaders.get(j))) {
                            myMap.put(tpHeaders.get(j), ggg);
                            break;
                        } else if (ggg.getTimepoint().equals("--")) {
                            if (!myMap.containsKey(tpHeaders.get(j))) {
                                myMap.put(tpHeaders.get(j), ggg);
                                break;
                            }
                        }
                    }
                }

                //SORT MAP BY TIMEPOINT SO THAT THE REPORT BEAN DATA CAN EASILY BE DISPLAYED UNDER THE APPROPRIATE TIEMPOINT
                for (int t = 0; t < tpHeaders.size(); t++) {
                    for (String k : myMap.keySet()) {
                        if (k.equalsIgnoreCase(tpHeaders.get(t))) {
                            mySortedMap.add(myMap.get(k));
                        }
                    }
                }

                int counter = 2;
                //ITERATE OVER THE MAP FOR EACH DATA FIELD WITH ITS CORRESPONDING TIMEPOINT AND BUILD DATA ROWS
                for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getPercentPositive());
                }
                for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getStainIntensity());
                }
                for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getStainLocalization());
                }
                for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getInvasivePresentation());
                }
                for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getOverallExpression());
                }
                u++;

            }
        }

    }

    else {
        //TODO: handle this error

    }

    return wb;
}

From source file:gov.nih.nci.caintegrator.application.report.LossOfExpressionIHCReport.java

License:BSD License

public static HSSFWorkbook getReportExcel(Finding finding, HashMap map) {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet(finding.getTaskId());

    ArrayList dFindings = new ArrayList(finding.getDomainFindings());
    ArrayList<LossOfExpressionIHCFinding> domainFindings = new ArrayList<LossOfExpressionIHCFinding>(dFindings);
    ArrayList<LossOfExpressionIHCFindingReportBean> results = new ArrayList<LossOfExpressionIHCFindingReportBean>();
    for (LossOfExpressionIHCFinding loef : domainFindings) {
        LossOfExpressionIHCFindingReportBean reportBean = new LossOfExpressionIHCFindingReportBean(loef);
        results.add(reportBean);//from ww  w . j a va 2s  .c o  m
    }
    LossOfExpressionIHCFindingCriteria criteria = (LossOfExpressionIHCFindingCriteria) finding.getQueryDTO();

    if (!results.isEmpty()) {

        //SORT THE ARRAYLIST(RESULTS) BY PATIENT DID
        PatientComparator p = new PatientComparator();
        Collections.sort(results, p);

        //CREATE A HASHMAP SORTED BY PATIENT DID AS THE KEY AND THE ARRAYLIST OF REPORTBEANS AS THE VALUE                

        Map<String, ArrayList<LossOfExpressionIHCFindingReportBean>> reportBeanMap = new HashMap<String, ArrayList<LossOfExpressionIHCFindingReportBean>>();

        for (int i = 0; i < results.size(); i++) {
            if (i == 0) {
                reportBeanMap.put(
                        results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(),
                        new ArrayList<LossOfExpressionIHCFindingReportBean>());
                reportBeanMap
                        .get(results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName())
                        .add(results.get(i));
            } else if (!results.get(i).getSpecimenIdentifier()
                    .equalsIgnoreCase(results.get(i - 1).getSpecimenIdentifier())) {
                reportBeanMap.put(
                        results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(),
                        new ArrayList<LossOfExpressionIHCFindingReportBean>());
                reportBeanMap
                        .get(results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName())
                        .add(results.get(i));
            } else if (results.get(i).getSpecimenIdentifier()
                    .equalsIgnoreCase(results.get(i - 1).getSpecimenIdentifier())
                    && !results.get(i).getBiomarkerName()
                            .equalsIgnoreCase(results.get(i - 1).getBiomarkerName())) {
                reportBeanMap.put(
                        results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(),
                        new ArrayList<LossOfExpressionIHCFindingReportBean>());
                reportBeanMap
                        .get(results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName())
                        .add(results.get(i));
            } else {
                reportBeanMap.get(results.get(i - 1).getSpecimenIdentifier() + "_"
                        + results.get(i - 1).getBiomarkerName()).add(results.get(i));
            }
        }

        //IF THE USER SELECTED TIMEPOINTS FOR WHICH THAT PATIENT DID DID NOT HAVE DATA, CREATE NULL BEANS SO AS TO RENDER A READABLE REPORT
        Set<String> b = reportBeanMap.keySet();
        for (String g : b) {
            while (reportBeanMap.get(g)
                    .size() < (reportBeanMap.get(g).get(0).getTimepointHeaders(criteria).size())) {
                reportBeanMap.get(g)
                        .add(new LossOfExpressionIHCFindingReportBean(new LossOfExpressionIHCFinding()));
            }
        }

        ArrayList<String> ntpHeaders = results.get(0).getNonTimepointHeaders();
        HSSFRow row = sheet.createRow((short) 0);

        //ADD HEADERS THAT ARE TIMEPOINT DEPENDENT
        ArrayList<String> headers = results.get(0).getHeaders();
        ArrayList<String> tpHeaders = results.get(0).getTimepointHeaders(criteria);
        TimepointStringComparator ts = new TimepointStringComparator();
        Collections.sort(tpHeaders, ts);
        ArrayList<String> combinedHeaders = new ArrayList<String>();
        for (int i = 0; i < headers.size(); i++) {
            for (int j = 0; j < tpHeaders.size(); j++) {
                combinedHeaders.add(headers.get(i) + tpHeaders.get(j));
            }
        }

        ntpHeaders.addAll(combinedHeaders);

        for (int i = 0; i < ntpHeaders.size(); i++) {
            HSSFCell cell = row.createCell((short) i);
            cell.setCellValue(ntpHeaders.get(i));
        }

        row = null;
        HSSFCell dataCell = null;
        Set<String> keysSet = reportBeanMap.keySet();
        ArrayList<String> keys = new ArrayList<String>(keysSet);
        int u = 0;
        // ADD DATA ROWS           
        for (int i = 0; i < keys.size(); i++) {

            String tp = reportBeanMap.get(keys.get(i)).get(0).getTimepoint();

            Integer invasiveSumCrit = criteria.getInvasiveSum();
            String invasiveSumOpCrit = criteria.getInvasiveSumOperator();

            String invasiveSum = reportBeanMap.get(keys.get(i)).get(0).getInvasiveSum();
            String invasiveSumOp = reportBeanMap.get(keys.get(i)).get(0).getInvasiveSumOperator();

            int q = 0;

            if (invasiveSumCrit != null && invasiveSumOpCrit != null) {
                q = new Integer(invasiveSum).compareTo(invasiveSumCrit);
            }

            Integer benignSumCrit = criteria.getBenignSum();
            String benignSumOpCrit = criteria.getBenignSumOperator();

            String benignSum = reportBeanMap.get(keys.get(i)).get(0).getBenignSum();
            String benignSumOp = reportBeanMap.get(keys.get(i)).get(0).getBenignSumOperator();

            int h = 0;

            if (benignSumCrit != null && benignSumOpCrit != null) {
                h = new Integer(benignSum).compareTo(benignSumCrit);
            }

            Collection<String> resultCodeCollection = criteria.getResultCodeCollection();
            String resultCode = reportBeanMap.get(keys.get(i)).get(0).getLossResult();

            // if(tpHeaders.contains(tp)) {                

            if (tpHeaders.contains(tp)
                    && (resultCodeCollection == null
                            || (resultCodeCollection != null && resultCodeCollection.contains(resultCode)))
                    && ((invasiveSumCrit == null && invasiveSumOpCrit == null)
                            || (invasiveSumCrit != null
                                    && (invasiveSumOpCrit != null && invasiveSumOpCrit.equals("="))
                                    && invasiveSumCrit.toString().equals(invasiveSum))
                            || (invasiveSumCrit != null
                                    && (invasiveSumOpCrit != null && invasiveSumOpCrit.equals(">=")) && q >= 0)
                            || (invasiveSumCrit != null
                                    && (invasiveSumOpCrit != null && invasiveSumOpCrit.equals("<=")) && q <= 0))
                    && ((benignSumCrit == null && benignSumOpCrit == null)
                            || (benignSumCrit != null
                                    && (benignSumOpCrit != null && benignSumOpCrit.equals("="))
                                    && benignSumCrit.toString().equals(benignSum))
                            || (benignSumCrit != null
                                    && (benignSumOpCrit != null && benignSumOpCrit.equals(">=")) && h >= 0)
                            || (benignSumCrit != null
                                    && (benignSumOpCrit != null && benignSumOpCrit.equals("<=")) && h <= 0))) {

                sheet.createFreezePane(0, 1, 0, 1);
                row = sheet.createRow((short) u + 1);
                dataCell = row.createCell((short) 0);
                dataCell.setCellValue(reportBeanMap.get(keys.get(i)).get(0).getPatientDID());

                dataCell = row.createCell((short) 1);
                dataCell.setCellValue(reportBeanMap.get(keys.get(i)).get(0).getBiomarkerName());

                //GRAB EACH REPORT BEAN IN EACH ARRAYLIST AND MATCH UP TO THE APPROPRIATE TIMEPOINT AS A MAP WITH THE TIMEPOINT AS KEY AND REPORTBEAN THE VALUE
                ArrayList<LossOfExpressionIHCFindingReportBean> myList = reportBeanMap.get(keys.get(i));
                Map<String, LossOfExpressionIHCFindingReportBean> myMap = new HashMap<String, LossOfExpressionIHCFindingReportBean>();
                ArrayList<LossOfExpressionIHCFindingReportBean> mySortedMap = new ArrayList<LossOfExpressionIHCFindingReportBean>();

                for (LossOfExpressionIHCFindingReportBean ggg : myList) {
                    for (int j = 0; j < tpHeaders.size(); j++) {
                        if (ggg.getTimepoint().equalsIgnoreCase(tpHeaders.get(j))) {
                            myMap.put(tpHeaders.get(j), ggg);
                            break;
                        } else if (ggg.getTimepoint().equals("--")) {
                            if (!myMap.containsKey(tpHeaders.get(j))) {
                                myMap.put(tpHeaders.get(j), ggg);
                                break;
                            }
                        }
                    }
                }

                //SORT MAP BY TIMEPOINT SO THAT THE REPORT BEAN DATA CAN EASILY BE DISPLAYED UNDER THE APPROPRIATE TIEMPOINT
                for (int t = 0; t < tpHeaders.size(); t++) {
                    for (String k : myMap.keySet()) {
                        if (k.equalsIgnoreCase(tpHeaders.get(t))) {
                            mySortedMap.add(myMap.get(k));
                        }
                    }
                }

                int counter = 2;
                //ITERATE OVER THE MAP FOR EACH DATA FIELD WITH ITS CORRESPONDING TIMEPOINT AND BUILD DATA ROWS
                for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getBenignPresentValue());
                }
                for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    if (!reportBean.getInvasiveSum().equals("--")) {
                        dataCell.setCellValue(Short.parseShort(reportBean.getInvasiveSum()));
                    } else {
                        dataCell.setCellValue(reportBean.getInvasiveSum());
                    }
                }
                for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    if (!reportBean.getBenignSum().equals("--")) {
                        dataCell.setCellValue(Short.parseShort(reportBean.getBenignSum()));
                    } else {
                        dataCell.setCellValue(reportBean.getBenignSum());
                    }
                }
                for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    if (!reportBean.getInvasiveBenignDiff().equals("--")) {
                        dataCell.setCellValue(Short.parseShort(reportBean.getInvasiveBenignDiff()));
                    } else {
                        dataCell.setCellValue(reportBean.getInvasiveBenignDiff());
                    }
                }
                for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getComments());
                }
                for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getLossResult());
                }
                u++;
            }
        }

    }

    else {
        //TODO: handle this error

    }
    return wb;
}

From source file:gov.nih.nci.caintegrator.application.report.P53Report.java

License:BSD License

public static HSSFWorkbook getReportExcel(Finding finding, HashMap map) {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet(finding.getTaskId());

    ArrayList dFindings = new ArrayList(finding.getDomainFindings());
    ArrayList<P53MutationFinding> domainFindings = new ArrayList<P53MutationFinding>(dFindings);
    ArrayList<P53FindingReportBean> results = new ArrayList<P53FindingReportBean>();
    for (P53MutationFinding p53f : domainFindings) {
        P53FindingReportBean reportBean = new P53FindingReportBean(p53f);
        results.add(reportBean);//w  w w.j  a v a2s  . c om
    }
    P53FindingCriteria criteria = (P53FindingCriteria) finding.getQueryDTO();

    if (!results.isEmpty()) {

        //SORT THE ARRAYLIST(RESULTS) BY PATIENT DID
        PatientComparator p = new PatientComparator();
        Collections.sort(results, p);

        //CREATE A HASHMAP SORTED BY PATIENT DID AS THE KEY AND THE ARRAYLIST OF REPORTBEANS AS THE VALUE                

        Map<String, ArrayList<P53FindingReportBean>> reportBeanMap = new HashMap<String, ArrayList<P53FindingReportBean>>();

        for (int i = 0; i < results.size(); i++) {
            if (i == 0) {
                reportBeanMap.put(results.get(i).getSpecimenIdentifier(),
                        new ArrayList<P53FindingReportBean>());
                reportBeanMap.get(results.get(i).getSpecimenIdentifier()).add(results.get(i));
            } else if (!results.get(i).getSpecimenIdentifier()
                    .equalsIgnoreCase(results.get(i - 1).getSpecimenIdentifier())) {
                reportBeanMap.put(results.get(i).getSpecimenIdentifier(),
                        new ArrayList<P53FindingReportBean>());
                reportBeanMap.get(results.get(i).getSpecimenIdentifier()).add(results.get(i));
            } else if (results.get(i).getSpecimenIdentifier()
                    .equalsIgnoreCase(results.get(i - 1).getSpecimenIdentifier())) {
                reportBeanMap.put(results.get(i).getSpecimenIdentifier(),
                        new ArrayList<P53FindingReportBean>());
                reportBeanMap.get(results.get(i).getSpecimenIdentifier()).add(results.get(i));
            } else {
                reportBeanMap.get(results.get(i - 1).getSpecimenIdentifier()).add(results.get(i));
            }
        }

        //IF THE USER SELECTED TIMEPOINTS FOR WHICH THAT PATIENT DID DID NOT HAVE DATA, CREATE NULL BEANS SO AS TO RENDER A READABLE REPORT
        Set<String> b = reportBeanMap.keySet();
        for (String g : b) {
            while (reportBeanMap.get(g)
                    .size() < (reportBeanMap.get(g).get(0).getTimepointHeaders(criteria).size())) {
                reportBeanMap.get(g).add(new P53FindingReportBean(new P53MutationFinding()));
            }
        }

        ArrayList<String> ntpHeaders = results.get(0).getNonTimepointHeaders();
        HSSFRow row = sheet.createRow((short) 0);

        //ADD HEADERS THAT ARE TIMEPOINT DEPENDENT
        ArrayList<String> headers = results.get(0).getHeaders();

        ArrayList<String> tpHeaders = results.get(0).getTimepointHeaders(criteria);
        TimepointStringComparator ts = new TimepointStringComparator();
        Collections.sort(tpHeaders, ts);
        ArrayList<String> combinedHeaders = new ArrayList<String>();
        for (int i = 0; i < headers.size(); i++) {
            for (int j = 0; j < tpHeaders.size(); j++) {
                combinedHeaders.add(headers.get(i) + tpHeaders.get(j));
            }
        }

        ntpHeaders.addAll(combinedHeaders);

        for (int i = 0; i < ntpHeaders.size(); i++) {
            HSSFCell cell = row.createCell((short) i);
            cell.setCellValue(ntpHeaders.get(i));
        }

        row = null;
        HSSFCell dataCell = null;
        Set<String> keysSet = reportBeanMap.keySet();
        ArrayList<String> keys = new ArrayList<String>(keysSet);
        int u = 0;
        // ADD DATA ROWS           
        for (int i = 0; i < keys.size(); i++) {
            String tp = reportBeanMap.get(keys.get(i)).get(0).getTimepoint();
            Collection<String> mutationStatusCollection = criteria.getMutationStatusCollection();
            Collection<String> mutationTypeCollection = criteria.getMutationTypeCollection();

            String mutationStatus = reportBeanMap.get(keys.get(i)).get(0).getMutationStatus();
            String mutationType = reportBeanMap.get(keys.get(i)).get(0).getMutationType();

            if (tpHeaders.contains(tp) && (mutationStatusCollection == null
                    || (mutationStatusCollection != null && mutationStatusCollection.contains(mutationStatus)))
                    && (mutationTypeCollection == null || (mutationTypeCollection != null
                            && mutationTypeCollection.contains(mutationType)))) {

                sheet.createFreezePane(0, 1, 0, 1);
                row = sheet.createRow((short) u + 1);
                dataCell = row.createCell((short) 0);
                dataCell.setCellValue(reportBeanMap.get(keys.get(i)).get(0).getPatientDID());

                dataCell = row.createCell((short) 1);
                dataCell.setCellValue(reportBeanMap.get(keys.get(i)).get(0).getSpecimenIdentifier());

                //GRAB EACH REPORT BEAN IN EACH ARRAYLIST AND MATCH UP TO THE APPROPRIATE TIMEPOINT AS A MAP WITH THE TIMEPOINT AS KEY AND REPORTBEAN THE VALUE
                ArrayList<P53FindingReportBean> myList = reportBeanMap.get(keys.get(i));
                Map<String, P53FindingReportBean> myMap = new HashMap<String, P53FindingReportBean>();
                ArrayList<P53FindingReportBean> mySortedMap = new ArrayList<P53FindingReportBean>();

                for (P53FindingReportBean ggg : myList) {
                    for (int j = 0; j < tpHeaders.size(); j++) {
                        if (ggg.getTimepoint().equalsIgnoreCase(tpHeaders.get(j))) {
                            myMap.put(tpHeaders.get(j), ggg);
                            break;
                        } else if (ggg.getTimepoint().equals("--")) {
                            if (!myMap.containsKey(tpHeaders.get(j))) {
                                myMap.put(tpHeaders.get(j), ggg);
                                break;
                            }
                        }
                    }
                }

                //SORT MAP BY TIMEPOINT SO THAT THE REPORT BEAN DATA CAN EASILY BE DISPLAYED UNDER THE APPROPRIATE TIEMPOINT
                for (int t = 0; t < tpHeaders.size(); t++) {
                    for (String k : myMap.keySet()) {
                        if (k.equalsIgnoreCase(tpHeaders.get(t))) {
                            mySortedMap.add(myMap.get(k));
                        }
                    }
                }

                int counter = 2;
                //ITERATE OVER THE MAP FOR EACH DATA FIELD WITH ITS CORRESPONDING TIMEPOINT AND BUILD DATA ROWS

                for (P53FindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getMutationStatus());
                }
                for (P53FindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getMutationType());
                }
                for (P53FindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getExonOrIntronLocation());
                }
                for (P53FindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getBaseChange());
                }
                for (P53FindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getCodonAminoacidChange());
                }
                for (P53FindingReportBean reportBean : mySortedMap) {
                    dataCell = row.createCell((short) counter++);
                    dataCell.setCellValue(reportBean.getProteinStructuralDomain());
                }
                u++;

            }
        }

    }

    else {
        //TODO: handle this error

    }

    return wb;
}

From source file:gov.nih.nci.cananolab.service.publication.impl.PublicationExporter.java

License:BSD License

private static int setDetailSheet(PublicationBean aPub, HSSFWorkbook wb, HSSFSheet sheet,
        HSSFPatriarch patriarch, int rowIndex) {
    HSSFFont headerFont = wb.createFont();
    headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle headerStyle = wb.createCellStyle();
    headerStyle.setFont(headerFont);/*from w w w.java  2s  . c o  m*/

    Publication publication = (Publication) aPub.getDomainFile();

    HSSFRow row = null;
    HSSFCell cell = null;
    // PubMedID
    Long pubMedId = publication.getPubMedId();
    row = sheet.createRow(rowIndex++);
    int cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString("Publication Identifier"));
    if (pubMedId != null && pubMedId.intValue() > 0) {
        row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(pubMedId.toString()));
    } else {
        String oid = publication.getDigitalObjectId();
        if (!StringUtils.isEmpty(oid)) {
            row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(oid));
        } else {
            // row.createCell(cellIndex++).setCellValue(
            // new HSSFRichTextString(""));
        }
    }
    // publication type
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString("Publication Type"));
    row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getCategory()));

    // publication status
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString(PUB_STATUS));
    row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getStatus()));

    // Authors
    String rowHeader = "Authors";
    StringBuffer sb = new StringBuffer();
    if (publication.getAuthorCollection() != null) {
        List<Author> authorslist = new ArrayList<Author>(publication.getAuthorCollection());
        Collections.sort(authorslist, new Comparator<Author>() {
            public int compare(Author o1, Author o2) {
                return (int) (o1.getCreatedDate().compareTo(o2.getCreatedDate()));
            }
        });
        for (Author author : authorslist) {
            sb.append(author.getFirstName());
            sb.append(' ');
            sb.append(author.getInitial());
            sb.append(' ');
            sb.append(author.getLastName());

            row = sheet.createRow(rowIndex++);
            cellIndex = 0;
            cell = row.createCell(cellIndex++);
            cell.setCellStyle(headerStyle);
            cell.setCellValue(new HSSFRichTextString(rowHeader));
            row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(sb.toString()));
            rowHeader = "";
            sb.setLength(0);
        }
    }

    // research area
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString(RESEARCH_CATEGORY));
    row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getResearchArea()));

    // Title
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString("Title"));
    row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getTitle()));

    // Journal
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString("Journal"));
    row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getJournalName()));

    // Year
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString("Year"));
    int year = 0;
    if (publication.getYear() != null)
        year = publication.getYear();
    if (year > 0) {
        row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(Integer.toString(year)));
    }

    // Volume
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString("Volume"));
    row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getVolume()));

    // Pages
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString("Pages"));
    String startPage = publication.getStartPage();
    String endPage = publication.getEndPage();
    if ((!StringUtils.isEmpty(startPage)) || (!StringUtils.isEmpty(endPage))) {
        row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getJournalName()));
    }

    // Description
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString(DESCRIPTION));
    row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getDescription()));

    // Uploaded Publication URI
    row = sheet.createRow(rowIndex++);
    cellIndex = 0;
    cell = row.createCell(cellIndex++);
    cell.setCellStyle(headerStyle);
    cell.setCellValue(new HSSFRichTextString("Publication URI"));
    row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getUri()));

    return rowIndex;
}

From source file:gov.nih.nci.cananolab.util.ExportUtils.java

License:BSD License

/**
 * Create a HSSFCell in row with index and value.
 *
 * @param row HSSFRow//from   w ww  . j  a v  a 2 s  .  c  o  m
 * @param index int
 * @param value String
 * @return HSSFCell
 */
public static HSSFCell createCell(HSSFRow row, int index, String value) {
    HSSFCell cell = row.createCell(index);
    cell.setCellValue(new HSSFRichTextString(value));
    return cell;
}

From source file:gov.nih.nci.evs.reportwriter.formatter.AsciiToExcelFormatter.java

License:BSD License

public Boolean convert(String textfile, String delimiter, String outfile) throws Exception {

    Vector<String> headings = getColumnHeadings(textfile, delimiter);
    Vector<Integer> maxChars = getColumnMaxChars(textfile, delimiter);

    // Note: Special Case for CDISC STDM Terminology report.
    int extensible_col = -1;
    if (_specialCases_CDISC)
        extensible_col = findColumnIndicator(headings, "Extensible");

    int heading_height_multiplier = 1;
    for (int i = 0; i < maxChars.size(); i++) {
        String heading = (String) headings.elementAt(i);
        int maxCellLen = maxChars.elementAt(i);
        int maxTokenLen = getMaxTokenLength(heading);
        if (maxTokenLen > maxCellLen) {
            maxCellLen = maxTokenLen;/* w  w w  .j  a v  a 2s  .com*/
            maxChars.setElementAt(new Integer(maxCellLen), i);
        }
        if (maxCellLen < MAX_CODE_WIDTH) {
            Vector<String> tokens = parseData(heading, " ");
            if (tokens.size() > heading_height_multiplier)
                heading_height_multiplier = tokens.size();
        }
    }

    Boolean[] a = findWrappedColumns(textfile, delimiter, MAX_WIDTH);
    // Note: The max column number allowed in an Excel spreadsheet is 256
    int[] b = new int[255];
    for (int i = 0; i < 255; i++) {
        b[i] = 0;
    }

    File file = new File(textfile);
    String absolutePath = file.getAbsolutePath();
    _logger.debug("Absolute Path: " + absolutePath);
    String filename = file.getName();
    _logger.debug("filename: " + filename);

    int m = filename.indexOf(".");
    String workSheetLabel = filename.substring(0, m);
    int n = workSheetLabel.indexOf("__");
    workSheetLabel = workSheetLabel.substring(0, n);
    _logger.debug("workSheetLabel: " + workSheetLabel);

    if (workSheetLabel.compareTo("") == 0)
        return Boolean.FALSE;

    String pathName = file.getPath();
    _logger.debug("Path: " + pathName);

    BufferedReader br = getBufferReader(textfile);
    FileOutputStream fout = new FileOutputStream(outfile);
    HSSFWorkbook wb = new HSSFWorkbook();

    HSSFSheet ws = wb.createSheet(workSheetLabel);
    HSSFCellStyle toprow = wb.createCellStyle();
    HSSFCellStyle highlightedrow = wb.createCellStyle();

    HSSFCellStyle cs = wb.createCellStyle();

    // Note: GF20673 shade top row
    HSSFFont font = wb.createFont();
    font.setColor(HSSFColor.BLACK.index);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    toprow.setFont(font);

    if (extensible_col == -1) {
        toprow.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    } else {
        //toprow.setFillForegroundColor(HSSFColor.YELLOW.index);
        toprow.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
    }

    toprow.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    toprow.setAlignment(HSSFCellStyle.VERTICAL_CENTER);
    toprow.setWrapText(true);

    highlightedrow.setFont(font);
    //highlightedrow.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
    //highlightedrow.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index);
    highlightedrow.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);

    highlightedrow.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    highlightedrow.setAlignment(HSSFCellStyle.VERTICAL_CENTER);
    // highlightedrow.setWrapText(true);

    cs.setWrapText(true);
    // cs.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);
    cs.setAlignment(HSSFCellStyle.VERTICAL_TOP);

    HSSFRow wr = null;
    int rownum = 0;
    // int baseline_height = 15;
    int baseline_height = 12;
    while (true) {
        String line = br.readLine();
        if (line == null)
            break;
        // line = line.trim(); Note: 090512 first value could be empty
        if (line.length() <= 0)
            continue;

        Vector<String> v = parseData(line, delimiter);
        wr = ws.createRow(rownum);
        // wr.setHeightInPoints(60);
        if (rownum == 0) {
            wr.setHeightInPoints(baseline_height * heading_height_multiplier);
        } else {
            wr.setHeightInPoints(baseline_height);
            if (ADJUST_HEIGHT) {
                int num_lines = getHeightInPoints(v, ADJUST_HEIGHT, MAX_CELL_WIDTH);
                wr.setHeightInPoints(baseline_height * num_lines);
            }
        }

        // Note: Special Case for CDISC STDM Terminology report.
        boolean highlight_row = false;
        if (_specialCases_CDISC)
            highlight_row = extensible_col != -1 && v.elementAt(extensible_col).trim().length() > 0;

        for (int i = 0; i < v.size(); i++) {
            HSSFCell wc = wr.createCell(i);
            if (rownum == 0) {
                wc.setCellStyle(toprow);
            } else if (a[i].equals(Boolean.TRUE)) {

                wc.setCellStyle(cs);
                wc.setCellType(HSSFCell.CELL_TYPE_STRING);

                if (highlight_row)
                    wc.setCellStyle(highlightedrow);

            } else {
                if (highlight_row)
                    wc.setCellStyle(highlightedrow);
            }

            String s = (String) v.elementAt(i);
            s = s.trim();

            if (s.length() > b[i]) {
                b[i] = s.length();
            }
            if (s.equals("")) {
                s = null;
            }

            wc.setCellValue(s);
            if (_ncitCodeColumns.contains(i) && rownum > 0 && s != null && s.length() > 0) {
                try {
                    wc.setCellFormula("HYPERLINK(\"" + getNCItCodeUrl(s) + "\", \"" + s + "\")");
                } catch (Exception e) {
                    ExceptionUtils.print(_logger, e, "The following string is too large to be a "
                            + "valid NCIt code (" + filename + "): " + s);
                }
            }
        }
        rownum++;
    }

    br.close();
    for (int i = 0; i < 255; i++) {
        if (b[i] != 0) {
            int multiplier = b[i];
            if (i < headings.size()) {
                Integer int_obj = (Integer) maxChars.elementAt(i);
                multiplier = int_obj.intValue();
            }

            // Note(GF20673): 315 is the magic number for this font and size
            int colWidth = multiplier * 315;

            // Fields like definition run long, some sanity required
            if (colWidth > 20000) {
                colWidth = 20000;
            }
            // _logger.debug("Calculated column width " + i + ": " +
            // colWidth);
            ws.setColumnWidth(i, colWidth);
        }
    }

    // Note(GF20673): Freeze top row
    ws.createFreezePane(0, 1, 0, 1);
    wb.write(fout);
    fout.close();
    return Boolean.TRUE;
}