Android Open Source - clinicalguide Parser Helper






From Project

Back to project page clinicalguide.

License

The source code is released under:

Apache License

If you think the Android project clinicalguide listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.get.oxicam.clinicalguide.xml;
/* w w  w .j ava2  s  .c  om*/
import java.util.ArrayList;
import java.util.HashSet;

import org.get.oxicam.clinicalguide.xml.stats.StatsColumnCompare;
import org.get.oxicam.clinicalguide.xml.stats.StatsComparatorOperator;
import org.get.oxicam.clinicalguide.xml.stats.StatsCompareConstraint;
import org.get.oxicam.clinicalguide.xml.stats.StatsConstraint;
import org.get.oxicam.clinicalguide.xml.stats.StatsSubject;
import org.get.oxicam.clinicalguide.xml.stats.StatsTimespan;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ParserHelper {

    /**
     * Gets an attribute from s specified element. If the attribute is not found
     * or the attribute has an empty value, an exception will be thrown.
     * 
     * @param e The element to get the attribute from.
     * @param attr Attribute name to get from the element.
     * @return The attribute value or null if it is not found or no value is defined.
     */
    public static String requiredAttributeGetter(Element e, String attr) {
  String retVal = null;
  retVal = e.getAttribute(attr);

  if (retVal.isEmpty()) {
      String tagName = e.getTagName();
      String str = "ERROR! <" + tagName + "> has no attribute [" + attr
        + "]";
      throw new IllegalArgumentException(str);
  }

  return retVal;
    }

    /**
     * Gets details from an element that acts like a subject.
     * The element must have attributes "columnname" and "tablename"
     * @param e The Element that has "columnname" and "tablename" attribute.
     * @return StatsQuestionSubject object with the columnname and tablename.
     */
    public static StatsSubject getStatsSubjectDetails(Element e) {
  String columnname = requiredAttributeGetter(e, "columnname");
  String tablename = requiredAttributeGetter(e, "tablename");
  return new StatsSubject(tablename, columnname);
    }

    /**
     * Gets details from an element that acts like a subject.
     * The element must have attributes "columnname", "tablename", "data" and an optional "operator"
     * @param e The Element that has "columnname", "tablename", "data" and an optional "operator" attributes.
     * @return FormConstraint object with the columnname, tablename, data and operator.
     */
    public static StatsConstraint getStatsConstraintDetails(Element e) {
  String columnname = requiredAttributeGetter(e, "columnname");
  String tablename = requiredAttributeGetter(e, "tablename");
  String data = requiredAttributeGetter(e, "data");
  String operator = e.getAttribute("operator");
  if(operator.isEmpty()){
      operator = "equal";
  }
  return new StatsConstraint(tablename, columnname, data, new StatsComparatorOperator(operator));
    }
    
    /**
     * Gets timespan details.
     * "type" attribute is mandatory. "group" and "adjust" are optional,
     * @param e The timespan element
     * @return Timespan object
     */
    public static StatsTimespan getTimespanDetails(Element e) {
  StatsTimespan retVal = null;
  String type = requiredAttributeGetter(e, "type");
  String group = "";
  String total = "";
  String adjust = "";
  int adjustInt = 0;
  if (!type.isEmpty()) {
      group = e.getAttribute("group");
      adjust = e.getAttribute("adjust");
      if (!adjust.isEmpty()) {
    adjustInt = Integer.parseInt(adjust);
      }
      retVal = new StatsTimespan(type, group, adjustInt);
  }
  return retVal;
    }

    /**
     * Checks if the arraylist contains more than one distinct table.
     * 
     * @param constraints
     * @return True if you will need more than one table (needs joining). False otherwise.
     */
    public static boolean moreThanOneTable(
      ArrayList<? extends StatsSubject> constraints) {
  HashSet<String> set = new HashSet<String>();
  int len = constraints.size();
  for (int i = 0; i < len; i++) {
      StatsSubject fc = constraints.get(i);
      if (set.add(fc.tablename) && set.size() > 1) {
    return true;
      }
  }
  return false;

    }

    /**
     * Gets compare constraint.
     * Element should have childnodes"lefthandside", "righthandside", and "comparator".
     * @param e The element that has childnodes"lefthandside", "righthandside", and "comparator"
     * @return CompareConstraint object.
     */
    public static StatsCompareConstraint getCompareConstraintDetails(Element e) {
  StatsCompareConstraint retVal = null;
  NodeList lhsList = e.getElementsByTagName("lefthandside");
  NodeList rhsList = e.getElementsByTagName("righthandside");
  NodeList signList = e.getElementsByTagName("comparator");
  int lhsLen = lhsList.getLength();
  int rhsLen = rhsList.getLength();
  int signLen = signList.getLength();

  if (lhsLen != 1 || rhsLen != 1 || signLen != 1) {
      throw new IllegalArgumentException(
        "compareconstraint should have one lefthandside, righthandside and comparator child");
  }

  Element signNode = (Element) signList.item(0);
  Element lhsNode = (Element) lhsList.item(0);
  Element rhsNode = (Element) rhsList.item(0);

  int lhsChildLen = lhsNode.getChildNodes().getLength();
  int rhsChildLen = rhsNode.getChildNodes().getLength();
  int signChildLen = signNode.getChildNodes().getLength();
  
  if (lhsChildLen != rhsChildLen && rhsChildLen != signChildLen) {
      throw new IllegalArgumentException(
        "left hand side, right hand side, and comparator should have the same number of child");
  }

  retVal = new StatsCompareConstraint(getCompareSideDetails(lhsNode),
    getCompareSideDetails(rhsNode), getComparator(signNode));

  return retVal;
    }

    /**
     * Gets the details for either lefthandside or righthandside of compareconstraint/
     * @param e The "lefthandside" or "righthandside" element that has a childnode "columncompare"
     * @return arraylist of column compare that has been generated depending on the details of the element passed in
     */
    private static ArrayList<StatsColumnCompare> getCompareSideDetails(
      Element e) {
  ArrayList<StatsColumnCompare> retVal = new ArrayList<StatsColumnCompare>();
  NodeList nl = e.getChildNodes();
  int len = nl.getLength();
  for (int i = 0; i < len; i++) {
      Node node = nl.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE) {

    Element child = (Element) node;
    if (child.getTagName().equalsIgnoreCase("columncompare")) {
        retVal.add(getColumnCompare(child));
    } 
    else {
        throw new IllegalArgumentException(
          "left hand side and right hand side can only have columncompare child");
    }
      }
  }
  return retVal;
    }
    /**
     * Gets comparator objects.
     * The element passed in should have a childnode "operator" and that child node should have attribute  "type"
     * @param e The element that has a childnode "operator"
     * @return Arraylist of StatsCOmparatorOperator that has been constructed depending on the "type" attribute of the "operator" tag
     */
    private static ArrayList<StatsComparatorOperator> getComparator(Element e){
  ArrayList<StatsComparatorOperator> retVal = new ArrayList<StatsComparatorOperator>();
  NodeList nl = e.getElementsByTagName("operator");
  int len = nl.getLength();
  
  for(int i = 0; i < len; i++){
      Element child = (Element)nl.item(i);
      retVal.add(new StatsComparatorOperator(requiredAttributeGetter(child, "type")));
  }
  return retVal;
    }

    private static StatsColumnCompare getColumnCompare(Element e) {
  String columnname = requiredAttributeGetter(e, "columnname");
  String tablename = requiredAttributeGetter(e, "tablename");
  return new StatsColumnCompare(tablename, columnname);
    }
    
}




