Example usage for javax.xml.datatype DatatypeConstants EQUAL

List of usage examples for javax.xml.datatype DatatypeConstants EQUAL

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeConstants EQUAL.

Prototype

int EQUAL

To view the source code for javax.xml.datatype DatatypeConstants EQUAL.

Click Source Link

Document

Comparison result.

Usage

From source file:DatatypeAPIUsage.java

public static void main(String[] args) {
    try {/*from   w  ww  . j av  a2  s . c  om*/
        DatatypeFactory df = DatatypeFactory.newInstance();
        // my work number in milliseconds:
        Duration myPhone = df.newDuration(9054133519l);
        Duration myLife = df.newDuration(true, 29, 2, 15, 13, 45, 0);
        int compareVal = myPhone.compare(myLife);
        switch (compareVal) {
        case DatatypeConstants.LESSER:
            System.out.println("There are fewer milliseconds in my phone number than my lifespan.");
            break;
        case DatatypeConstants.EQUAL:
            System.out.println("The same number of milliseconds are in my phone number and my lifespan.");
            break;
        case DatatypeConstants.GREATER:
            System.out.println("There are more milliseconds in my phone number than my lifespan.");
            break;
        case DatatypeConstants.INDETERMINATE:
            System.out.println("The comparison could not be carried out.");
        }

        // create a yearMonthDuration
        Duration ymDuration = df.newDurationYearMonth("P12Y10M");
        System.out.println("P12Y10M is of type: " + ymDuration.getXMLSchemaType());

        // create a dayTimeDuration (really this time)
        Duration dtDuration = df.newDurationDayTime("P10DT10H12M0S");
        System.out.println("P10DT10H12M0S is of type: " + dtDuration.getXMLSchemaType());

        // try to fool the factory!
        try {
            ymDuration = df.newDurationYearMonth("P12Y10M1D");
        } catch (IllegalArgumentException e) {
            System.out.println("'duration': P12Y10M1D is not 'yearMonthDuration'!!!");
        }

        XMLGregorianCalendar xgc = df.newXMLGregorianCalendar();
        xgc.setYear(1975);
        xgc.setMonth(DatatypeConstants.AUGUST);
        xgc.setDay(11);
        xgc.setHour(6);
        xgc.setMinute(44);
        xgc.setSecond(0);
        xgc.setMillisecond(0);
        xgc.setTimezone(5);
        xgc.add(myPhone);
        System.out.println("The approximate end of the number of milliseconds in my phone number was " + xgc);

        // adding a duration to XMLGregorianCalendar
        xgc.add(myLife);
        System.out.println("Adding the duration myLife to the above calendar:" + xgc);

        // create a new XMLGregorianCalendar using the string format of xgc.
        XMLGregorianCalendar xgcCopy = df.newXMLGregorianCalendar(xgc.toXMLFormat());

        // should be equal-if not what happened!!
        if (xgcCopy.compare(xgc) != DatatypeConstants.EQUAL) {
            System.out.println("oooops!");
        } else {
            System.out.println("Very good: " + xgc + " is equal to " + xgcCopy);
        }
    } catch (DatatypeConfigurationException dce) {
        System.err.println("error: Datatype error occurred - " + dce.getMessage());
        dce.printStackTrace(System.err);
    }
}

From source file:edu.harvard.i2b2.analysis.dataModel.TimelineFactory.java

