Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

de:userguide:formeditor:functions:graph_date_to_patient_age

changeGraphDateToPatientAge

/**
 * This function replaces the x-values, given as milliseconds since 1970
 * into the age of the patient in years at that point in time.
 * It returns an array of Range objects, that defines the dimensions
 * of the changed graph. 
 * 
 * NEEDED FUNCTIONS:
 *  - calculateAge
 * 
 * @param patientBirthday: 
 * The patients birthday as a java.util.Calendar
 * 
 * @param diagrammToChange: 
 * The diagram that contains the graph to change 
 * (this is a component created by adding a diagram to the form editor).
 * 
 * @param indexOfGraphToChange
 * The position of the graph in the diagram as int.
 * 
 * @return 
 * An array of org.jfree.data.Range objects, that define the dimensions 
 * of this graph. They're supposed to be used for centering the chart 
 * view on this graph. The range at position 0 defines the x-axis value, 
 * the range at position 1 defines the y-axis value.
 */
function changeGraphDateToPatientAge (
         patientBirthday, diagramToChange, indexOfGraphToChange) {
   /* ======================================== */
   // IMPORTS:
   importPackage(java.lang);
   importPackage(java.util);
   importPackage(org.jfree.chart);
   importPackage(org.jfree.data.xy);
   importPackage(org.jfree.data);
 
 
   // prepare the necessary objects
   var plot = diagramToChange.getChart().getXYPlot();
   var dataset = plot.getDataset();
   var series = dataset.getSeries(indexOfGraphToChange);
   var tempList = new LinkedList();
   var creationDate = new GregorianCalendar();
 
 
   /* to center the view in the diagramm on the patients data, 
    * we need to get the highest and lowest x- and y-values.
    */
   var highestX = 0;
   var highestY = 0;
   var lowestX = Integer.MAX_VALUE;
   var lowestY = Integer.MAX_VALUE;
 
   // replace the creation date with the patient's age in every row
   for (var iter = series.getItems().iterator(); iter.hasNext(); ) {
      /* ---------------------------------------- */
      var _item = iter.next();
 
      try {
         /* try to make a Date resp. Calendar out of the formated String.
          * If it fails, ignore this item
          */
         var long_newXValue = new Double(_item.getXValue()).longValue();
         creationDate.setTimeInMillis(long_newXValue);
      } catch (err) {
         // maybe you want to see want's happening here
         println("changeGraphDateToPatientAge(): " + err);
         continue;
      }
 
      // get the right values and add them as item to the tempList
      var y = _item.getYValue();
      // calculate the age
      var age = calculateAge(patientBirthday, creationDate);
      tempList.add(new XYDataItem(age, y));
 
      // check, if this value is the lowest or highest x- or y-value
      if (age < lowestX) {
         lowestX = age;
      } 
      if (age > highestX) {
         highestX = age; 
      }
      if (y < lowestY) {
         lowestY = y;
      } 
      if (y > highestY) {
         highestY = y;
      }
      /* ---------------------------------------- */
   }
 
   // put the changes values from the template list back into the series
   series.clear();
   for (var iter = tempList.iterator(); iter.hasNext(); ) {
      series.add(iter.next());
   }
 
   if (lowestX > highestX
         || lowestY > highestY) {
      return null;
   } else {
      return new Array(new Range(lowestX, highestX), new Range(lowestY, highestY));
   }
   /* ======================================== */
}
de/userguide/formeditor/functions/graph_date_to_patient_age.txt · Zuletzt geändert: 2019/12/09 10:19 (Externe Bearbeitung)

Seiten-Werkzeuge