Android Open Source - clinicalguide C G Stats Parser






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  a  v  a 2s .c o m*/
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.get.oxicam.clinicalguide.ClinicalGuideActivity;
import org.get.oxicam.clinicalguide.xml.stats.AbstractStatsQuestion;
import org.get.oxicam.clinicalguide.xml.stats.Stats;
import org.get.oxicam.clinicalguide.xml.stats.StatsQuestionFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class CGStatsParser {

  private final Document mDom;
  private Context clinicalGuideContext;
  private String statsName;

  public CGStatsParser(Context context) {
    Document document = null;
    this.clinicalGuideContext = context;
    
    String filename = "clinicalguidestats.xml";
    
    InputStream inputStream = XMLHandler.getDecryptedXMLInputStream(context,
        filename);
    if (inputStream != null) {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        document = db.parse(inputStream);
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          inputStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    if (document == null) {
      Log.e("Parser", "failed loading XML file");
    }
    mDom = document;
  }

  /**
   * Gets all the stats tags inside the clinicalguidestats.xml
   * 
   * @return A NodeList containing all form nodes inside clinicalguidestas.xml
   */
  private NodeList getStats() {
    return mDom.getElementsByTagName("stats");
  }

  /**
   * Populates the stats using a specific form id.
   * 
   * @param id The id of the stats to be populated.
   */
  public String populateStats(String id) {
    Element e = mDom.getElementById(id);
    String retVal = "";
    if (!e.getTagName().equals("stats")) {
      Toast.makeText(clinicalGuideContext,
          "Error! " + id + " is not an id of a <stats> tag",
          Toast.LENGTH_SHORT).show();
      return retVal;
    }

    statsName = ParserHelper.requiredAttributeGetter(e, "name");

    if (statsName != null) {
      Stats stats = new Stats(getQuestions(e), e.getAttribute("name"));
      StatsGenerator sqb = new StatsGenerator(clinicalGuideContext, stats);
      retVal = sqb.getStatsString();
    }

    return retVal;
  }

  private ArrayList<AbstractStatsQuestion> getQuestions(Element e) {
    ArrayList<AbstractStatsQuestion> retVal = new ArrayList<AbstractStatsQuestion>();
    NodeList nl = e.getElementsByTagName("question");
    int len = nl.getLength();
    for (int i = 0; i < len; i++) {
      retVal.add(StatsQuestionFactory.createQuestion((Element) nl.item(i), (ClinicalGuideActivity)clinicalGuideContext));
    }
    return retVal;
  }

  /**
   * Gets all stats names and its corresponding id that is inside
   * clinicalguidestats.xml
   * 
   * @return A HashMap<String,String> containing stats IDs as the keys and form
   *         names as the values.
   */
  public HashMap<String, String> getStatsNamesAndIds() {
    NodeList nl = getStats();
    HashMap<String, String> id_name = new LinkedHashMap<String, String>();
    int len = nl.getLength();
    for (int i = 0; i < len; i++) {
      String id = ParserHelper.requiredAttributeGetter((Element) nl.item(i), "id");
      String name = ParserHelper.requiredAttributeGetter((Element) nl.item(i), "name");
      if (id != null && name != null) {
        id_name.put(id, name);
      }
    }
    return id_name;
  }

  /**
   * Gets the stats ids that is inside clinicalguidestats.xml
   * 
   * @return Arraylist of String containing the ids of each stats in the clinicalguidestats.xml
   *         file.
   */
  public ArrayList<String> getStatsIds() {
    ArrayList<String> arr = new ArrayList<String>();
    NodeList nl = getStats();
    int len = nl.getLength();
    String str = "";
    for (int i = 0; i < len; i++) {
      String id = ParserHelper.requiredAttributeGetter((Element) nl.item(i), "id");
      if (id != null) {
        arr.add(id);
        str += (id + "\n");
      }
    }
    return arr;
  }

  /**
   * Gets the stats names that is inside clinicalguidestats.xml
   * 
   * @return Arraylist of String containing the names of each stats in the xml
   *         file.
   */
  public ArrayList<String> getStatsNames() {
    ArrayList<String> arr = new ArrayList<String>();
    NodeList nl = getStats();
    int len = nl.getLength();
    for (int i = 0; i < len; i++) {
      String name = ParserHelper.requiredAttributeGetter((Element) nl.item(i), "name");
      if (name != null) {
        arr.add(name);
      }
    }
    return arr;
  }

}




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