public static String generateTimelineData(String result, ArrayList<TimelineRow> rows, boolean writeFile,
        boolean displayAll, boolean displayDemographics) {

    try {/*from w ww.j a v a  2  s .c o m*/
        PDOResponseMessageModel pdoresponsefactory = new PDOResponseMessageModel();
        StatusType statusType = pdoresponsefactory.getStatusFromResponseXML(result);
        if (!statusType.getType().equalsIgnoreCase("DONE")) {
            return "error";
        }

        StringBuilder resultFile = new StringBuilder();
        resultFile.append(GetTimelineHeader());

        PatientSet patientDimensionSet = pdoresponsefactory.getPatientSetFromResponseXML(result);
        if (patientDimensionSet != null) {
            log.debug("Total patient: " + patientDimensionSet.getPatient().size());
            // for(int i=0;
            // i<patientDimensionSet.getPatientDimension().size();i++) {
            // PatientDimensionType patientType =
            // patientDimensionSet.getPatientDimension().get(i);
            // System.out.println("PatientNum: " +
            // patientType.getPatientNum());
            // }
        } else {
            return "error";
        }

        // / testing the visit set
        // PatientDataType.VisitDimensionSet visitSet =
        // pdoresponsefactory.getVisitSetFromResponseXML(result);
        // System.out.println("Total visits: "+visitSet.getVisitDimension().
        // size());

        List<ObservationSet> factSets = pdoresponsefactory.getFactSetsFromResponseXML(result);

        log.debug("\nGenerate lld:");
        for (int i = 0; i < patientDimensionSet.getPatient().size(); i++) {
            PatientType patientType = patientDimensionSet.getPatient().get(i);
            String pnum = patientType.getPatientId().getValue();
            // Integer pnum = new Integer(snum);
            // log.debug("PatientNum: " + snum);

            if (displayDemographics) {
                resultFile.append(getTimelinePatientString(pnum.toString(), patientType));
            } else {
                resultFile.append(getTimelinePatientString(pnum.toString()));
            }

            String path = null;
            TimelineRow currentRow = null;
            ObservationSet observationFactSet = null;

            for (int j = 0; j < rows.size(); j++) {
                TimelineRow row = rows.get(j);
                int total = 0;
                StringBuilder resultString = new StringBuilder();

                // loop thru all the pdo sets for this row here
                for (int s = 0; s < row.pdoItems.size(); s++) {
                    PDOItem pset = row.pdoItems.get(s);
                    observationFactSet = null;

                    for (int m = 0; m < factSets.size(); m++) {
                        ObservationSet tmpFactSet = factSets.get(m);
                        if (tmpFactSet.getPanelName().equalsIgnoreCase(pset.fullPath)) {
                            observationFactSet = tmpFactSet;
                            path = observationFactSet.getPanelName();
                            currentRow = row;
                            break;
                        }
                    }

                    if (observationFactSet == null) {
                        continue;
                    }

                    XMLGregorianCalendar curStartDate = null;
                    for (int k = 0; k < observationFactSet.getObservation().size(); k++) {
                        ObservationType obsFactType = observationFactSet.getObservation().get(k);

                        if (pnum.equals(obsFactType.getPatientId().getValue())) {
                            /*   if ((curStartDate != null)
                                     && (obsFactType.getStartDate().compare(
                            curStartDate) == DatatypeConstants.EQUAL)) {
                                  continue;
                               }
                               */

                            String sStart_date = obsFactType.getStartDate().getMonth() + "-"
                                    + obsFactType.getStartDate().getDay() + "-"
                                    + obsFactType.getStartDate().getYear() + " 12:00";
                            String sEnd_date;
                            if (obsFactType.getEndDate() == null) {
                                sEnd_date = sStart_date;
                            } else {
                                sEnd_date = obsFactType.getEndDate().getMonth() + "-"
                                        + obsFactType.getEndDate().getDay() + "-"
                                        + obsFactType.getEndDate().getYear() + " 12:00";
                            }

                            double nval = -1;
                            if (obsFactType.getNvalNum().getValue() != null) {
                                nval = obsFactType.getNvalNum().getValue().doubleValue();
                            }
                            PDOValueData valdp = null;

                            if (pset.hasValueDisplayProperty) {
                                for (int n = 0; n < pset.valDisplayProperties.size(); n++) {
                                    PDOValueData tmpvaldp = pset.valDisplayProperties.get(n);
                                    // if (tmpvaldp.inRange(nval)) {
                                    valdp = tmpvaldp;
                                    // break;
                                    // }
                                }

                                String sValue = getSValue(row.displayName, obsFactType, true);
                                if ((curStartDate != null) && (obsFactType.getStartDate()
                                        .compare(curStartDate) == DatatypeConstants.EQUAL)) {
                                    resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                            "slateblue", valdp.height, sValue));
                                } else {
                                    resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                            valdp.color, valdp.height, sValue));
                                }
                            } else {
                                String sValue = getSValue(row.displayName, obsFactType, false);
                                if ((curStartDate != null) && (obsFactType.getStartDate()
                                        .compare(curStartDate) == DatatypeConstants.EQUAL)) {
                                    resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                            "slateblue", pset.height, sValue));
                                } else {
                                    resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                            pset.color, pset.height, sValue));
                                }
                            }

                            total++;
                            curStartDate = obsFactType.getStartDate();
                        }
                    }
                }

                if (total > 0) {
                    // log.debug("-- "+path+" has "+total+" events");
                    resultFile.append(getTimelineConceptString(row.displayName, total));

                    // log.debug(resultString.toString());
                    resultFile.append(resultString);
                } else {
                    // display all
                    if (displayAll) {
                        // log.debug("-- "+path+" has "+total+" events");
                        resultFile.append(getTimelineConceptString(row.displayName, 1));

                        // log.debug(getTimelineEmptyDateString());
                        resultFile.append(getTimelineEmptyDateString());
                    }
                }
            }
        }

        resultFile.append(GetTimelineFooter());

        if (writeFile) {
            String i2b2File = System.getProperty("user.dir") + "/temp/" + "i2b2xml.lld";
            File oDelete = new File(i2b2File);
            if (oDelete != null)
                oDelete.delete();
            RandomAccessFile f = new RandomAccessFile(i2b2File, "rw");
            append(f, resultFile.toString());
            f.close();
        }

        // log.debug("\nThe lld file: \n"+resultFile.toString());
        return resultFile.toString();
    } catch (org.apache.axis2.AxisFault e) {
        e.printStackTrace();
        log.error(e.getMessage());
        return null;
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
        return "error";
    }
}

From source file:com.evolveum.midpoint.util.MiscUtil.java

public static boolean isBetween(XMLGregorianCalendar date, XMLGregorianCalendar start,
        XMLGregorianCalendar end) {
    return (date.compare(start) == DatatypeConstants.GREATER || date.compare(start) == DatatypeConstants.EQUAL)
            && (date.compare(end) == DatatypeConstants.LESSER || date.compare(end) == DatatypeConstants.EQUAL);
}

From source file:edu.harvard.i2b2.explorer.dataModel.TimelineFactory.java