Java Source Code List

.PatientDetailsDataSource.java
org.get.oxicam.clinicalguide.ClinicalGuideActivity.java
org.get.oxicam.clinicalguide.FileUtils.java
org.get.oxicam.clinicalguide.LoginActivity.java
org.get.oxicam.clinicalguide.db.DatabaseHelper.java
org.get.oxicam.clinicalguide.db.Database.java
org.get.oxicam.clinicalguide.db.FollowupDataSource.java
org.get.oxicam.clinicalguide.db.FollowupDetails.java
org.get.oxicam.clinicalguide.db.FollowupSQLHelper.java
org.get.oxicam.clinicalguide.db.HistoryDetailsDataSource.java
org.get.oxicam.clinicalguide.db.HistoryDetailsSQLHelper.java
org.get.oxicam.clinicalguide.db.HistoryDetails.java
org.get.oxicam.clinicalguide.db.PatientDetailsSQLHelper.java
org.get.oxicam.clinicalguide.db.PatientDetails.java
org.get.oxicam.clinicalguide.db.RegistrationValidator.java
org.get.oxicam.clinicalguide.db.Validator.java
org.get.oxicam.clinicalguide.encryption.Encryption.java
org.get.oxicam.clinicalguide.ui.AnswersReviewFragment.java
org.get.oxicam.clinicalguide.ui.AssessmentDetailFragment.java
org.get.oxicam.clinicalguide.ui.ClassificationFragment.java
org.get.oxicam.clinicalguide.ui.ClassificationListItem.java
org.get.oxicam.clinicalguide.ui.DatePickerFragment.java
org.get.oxicam.clinicalguide.ui.ExportFragment.java
org.get.oxicam.clinicalguide.ui.ExportscreenListItem.java
org.get.oxicam.clinicalguide.ui.FollowUpFragment.java
org.get.oxicam.clinicalguide.ui.FormScreenFragment.java
org.get.oxicam.clinicalguide.ui.HomescreenFragment.java
org.get.oxicam.clinicalguide.ui.HomescreenListItem.java
org.get.oxicam.clinicalguide.ui.ListItemOnClickListener.java
org.get.oxicam.clinicalguide.ui.MainSymptomFragment.java
org.get.oxicam.clinicalguide.ui.MainSymptomListItem.java
org.get.oxicam.clinicalguide.ui.NumberTickerValueChangeListener.java
org.get.oxicam.clinicalguide.ui.NumberTicker.java
org.get.oxicam.clinicalguide.ui.PatientDetailsFragment.java
org.get.oxicam.clinicalguide.ui.PatientHistoryFragment.java
org.get.oxicam.clinicalguide.ui.PatientsFragment.java
org.get.oxicam.clinicalguide.ui.QuestionListItem.java
org.get.oxicam.clinicalguide.ui.QuestionnaireFragment.java
org.get.oxicam.clinicalguide.ui.StatScreenFragment.java
org.get.oxicam.clinicalguide.ui.SummaryScreenFragment.java
org.get.oxicam.clinicalguide.ui.TextViewCustomFont.java
org.get.oxicam.clinicalguide.ui.TreatmentConfirmationDialog.java
org.get.oxicam.clinicalguide.ui.TreatmentFragment.java
org.get.oxicam.clinicalguide.ui.TreatmentListItem.java
org.get.oxicam.clinicalguide.ui.ViewDetailScreenFragment.java
org.get.oxicam.clinicalguide.xml.CGFormParser.java
org.get.oxicam.clinicalguide.xml.CGParser.java
org.get.oxicam.clinicalguide.xml.CGStatsParser.java
org.get.oxicam.clinicalguide.xml.DateHelper.java
org.get.oxicam.clinicalguide.xml.FormGenerator.java
org.get.oxicam.clinicalguide.xml.ParserHelper.java
org.get.oxicam.clinicalguide.xml.StatsGenerator.java
org.get.oxicam.clinicalguide.xml.XMLHandler.java
org.get.oxicam.clinicalguide.xml.data.AbstractAnswer.java
org.get.oxicam.clinicalguide.xml.data.Annotation.java
org.get.oxicam.clinicalguide.xml.data.AnswerValidator.java
org.get.oxicam.clinicalguide.xml.data.Answer.java
org.get.oxicam.clinicalguide.xml.data.Assessment.java
org.get.oxicam.clinicalguide.xml.data.CombinedAnswer.java
org.get.oxicam.clinicalguide.xml.data.FollowUp.java
org.get.oxicam.clinicalguide.xml.data.FormQuery.java
org.get.oxicam.clinicalguide.xml.data.Info.java
org.get.oxicam.clinicalguide.xml.data.Option.java
org.get.oxicam.clinicalguide.xml.data.PatientAttribute.java
org.get.oxicam.clinicalguide.xml.data.Question.java
org.get.oxicam.clinicalguide.xml.data.Questionnaire.java
org.get.oxicam.clinicalguide.xml.data.SimpleAnswer.java
org.get.oxicam.clinicalguide.xml.data.Symptom.java
org.get.oxicam.clinicalguide.xml.data.TreatmentAction.java
org.get.oxicam.clinicalguide.xml.data.Treatment.java
org.get.oxicam.clinicalguide.xml.data.User.java
org.get.oxicam.clinicalguide.xml.forms.FormCell.java
org.get.oxicam.clinicalguide.xml.forms.FormColumn.java
org.get.oxicam.clinicalguide.xml.forms.FormDuration.java
org.get.oxicam.clinicalguide.xml.forms.Form.java
org.get.oxicam.clinicalguide.xml.query.QueryHelper.java
org.get.oxicam.clinicalguide.xml.query.QueryResultCell.java
org.get.oxicam.clinicalguide.xml.query.QueryResultRow.java
org.get.oxicam.clinicalguide.xml.query.QueryResultTable.java
org.get.oxicam.clinicalguide.xml.stats.AbstractStatsQuestion.java
org.get.oxicam.clinicalguide.xml.stats.StatsAnswerHolder.java
org.get.oxicam.clinicalguide.xml.stats.StatsColumnCompare.java
org.get.oxicam.clinicalguide.xml.stats.StatsComparatorOperator.java
org.get.oxicam.clinicalguide.xml.stats.StatsCompareConstraint.java
org.get.oxicam.clinicalguide.xml.stats.StatsConstraint.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionAverage.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionCount.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionExtrema.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionFactory.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionList.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionPercentage.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionRatio.java
org.get.oxicam.clinicalguide.xml.stats.StatsSubject.java
org.get.oxicam.clinicalguide.xml.stats.StatsTimespan.java
org.get.oxicam.clinicalguide.xml.stats.Stats.java