@SuppressWarnings("unchecked")
public String generateTimelineData(String result, ArrayList<TimelineRow> rows, boolean writeFile,
        boolean displayAll, boolean displayDemographics, final MainComposite explorer) {

    try {/*from w w  w .j  av a 2  s.co m*/
        PDOResponseMessageModel pdoresponsefactory = new PDOResponseMessageModel();
        StatusType statusType = pdoresponsefactory.getStatusFromResponseXML(result);
        if (!statusType.getType().equalsIgnoreCase("DONE")) {
            return "error";
        }

        JAXBUtil jaxbUtil = ExplorerJAXBUtil.getJAXBUtil();

        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(result);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bodyType = messageType.getMessageBody();
        PatientDataResponseType responseType = (PatientDataResponseType) new JAXBUnWrapHelper()
                .getObjectByClass(bodyType.getAny(), PatientDataResponseType.class);
        PageType pageType = responseType.getPage();
        if (pageType != null) {
            final int returnLastIndex = pageType.getPagingByPatients().getPatientsReturned().getLastIndex()
                    .intValue();
            final int returnFirstIndex = pageType.getPagingByPatients().getPatientsReturned().getFirstIndex()
                    .intValue();
            final int requestLastIndex = pageType.getPagingByPatients().getPatientsRequested().getLastIndex()
                    .intValue();
            if (returnLastIndex < requestLastIndex) {
                // System.out.println("Can't return all the requested "+
                // requestIndex+" patients, only "+returnIndex+" patients returned");
                explorer.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        // MessageBox mBox = new MessageBox(explorer
                        // .getShell(), SWT.ICON_INFORMATION
                        // | SWT.OK );
                        // mBox.setText("Please Note ...");
                        // mBox.setMessage("Only "+(returnLastIndex-returnFirstIndex+1)+" patients returned");
                        // mBox.open();
                        if (explorer.runMode() >= 0) {
                            explorer.setIncrementNumber(returnLastIndex - returnFirstIndex + 1);
                        } else if (explorer.runMode() == -1) {
                            explorer.setDecreaseNumber(returnLastIndex - returnFirstIndex + 1);
                        }
                    }
                });
                explorer.returnedNumber(returnLastIndex - returnFirstIndex + 1);
            } else {
                explorer.returnedNumber(-1);
            }
        } else {
            explorer.getDisplay().syncExec(new Runnable() {
                public void run() {
                    // MessageBox mBox = new MessageBox(explorer
                    // .getShell(), SWT.ICON_INFORMATION
                    // | SWT.OK );
                    // mBox.setText("Please Note ...");
                    // mBox.setMessage("Only "+(returnLastIndex-returnFirstIndex+1)+" patients returned");
                    // mBox.open();
                    if (explorer.runMode() >= 0) {
                        explorer.setIncrementNumber(-1);
                    } else if (explorer.runMode() == -1) {
                        explorer.setDecreaseNumber(-1);
                    }
                }
            });
        }

        StringBuilder resultFile = new StringBuilder();
        resultFile.append(GetTimelineHeader());

        PatientSet patientDimensionSet = pdoresponsefactory.getPatientSetFromResponseXML(result);
        if (patientDimensionSet != null) {
            log.debug("Total patient: " + patientDimensionSet.getPatient().size());
            // for(int i=0;
            // i<patientDimensionSet.getPatientDimension().size();i++) {
            // PatientDimensionType patientType =
            // patientDimensionSet.getPatientDimension().get(i);
            // System.out.println("PatientNum: " +
            // patientType.getPatientNum());
            // }
        } else {
            return "error";
        }

        // / testing the visit set
        // PatientDataType.VisitDimensionSet visitSet =
        // pdoresponsefactory.getVisitSetFromResponseXML(result);
        // System.out.println("Total visits: "+visitSet.getVisitDimension().
        // size());

        List<ObservationSet> factSets = pdoresponsefactory.getFactSetsFromResponseXML(result);

        log.debug("\nGenerate lld:");

        String curPNum = "-1";
        for (int i = 0; i < patientDimensionSet.getPatient().size(); i++) {
            PatientType patientType = patientDimensionSet.getPatient().get(i);
            String pnum = patientType.getPatientId().getValue();
            // Integer pnum = new Integer(snum);
            // log.debug("PatientNum: " + snum);
            //if(curPNum.equals("-1")) {
            curPNum = new String(pnum);
            //}

            if (displayDemographics) {
                resultFile.append(getTimelinePatientString(pnum.toString(), patientType));
            } else {
                resultFile.append(getTimelinePatientString(pnum.toString()));
            }

            String path = null;
            TimelineRow currentRow = null;
            ObservationSet observationFactSet = null;

            for (int j = 0; j < rows.size(); j++) {
                TimelineRow row = rows.get(j);
                int total = 0;
                StringBuilder resultString = new StringBuilder();

                XMLGregorianCalendar curStartDate = null;
                //int currentInstanceNum = 0;
                //String currentConcept = "";
                ArrayList<ObservationType> facts = new ArrayList<ObservationType>();
                ObservationType curFact = null;
                boolean recorded = false;
                String sStart_date = null;
                String sEnd_date = null;

                // loop thru all the pdo sets for this row here
                for (int s = 0; s < row.pdoItems.size(); s++) {
                    PDOItem pset = row.pdoItems.get(s);
                    observationFactSet = null;

                    for (int m = 0; m < factSets.size(); m++) {
                        ObservationSet tmpFactSet = factSets.get(m);
                        if (tmpFactSet.getPanelName().equalsIgnoreCase(pset.panelName())) {
                            observationFactSet = tmpFactSet;
                            path = observationFactSet.getPanelName();
                            currentRow = row;
                            break;
                        }
                    }

                    if (observationFactSet == null) {
                        continue;
                    }

                    for (int k = 0; k < observationFactSet.getObservation().size(); k++) {
                        ObservationType obsFactType = observationFactSet.getObservation().get(k);
                        //if(curFact == null) {
                        //curFact = obsFactType;
                        //}

                        //facts.add(obsFactType);

                        if (pnum.equals(obsFactType.getPatientId().getValue())) {
                            /*
                             * if ((curStartDate != null) &&
                             * (obsFactType.getStartDate().compare(
                             * curStartDate) == DatatypeConstants.EQUAL)) {
                             * continue; }
                             */
                            if (curFact == null) {
                                curFact = obsFactType;
                            }

                            if (curStartDate == null) {
                                curStartDate = obsFactType.getStartDate();
                            }

                            sStart_date = obsFactType.getStartDate().getMonth() + "-"
                                    + obsFactType.getStartDate().getDay() + "-"
                                    + obsFactType.getStartDate().getYear();

                            if (obsFactType.getEndDate() == null) {
                                sEnd_date = sStart_date;
                            } else {
                                sEnd_date = obsFactType.getEndDate().getMonth() + "-"
                                        + obsFactType.getEndDate().getDay() + "-"
                                        + obsFactType.getEndDate().getYear();
                            }

                            double nval = -1;
                            if (obsFactType.getNvalNum().getValue() != null) {
                                nval = obsFactType.getNvalNum().getValue().doubleValue();
                            }
                            PDOValueModel valdp = null;

                            boolean same = sameInstance(curFact, obsFactType);
                            if (false) {//pset.hasValueDisplayProperty) {
                                for (int n = 0; n < pset.valDisplayProperties.size(); n++) {
                                    PDOValueModel tmpvaldp = pset.valDisplayProperties.get(n);
                                    // if (tmpvaldp.inRange(nval)) {
                                    valdp = tmpvaldp;
                                    // break;
                                    // }
                                }

                                String sValue = getSValue(obsFactType.getConceptCd().getName(), obsFactType,
                                        true);
                                if ((curStartDate != null) && (obsFactType.getStartDate()
                                        .compare(curStartDate) == DatatypeConstants.EQUAL)) {
                                    resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                            "slateblue", valdp.height, sValue));
                                } else {
                                    resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                            valdp.color, valdp.height, sValue));
                                }
                            } else {
                                //////////////////////
                                String sValue = "";
                                if (same && k != observationFactSet.getObservation().size() - 1) {
                                    //if(recorded) {
                                    facts.add(obsFactType);
                                    //recorded = false;
                                    continue;
                                    //}
                                    /*sValue = getSValueSame(obsFactType.getConceptCd().getName(),
                                          obsFactType, false);
                                    if ((curStartDate != null)
                                          && (obsFactType.getStartDate()
                                                .compare(curStartDate) == DatatypeConstants.EQUAL)) {
                                       resultString
                                             .append(getTimelineDateStringHeightSame(
                                     sStart_date, sEnd_date,
                                     "slateblue",
                                     pset.height, sValue));
                                    } else {
                                       resultString
                                             .append(getTimelineDateStringHeightSame(
                                     sStart_date, sEnd_date,
                                     pset.color,
                                     pset.height, sValue));
                                    }*/
                                }
                                //else {
                                if (facts.size() == 0) {
                                    facts.add(obsFactType);
                                }
                                sValue = getSValue(curFact.getConceptCd().getName(), facts, false);
                                //}

                                sStart_date = curFact.getStartDate().getMonth() + "-"
                                        + curFact.getStartDate().getDay() + "-"
                                        + curFact.getStartDate().getYear();

                                if (curFact.getEndDate() == null) {
                                    sEnd_date = sStart_date;
                                } else {
                                    sEnd_date = curFact.getEndDate().getMonth() + "-"
                                            + curFact.getEndDate().getDay() + "-"
                                            + curFact.getEndDate().getYear();
                                }

                                //if ((curStartDate != null)
                                //      && (obsFactType.getStartDate()
                                //      .compare(curStartDate) == DatatypeConstants.EQUAL)) {
                                //resultString
                                //.append(getTimelineDateStringHeight(
                                //sStart_date, sEnd_date,
                                //"slateblue",
                                //pset.height, sValue));
                                //} else {
                                resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                        pset.color, pset.height, sValue));
                                //}
                            }

                            total++;
                            recorded = false;
                            facts.clear();
                            facts.add(obsFactType);
                            curStartDate = obsFactType.getStartDate();
                            curFact = obsFactType;

                            /////
                            if (!same && k == observationFactSet.getObservation().size() - 1) {
                                String sValue = "";
                                sValue = getSValue(obsFactType.getConceptCd().getName(), facts, false);
                                //}

                                sStart_date = obsFactType.getStartDate().getMonth() + "-"
                                        + obsFactType.getStartDate().getDay() + "-"
                                        + obsFactType.getStartDate().getYear();

                                if (obsFactType.getEndDate() == null) {
                                    sEnd_date = sStart_date;
                                } else {
                                    sEnd_date = obsFactType.getEndDate().getMonth() + "-"
                                            + obsFactType.getEndDate().getDay() + "-"
                                            + obsFactType.getEndDate().getYear();
                                }

                                //if ((curStartDate != null)
                                //      && (obsFactType.getStartDate()
                                //      .compare(curStartDate) == DatatypeConstants.EQUAL)) {
                                //resultString
                                //.append(getTimelineDateStringHeight(
                                //sStart_date, sEnd_date,
                                //"slateblue",
                                //pset.height, sValue));
                                //} else {
                                resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                        pset.color, pset.height, sValue));
                                //}
                                total++;
                            }
                            ////
                        } else {
                            if (recorded || facts.size() == 0) {
                                curPNum = new String(pnum);
                                continue;
                            }
                            sStart_date = curStartDate.getMonth() + "-" + curStartDate.getDay() + "-"
                                    + curStartDate.getYear();

                            //if (obsFactType.getEndDate() == null) {
                            //sEnd_date = sStart_date;
                            //} else {
                            sEnd_date = curStartDate.getMonth() + "-" + curStartDate.getDay() + "-"
                                    + curStartDate.getYear() + " 12:00";
                            //}
                            //curFact = null;
                            String sValue = getSValue(curFact.getConceptCd().getName(), facts, false);
                            //if ((curStartDate != null)
                            //&& (obsFactType.getStartDate()
                            //.compare(curStartDate) == DatatypeConstants.EQUAL)) {
                            //resultString
                            //.append(getTimelineDateStringHeight(
                            //sStart_date, sEnd_date,
                            //"slateblue",
                            //pset.height, sValue));
                            //} else {
                            resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date, pset.color,
                                    pset.height, sValue));
                            //}
                            total++;
                            recorded = true;
                            facts.clear();
                            curStartDate = null;//obsFactType.getStartDate();
                            curFact = null;//obsFactType;
                            curPNum = new String(pnum);
                        }
                    }
                }

                if (total > 0) {
                    // log.debug("-- "+path+" has "+total+" events");
                    resultFile.append(getTimelineConceptString(row.displayName, total));

                    // log.debug(resultString.toString());
                    resultFile.append(resultString);
                    total = 0;
                    recorded = true;
                } else {
                    // display all
                    if (displayAll) {
                        // log.debug("-- "+path+" has "+total+" events");
                        resultFile.append(getTimelineConceptString(row.displayName, 1));

                        // log.debug(getTimelineEmptyDateString());
                        resultFile.append(getTimelineEmptyDateString());
                    }
                }

                if (recorded || facts.size() == 0) {
                    curPNum = new String(pnum);
                    continue;
                }
                sStart_date = curStartDate.getMonth() + "-" + curStartDate.getDay() + "-"
                        + curStartDate.getYear();

                //if (obsFactType.getEndDate() == null) {
                //sEnd_date = sStart_date;
                //} else {
                sEnd_date = curStartDate.getMonth() + "-" + curStartDate.getDay() + "-"
                        + curStartDate.getYear();
                //}
                //curFact = null;
                String sValue = getSValue(curFact.getConceptCd().getName(), facts, false);

                resultString
                        .append(getTimelineDateStringHeight(sStart_date, sEnd_date, "navyblue", "p10", sValue));

                total++;
                recorded = true;
                facts.clear();
                //curStartDate = obsFactType.getStartDate();
                //curFact = obsFactType;
                curPNum = new String(pnum);
                if (total > 0) {
                    // log.debug("-- "+path+" has "+total+" events");
                    resultFile.append(getTimelineConceptString(row.displayName, total));

                    // log.debug(resultString.toString());
                    resultFile.append(resultString);
                }
            }
        }

        resultFile.append(GetTimelineFooter());

        if (writeFile) {
            String i2b2File = System.getProperty("user.dir") + "/temp/" + "i2b2xml.lld";
            File oDelete = new File(i2b2File);
            if (oDelete != null)
                oDelete.delete();
            RandomAccessFile f = new RandomAccessFile(i2b2File, "rw");
            append(f, resultFile.toString());
            f.close();
        }

        // log.debug("\nThe lld file: \n"+resultFile.toString());
        return resultFile.toString();
    } catch (org.apache.axis2.AxisFault e) {
        e.printStackTrace();
        log.error(e.getMessage());
        return null;
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
        return "error";
    }
}

From source file:edu.harvard.i2b2.adminTool.dataModel.PatientMappingFactory.java

@SuppressWarnings("unchecked")
public String generateTimelineData(String result, ArrayList<TimelineRow> rows, boolean writeFile,
        boolean displayAll, boolean displayDemographics, final MainComposite explorer) {

    try {/*from w w w  .j  av  a  2 s .  c  o  m*/
        PDOResponseMessageModel pdoresponsefactory = new PDOResponseMessageModel();
        StatusType statusType = pdoresponsefactory.getStatusFromResponseXML(result);
        if (!statusType.getType().equalsIgnoreCase("DONE")) {
            return "error";
        }

        JAXBUtil jaxbUtil = PatientMappingJAXBUtil.getJAXBUtil();

        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(result);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bodyType = messageType.getMessageBody();
        PatientDataResponseType responseType = (PatientDataResponseType) new JAXBUnWrapHelper()
                .getObjectByClass(bodyType.getAny(), PatientDataResponseType.class);
        PageType pageType = responseType.getPage();
        if (pageType != null) {
            final int returnLastIndex = pageType.getPagingByPatients().getPatientsReturned().getLastIndex()
                    .intValue();
            final int returnFirstIndex = pageType.getPagingByPatients().getPatientsReturned().getFirstIndex()
                    .intValue();
            final int requestLastIndex = pageType.getPagingByPatients().getPatientsRequested().getLastIndex()
                    .intValue();
            if (returnLastIndex < requestLastIndex) {
                // System.out.println("Can't return all the requested "+
                // requestIndex+" patients, only "+returnIndex+" patients returned");
                explorer.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        // MessageBox mBox = new MessageBox(explorer
                        // .getShell(), SWT.ICON_INFORMATION
                        // | SWT.OK );
                        // mBox.setText("Please Note ...");
                        // mBox.setMessage("Only "+(returnLastIndex-returnFirstIndex+1)+" patients returned");
                        // mBox.open();
                        if (explorer.runMode() >= 0) {
                            explorer.setIncrementNumber(returnLastIndex - returnFirstIndex + 1);
                        } else if (explorer.runMode() == -1) {
                            explorer.setDecreaseNumber(returnLastIndex - returnFirstIndex + 1);
                        }
                    }
                });
                explorer.returnedNumber(returnLastIndex - returnFirstIndex + 1);
            } else {
                explorer.returnedNumber(-1);
            }
        } else {
            explorer.getDisplay().syncExec(new Runnable() {
                public void run() {
                    // MessageBox mBox = new MessageBox(explorer
                    // .getShell(), SWT.ICON_INFORMATION
                    // | SWT.OK );
                    // mBox.setText("Please Note ...");
                    // mBox.setMessage("Only "+(returnLastIndex-returnFirstIndex+1)+" patients returned");
                    // mBox.open();
                    if (explorer.runMode() >= 0) {
                        explorer.setIncrementNumber(-1);
                    } else if (explorer.runMode() == -1) {
                        explorer.setDecreaseNumber(-1);
                    }
                }
            });
        }

        StringBuilder resultFile = new StringBuilder();
        resultFile.append(GetTimelineHeader());

        PatientSet patientDimensionSet = pdoresponsefactory.getPatientSetFromResponseXML(result);
        if (patientDimensionSet != null) {
            log.debug("Total patient: " + patientDimensionSet.getPatient().size());
            // for(int i=0;
            // i<patientDimensionSet.getPatientDimension().size();i++) {
            // PatientDimensionType patientType =
            // patientDimensionSet.getPatientDimension().get(i);
            // System.out.println("PatientNum: " +
            // patientType.getPatientNum());
            // }
        } else {
            return "error";
        }

        // / testing the visit set
        // PatientDataType.VisitDimensionSet visitSet =
        // pdoresponsefactory.getVisitSetFromResponseXML(result);
        // System.out.println("Total visits: "+visitSet.getVisitDimension().
        // size());

        List<ObservationSet> factSets = pdoresponsefactory.getFactSetsFromResponseXML(result);

        log.debug("\nGenerate lld:");

        String curPNum = "-1";
        for (int i = 0; i < patientDimensionSet.getPatient().size(); i++) {
            PatientType patientType = patientDimensionSet.getPatient().get(i);
            String pnum = patientType.getPatientId().getValue();
            // Integer pnum = new Integer(snum);
            // log.debug("PatientNum: " + snum);
            //if(curPNum.equals("-1")) {
            curPNum = new String(pnum);
            //}

            if (displayDemographics) {
                resultFile.append(getTimelinePatientString(pnum.toString(), patientType));
            } else {
                resultFile.append(getTimelinePatientString(pnum.toString()));
            }

            String path = null;
            TimelineRow currentRow = null;
            ObservationSet observationFactSet = null;

            for (int j = 0; j < rows.size(); j++) {
                TimelineRow row = rows.get(j);
                int total = 0;
                StringBuilder resultString = new StringBuilder();

                XMLGregorianCalendar curStartDate = null;
                //int currentInstanceNum = 0;
                //String currentConcept = "";
                ArrayList<ObservationType> facts = new ArrayList<ObservationType>();
                ObservationType curFact = null;
                boolean recorded = false;
                String sStart_date = null;
                String sEnd_date = null;

                // loop thru all the pdo sets for this row here
                for (int s = 0; s < row.pdoItems.size(); s++) {
                    PDOItem pset = row.pdoItems.get(s);
                    observationFactSet = null;

                    for (int m = 0; m < factSets.size(); m++) {
                        ObservationSet tmpFactSet = factSets.get(m);
                        if (tmpFactSet.getPanelName().equalsIgnoreCase(pset.panelName())) {
                            observationFactSet = tmpFactSet;
                            path = observationFactSet.getPanelName();
                            currentRow = row;
                            break;
                        }
                    }

                    if (observationFactSet == null) {
                        continue;
                    }

                    for (int k = 0; k < observationFactSet.getObservation().size(); k++) {
                        ObservationType obsFactType = observationFactSet.getObservation().get(k);
                        //if(curFact == null) {
                        //curFact = obsFactType;
                        //}

                        //facts.add(obsFactType);

                        if (pnum.equals(obsFactType.getPatientId().getValue())) {
                            /*
                             * if ((curStartDate != null) &&
                             * (obsFactType.getStartDate().compare(
                             * curStartDate) == DatatypeConstants.EQUAL)) {
                             * continue; }
                             */
                            if (curFact == null) {
                                curFact = obsFactType;
                            }

                            if (curStartDate == null) {
                                curStartDate = obsFactType.getStartDate();
                            }

                            sStart_date = obsFactType.getStartDate().getMonth() + "-"
                                    + obsFactType.getStartDate().getDay() + "-"
                                    + obsFactType.getStartDate().getYear() + " 12:00";

                            if (obsFactType.getEndDate() == null) {
                                sEnd_date = sStart_date;
                            } else {
                                sEnd_date = obsFactType.getEndDate().getMonth() + "-"
                                        + obsFactType.getEndDate().getDay() + "-"
                                        + obsFactType.getEndDate().getYear() + " 12:00";
                            }

                            double nval = -1;
                            if (obsFactType.getNvalNum().getValue() != null) {
                                nval = obsFactType.getNvalNum().getValue().doubleValue();
                            }
                            PDOValueModel valdp = null;

                            if (false) {//pset.hasValueDisplayProperty) {
                                for (int n = 0; n < pset.valDisplayProperties.size(); n++) {
                                    PDOValueModel tmpvaldp = pset.valDisplayProperties.get(n);
                                    // if (tmpvaldp.inRange(nval)) {
                                    valdp = tmpvaldp;
                                    // break;
                                    // }
                                }

                                String sValue = getSValue(obsFactType.getConceptCd().getName(), obsFactType,
                                        true);
                                if ((curStartDate != null) && (obsFactType.getStartDate()
                                        .compare(curStartDate) == DatatypeConstants.EQUAL)) {
                                    resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                            "slateblue", valdp.height, sValue));
                                } else {
                                    resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                            valdp.color, valdp.height, sValue));
                                }
                            } else {
                                //////////////////////
                                String sValue = "";
                                if (sameInstance(curFact, obsFactType)) {
                                    //if(recorded) {
                                    facts.add(obsFactType);
                                    //recorded = false;
                                    continue;
                                    //}
                                    /*sValue = getSValueSame(obsFactType.getConceptCd().getName(),
                                          obsFactType, false);
                                    if ((curStartDate != null)
                                          && (obsFactType.getStartDate()
                                                .compare(curStartDate) == DatatypeConstants.EQUAL)) {
                                       resultString
                                             .append(getTimelineDateStringHeightSame(
                                     sStart_date, sEnd_date,
                                     "slateblue",
                                     pset.height, sValue));
                                    } else {
                                       resultString
                                             .append(getTimelineDateStringHeightSame(
                                     sStart_date, sEnd_date,
                                     pset.color,
                                     pset.height, sValue));
                                    }*/
                                }
                                //else {
                                sValue = getSValue(curFact.getConceptCd().getName(), facts, false);
                                //}

                                sStart_date = curFact.getStartDate().getMonth() + "-"
                                        + curFact.getStartDate().getDay() + "-"
                                        + curFact.getStartDate().getYear() + " 12:00";

                                if (curFact.getEndDate() == null) {
                                    sEnd_date = sStart_date;
                                } else {
                                    sEnd_date = curFact.getEndDate().getMonth() + "-"
                                            + curFact.getEndDate().getDay() + "-"
                                            + curFact.getEndDate().getYear() + " 12:00";
                                }

                                //if ((curStartDate != null)
                                //      && (obsFactType.getStartDate()
                                //      .compare(curStartDate) == DatatypeConstants.EQUAL)) {
                                //resultString
                                //.append(getTimelineDateStringHeight(
                                //sStart_date, sEnd_date,
                                //"slateblue",
                                //pset.height, sValue));
                                //} else {
                                resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date,
                                        pset.color, pset.height, sValue));
                                //}
                            }

                            total++;
                            recorded = false;
                            facts.clear();
                            facts.add(obsFactType);
                            curStartDate = obsFactType.getStartDate();
                            curFact = obsFactType;
                        } else {
                            if (recorded || facts.size() == 0) {
                                curPNum = new String(pnum);
                                continue;
                            }
                            sStart_date = curStartDate.getMonth() + "-" + curStartDate.getDay() + "-"
                                    + curStartDate.getYear() + " 12:00";

                            //if (obsFactType.getEndDate() == null) {
                            //sEnd_date = sStart_date;
                            //} else {
                            sEnd_date = curStartDate.getMonth() + "-" + curStartDate.getDay() + "-"
                                    + curStartDate.getYear() + " 12:00";
                            //}
                            //curFact = null;
                            String sValue = getSValue(curFact.getConceptCd().getName(), facts, false);
                            //if ((curStartDate != null)
                            //&& (obsFactType.getStartDate()
                            //.compare(curStartDate) == DatatypeConstants.EQUAL)) {
                            //resultString
                            //.append(getTimelineDateStringHeight(
                            //sStart_date, sEnd_date,
                            //"slateblue",
                            //pset.height, sValue));
                            //} else {
                            resultString.append(getTimelineDateStringHeight(sStart_date, sEnd_date, pset.color,
                                    pset.height, sValue));
                            //}
                            total++;
                            recorded = true;
                            facts.clear();
                            curStartDate = null;//obsFactType.getStartDate();
                            curFact = null;//obsFactType;
                            curPNum = new String(pnum);
                        }
                    }
                }

                if (total > 0) {
                    // log.debug("-- "+path+" has "+total+" events");
                    resultFile.append(getTimelineConceptString(row.displayName, total));

                    // log.debug(resultString.toString());
                    resultFile.append(resultString);
                    total = 0;
                    ////rdtr
                } else {
                    // display all
                    if (displayAll) {
                        // log.debug("-- "+path+" has "+total+" events");
                        resultFile.append(getTimelineConceptString(row.displayName, 1));

                        // log.debug(getTimelineEmptyDateString());
                        resultFile.append(getTimelineEmptyDateString());
                    }
                }

                if (recorded || facts.size() == 0) {
                    curPNum = new String(pnum);
                    continue;
                }
                sStart_date = curStartDate.getMonth() + "-" + curStartDate.getDay() + "-"
                        + curStartDate.getYear() + " 12:00";

                //if (obsFactType.getEndDate() == null) {
                //sEnd_date = sStart_date;
                //} else {
                sEnd_date = curStartDate.getMonth() + "-" + curStartDate.getDay() + "-" + curStartDate.getYear()
                        + " 12:00";
                //}
                //curFact = null;
                String sValue = getSValue(curFact.getConceptCd().getName(), facts, false);

                resultString
                        .append(getTimelineDateStringHeight(sStart_date, sEnd_date, "navyblue", "p10", sValue));

                total++;
                recorded = true;
                facts.clear();
                //curStartDate = obsFactType.getStartDate();
                //curFact = obsFactType;
                curPNum = new String(pnum);
                if (total > 0) {
                    // log.debug("-- "+path+" has "+total+" events");
                    resultFile.append(getTimelineConceptString(row.displayName, total));

                    // log.debug(resultString.toString());
                    resultFile.append(resultString);
                }
            }
        }

        resultFile.append(GetTimelineFooter());

        if (writeFile) {
            String i2b2File = System.getProperty("user.dir") + "/temp/" + "i2b2xml.lld";
            File oDelete = new File(i2b2File);
            if (oDelete != null)
                oDelete.delete();
            RandomAccessFile f = new RandomAccessFile(i2b2File, "rw");
            append(f, resultFile.toString());
            f.close();
        }

        // log.debug("\nThe lld file: \n"+resultFile.toString());
        return resultFile.toString();
    } catch (org.apache.axis2.AxisFault e) {
        e.printStackTrace();
        log.error(e.getMessage());
        return null;
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
        return "error";
    }
}

From source file:com.evolveum.midpoint.test.util.TestUtil.java

public static void assertBetween(String message, XMLGregorianCalendar start, XMLGregorianCalendar end,
        XMLGregorianCalendar actual) {
    assertNotNull(message + " is null", actual);
    if (start != null) {
        assertTrue(message + ": expected time to be after " + start + " but it was " + actual,
                actual.compare(start) == DatatypeConstants.GREATER
                        || actual.compare(start) == DatatypeConstants.EQUAL);
    }/*from  w  w  w .  ja v a2  s  . c  om*/
    if (end != null) {
        assertTrue(message + ": expected time to be before " + end + " but it was " + actual,
                actual.compare(end) == DatatypeConstants.LESSER
                        || actual.compare(end) == DatatypeConstants.EQUAL);
    }
}

From source file:edu.harvard.i2b2.adminTool.dataModel.PatientMappingFactory.java

private boolean sameInstance(ObservationType curFact, ObservationType obsFactType) {
    boolean same = false;
    //if(obsFactType.getInstanceNum() == null) {
    //return same;
    //}/*  w ww .j a v  a 2 s.  c o  m*/

    if (obsFactType.getStartDate().compare(curFact.getStartDate()) == DatatypeConstants.EQUAL
            && obsFactType.getConceptCd().getValue().equals(curFact.getConceptCd().getValue())
            && ((obsFactType.getInstanceNum() == null)
                    || obsFactType.getInstanceNum().getValue().equals(curFact.getInstanceNum().getValue()))) {
        same = true;
    }

    return same;
}

From source file:de.escidoc.core.test.EscidocTestBase.java

/**
 * Returns a positive integer if ts1 depicts a time after ts2 (ts1 > ts2), 0 if ts1 and ts2 depict the same time
 * (ts1 == ts2), and a negative integer if if ts1 depicts a time before ts2 (ts1 < ts2).
 * //  w  ww.  j  a va 2 s .  c o  m
 * @param ts1
 *            The first timestamp.
 * @param ts2
 *            The second timestamp.
 * @return The comparison result.
 * @throws Exception
 *             If anything fails (e.g. one timstamp has incorrect format).
 */
public static int compareTimestamps(final String ts1, final String ts2) throws Exception {

    int result = 0;

    XMLGregorianCalendar date1 = DatatypeFactory.newInstance().newXMLGregorianCalendar(ts1);
    XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(ts2);

    int diff = date1.compare(date2);
    if (diff == DatatypeConstants.LESSER) {
        result = -1;
    } else if (diff == DatatypeConstants.GREATER) {
        result = 1;
    } else if (diff == DatatypeConstants.EQUAL) {
        result = 0;
    } else if (diff == DatatypeConstants.INDETERMINATE) {
        throw new Exception("Date comparing: INDETERMINATE");
    }

    return result;
}