Android Open Source - clinicalguide Stats Question Factory






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.stats;
//from   w ww .j av a2  s  .c  o  m
import java.util.ArrayList;

import org.get.oxicam.clinicalguide.ClinicalGuideActivity;
import org.get.oxicam.clinicalguide.xml.ParserHelper;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class StatsQuestionFactory {

    private static int typeInt = -1;
    /**
     * Creates the specific question object depending on the type attribute of
     * the question
     * 
     * @param e Element with a tagname "question"
     * @return A child class of FormStatsQuestion depending on the attributes and childnodes.
     */
    public static AbstractStatsQuestion createQuestion(Element e, ClinicalGuideActivity mActivity) {
  if (!e.getTagName().equalsIgnoreCase("question")) {
      throw new IllegalArgumentException("Not a question tag");
  }
  
  String type = ParserHelper.requiredAttributeGetter(e, "type");
  typeInt = AbstractStatsQuestion.getQuestionTypeInt(type);
  switch (typeInt) {
  case AbstractStatsQuestion.QUESTION_TYPE_COUNT:
      return createCountQuestion(e, mActivity);
  case AbstractStatsQuestion.QUESTION_TYPE_LIST:
      return createListQuestion(e, mActivity);
  case AbstractStatsQuestion.QUESTION_TYPE_MIN:
  case AbstractStatsQuestion.QUESTION_TYPE_MAX:
      return createExtremaQuestion(e, mActivity);
  case AbstractStatsQuestion.QUESTION_TYPE_PERCENTAGE:
      return createPercentageQuestion(e, mActivity);
  case AbstractStatsQuestion.QUESTION_TYPE_RATIO:
      return createRatioQuestion(e, mActivity);
  case AbstractStatsQuestion.QUESTION_TYPE_AVERAGE:
      return createAverageQuestion(e, mActivity);   
  default:
      throw new IllegalArgumentException("Question type not existing");
  }
    }
    
    private static AbstractStatsQuestion createListQuestion(Element e, ClinicalGuideActivity mActivity){
  AbstractStatsQuestion retVal = null;
  
  ArrayList<StatsSubject> arrSubj = new ArrayList<StatsSubject>();
  ArrayList<StatsConstraint> arrConst = new ArrayList<StatsConstraint>();
  StatsCompareConstraint compareConstraint = null;
  NodeList subjects = e.getElementsByTagName("subject");
  NodeList constraints = e.getElementsByTagName("statsconstraint");
  NodeList compareConstraintNodeList = e.getElementsByTagName("compareconstraint");
  NodeList timespan = e.getElementsByTagName("timespan");
  
  int subjLen = subjects.getLength();
  int constLen = constraints.getLength();
  int spanLen = timespan.getLength();
  int compLen = compareConstraintNodeList.getLength();
  
  if(spanLen > 1 || compLen > 1){
      throw new IllegalArgumentException("There can only be one timespan or 1 comparecontraint in a question");
  }
  
  for(int i = 0; i < subjLen; i++){
      arrSubj.add(ParserHelper.getStatsSubjectDetails((Element) subjects.item(i)));
  }
  
  for(int i = 0; i < constLen; i++){
      arrConst.add(ParserHelper.getStatsConstraintDetails((Element)constraints.item(i)));
  }
  
  if(compLen == 1){
      Element compConstNode = (Element)compareConstraintNodeList.item(0);
      compareConstraint = ParserHelper.getCompareConstraintDetails(compConstNode);
  }
  

  StatsTimespan qTimespan = spanLen == 1 ? ParserHelper.getTimespanDetails((Element)timespan.item(0)) : null;
  retVal = new StatsQuestionList(mActivity, arrSubj, e.getAttribute("distinct").equalsIgnoreCase("true"), arrConst, qTimespan, compareConstraint);    
  
  return retVal;
    }
    
    private static AbstractStatsQuestion createRatioQuestion(Element e, ClinicalGuideActivity mActivity){
  AbstractStatsQuestion retVal = null;
  
  ArrayList<StatsQuestionCount> arrCounts = new ArrayList<StatsQuestionCount>();
  ArrayList<StatsConstraint> arrConst = new ArrayList<StatsConstraint>();

  StatsCompareConstraint compareConstraint = null;
  NodeList counts = e.getElementsByTagName("count");
  NodeList constraints = e.getElementsByTagName("statsconstraint");
  NodeList timespan = e.getElementsByTagName("timespan");
  NodeList compareConstraintNodeList = e.getElementsByTagName("compareconstraint");
  
  int subjLen = counts.getLength();
  int constLen = constraints.getLength();
  int spanLen = timespan.getLength();
  int compLen = compareConstraintNodeList.getLength();
  
  if(spanLen > 1){
      throw new IllegalArgumentException("There can only be one timespan in a question");
  }
  
  for(int i = 0; i < subjLen; i++){
      arrCounts.add(createSubCountQuestion((Element) counts.item(i), mActivity));
  }
  
  for(int i = 0; i < constLen; i++){
      arrConst.add(ParserHelper.getStatsConstraintDetails((Element)constraints.item(i)));
  }
  

  if(compLen == 1){
      Element compConstNode = (Element)compareConstraintNodeList.item(0);
      compareConstraint = ParserHelper.getCompareConstraintDetails(compConstNode);
  }
  
  
  StatsTimespan qTimespan = spanLen == 1 ? ParserHelper.getTimespanDetails((Element)timespan.item(0)) : null;
  
  retVal = new StatsQuestionRatio(mActivity, arrCounts, arrConst, qTimespan, compareConstraint);
  return retVal;
    }
    
    private static StatsQuestionPercentage createPercentageQuestion(Element e, ClinicalGuideActivity mActivity){
  StatsQuestionPercentage retVal = null;
  StatsQuestionCount mainTarget = null;
  ArrayList<StatsQuestionCount> arrCounts = new ArrayList<StatsQuestionCount>();
  ArrayList<StatsConstraint> arrConst = new ArrayList<StatsConstraint>();

  StatsCompareConstraint compareConstraint = null;
  NodeList mainTargetList = e.getElementsByTagName("target");
  NodeList otherList = e.getElementsByTagName("others");
  NodeList constraints = e.getElementsByTagName("statsconstraint");
  NodeList timespan = e.getElementsByTagName("timespan");
  NodeList compareConstraintNodeList = e.getElementsByTagName("compareconstraint");
  
  int subjLen = mainTargetList.getLength();
  int otherLen = otherList.getLength();
  int constLen = constraints.getLength();
  int spanLen = timespan.getLength();
  int compLen = compareConstraintNodeList.getLength();
  
  if(spanLen > 1){
      throw new IllegalArgumentException("There can only be one timespan in a question");
  }
  
  if(subjLen != 1){
      throw new IllegalArgumentException("There should be one target in a percentage question");
  }
  
  mainTarget = createSubCountQuestion((Element)mainTargetList.item(0), mActivity);
  arrCounts.add(mainTarget);
  
  for(int i = 0; i < otherLen; i++){
      arrCounts.add(createSubCountQuestion((Element) otherList.item(i), mActivity));
  }
  
  for(int i = 0; i < constLen; i++){
      arrConst.add(ParserHelper.getStatsConstraintDetails((Element)constraints.item(i)));
  }
  

  if(compLen == 1){
      Element compConstNode = (Element)compareConstraintNodeList.item(0);
      compareConstraint = ParserHelper.getCompareConstraintDetails(compConstNode);
  }
  
  
  StatsTimespan qTimespan = spanLen == 1 ? ParserHelper.getTimespanDetails((Element)timespan.item(0)) : null;
  
  retVal = new StatsQuestionPercentage(mActivity, mainTarget, arrCounts, arrConst, qTimespan, compareConstraint);
  return retVal;
    }
    
    private static StatsQuestionCount createCountQuestion(Element e, ClinicalGuideActivity mActivity){
  
  StatsSubject distinctSubj = null;
  ArrayList<StatsConstraint> arrConst = new ArrayList<StatsConstraint>();
  StatsCompareConstraint compareConstraint = null;
  NodeList distinctNl = e.getElementsByTagName("distinct");
  NodeList constraints = e.getElementsByTagName("statsconstraint");
  NodeList compareConstraintNodeList = e.getElementsByTagName("compareconstraint");
  NodeList timespan = e.getElementsByTagName("timespan");
  
  int distinctLen = distinctNl.getLength();
  int constLen = constraints.getLength();
  int spanLen = timespan.getLength();
  int compLen = compareConstraintNodeList.getLength();
  
  if(spanLen > 1 || compLen > 1 || distinctLen > 1){
      throw new IllegalArgumentException("There can only be one timespan or 1 comparecontraint in a question");
  }
  
  if(distinctLen == 1){
      distinctSubj = ParserHelper.getStatsSubjectDetails((Element) distinctNl.item(0));
  }
  
  for(int i = 0; i < constLen; i++){
      arrConst.add(ParserHelper.getStatsConstraintDetails((Element)constraints.item(i)));
  }
  
  if(compLen == 1){
      Element compConstNode = (Element)compareConstraintNodeList.item(0);
      compareConstraint = ParserHelper.getCompareConstraintDetails(compConstNode);
  }
  

  StatsTimespan qTimespan = spanLen == 1 ? ParserHelper.getTimespanDetails((Element)timespan.item(0)) : null;
  String label = e.getAttribute("label");
  return new StatsQuestionCount(mActivity, label, distinctSubj, arrConst, qTimespan, compareConstraint);
    }
    
    private static StatsQuestionCount createSubCountQuestion(Element e, ClinicalGuideActivity mActivity){
  
  StatsSubject distinctSubj = null;
  ArrayList<StatsConstraint> arrConst = new ArrayList<StatsConstraint>();
  StatsCompareConstraint compareConstraint = null;
  NodeList distinctNl = e.getElementsByTagName("countdistinct");
  NodeList constraints = e.getElementsByTagName("countconstraint");
  NodeList compareConstraintNodeList = e.getElementsByTagName("countcompareconstraint");
  NodeList timespan = e.getElementsByTagName("counttimespan");
  
  int distinctLen = distinctNl.getLength();
  int constLen = constraints.getLength();
  int spanLen = timespan.getLength();
  int compLen = compareConstraintNodeList.getLength();
  
  if(spanLen > 1 || compLen > 1 || distinctLen > 1){
      throw new IllegalArgumentException("There can only be one timespan or 1 comparecontraint in a question");
  }
  
  if(distinctLen == 1){
      distinctSubj = ParserHelper.getStatsSubjectDetails((Element) distinctNl.item(0));
  }
  
  for(int i = 0; i < constLen; i++){
      arrConst.add(ParserHelper.getStatsConstraintDetails((Element)constraints.item(i)));
  }
  
  if(compLen == 1){
      Element compConstNode = (Element)compareConstraintNodeList.item(0);
      compareConstraint = ParserHelper.getCompareConstraintDetails(compConstNode);
  }
  

  StatsTimespan qTimespan = spanLen == 1 ? ParserHelper.getTimespanDetails((Element)timespan.item(0)) : null;
  String label = e.getAttribute("label");
  return new StatsQuestionCount(mActivity, label, distinctSubj, arrConst, qTimespan, compareConstraint);
    }
    
    private static AbstractStatsQuestion createAverageQuestion(Element e, ClinicalGuideActivity mActivity){
  AbstractStatsQuestion retVal = null;
  
  ArrayList<StatsSubject> arrSubj = new ArrayList<StatsSubject>();
  ArrayList<StatsConstraint> arrConst = new ArrayList<StatsConstraint>();
  StatsCompareConstraint compareConstraint = null;
  NodeList subjects = e.getElementsByTagName("subject");
  NodeList countQuestions = e.getElementsByTagName("count");
  NodeList constraints = e.getElementsByTagName("statsconstraint");
  NodeList compareConstraintNodeList = e.getElementsByTagName("compareconstraint");
  NodeList timespan = e.getElementsByTagName("timespan");

  int subjLen = subjects.getLength();
  int countLen = countQuestions.getLength();
  int constLen = constraints.getLength();
  int spanLen = timespan.getLength();
  int compLen = compareConstraintNodeList.getLength();
  
  if(spanLen > 1 || compLen > 1){
      throw new IllegalArgumentException("There can only be one timespan or 1 comparecontraint in a question");
  }
  
  

  if(compLen == 1){
      Element compConstNode = (Element)compareConstraintNodeList.item(0);
      compareConstraint = ParserHelper.getCompareConstraintDetails(compConstNode);
  }
  

  StatsTimespan qTimespan = spanLen == 1 ? ParserHelper.getTimespanDetails((Element)timespan.item(0)) : null;
  
  
  if(subjLen == 1){
      StatsSubject subj = ParserHelper.getStatsSubjectDetails((Element) subjects.item(0));
      retVal = new StatsQuestionAverage(mActivity, subj, arrConst, qTimespan, compareConstraint);
  } else if(countLen == 1){
      StatsQuestionCount countQuestion =createSubCountQuestion((Element) countQuestions.item(0), mActivity);
      retVal = new StatsQuestionAverage(mActivity, countQuestion, arrConst, qTimespan, compareConstraint);
  } else {
      throw new IllegalArgumentException("Average question can only have either 1 <subject> or 1 <count> tag");
  }
  
  for(int i = 0; i < subjLen; i++){
      arrSubj.add(ParserHelper.getStatsSubjectDetails((Element) subjects.item(i)));
  }
  
  for(int i = 0; i < constLen; i++){
      arrConst.add(ParserHelper.getStatsConstraintDetails((Element)constraints.item(i)));
  }
  
  
  
  return retVal;
    }
    
    
    private static StatsQuestionExtrema createExtremaQuestion(Element e, ClinicalGuideActivity mActivity){
  StatsQuestionExtrema retVal = null;
  
  ArrayList<StatsSubject> arrSubj = new ArrayList<StatsSubject>();
  ArrayList<StatsConstraint> arrConst = new ArrayList<StatsConstraint>();
  StatsCompareConstraint compareConstraint = null;
  NodeList subjects = e.getElementsByTagName("subject");
  NodeList countQuestions = e.getElementsByTagName("count");
  NodeList constraints = e.getElementsByTagName("statsconstraint");
  NodeList compareConstraintNodeList = e.getElementsByTagName("compareconstraint");
  NodeList timespan = e.getElementsByTagName("timespan");

  

  String type = ParserHelper.requiredAttributeGetter(e, "type");
  int extremaType = -1;
  type = type.trim();
  if(type.equalsIgnoreCase("max")){
      extremaType = StatsQuestionExtrema.MAX;
  } else if(type.equalsIgnoreCase("min")){
      extremaType = StatsQuestionExtrema.MIN;
  }
  int subjLen = subjects.getLength();
  int countLen = countQuestions.getLength();
  int constLen = constraints.getLength();
  int spanLen = timespan.getLength();
  int compLen = compareConstraintNodeList.getLength();
  
  if(spanLen > 1 || compLen > 1){
      throw new IllegalArgumentException("There can only be one timespan or 1 comparecontraint in a question");
  }
  
  
  if(compLen == 1){
      Element compConstNode = (Element)compareConstraintNodeList.item(0);
      compareConstraint = ParserHelper.getCompareConstraintDetails(compConstNode);
  }
  

  StatsTimespan qTimespan = spanLen == 1 ? ParserHelper.getTimespanDetails((Element)timespan.item(0)) : null;
  
  
  if(subjLen == 1){
      StatsSubject subj = ParserHelper.getStatsSubjectDetails((Element) subjects.item(0));
      retVal = new StatsQuestionExtrema(mActivity, extremaType, subj, arrConst, qTimespan, compareConstraint);
  } else if(countLen == 1){
      StatsQuestionCount countQuestion =createSubCountQuestion((Element) countQuestions.item(0), mActivity);
      retVal = new StatsQuestionExtrema(mActivity, extremaType, countQuestion, arrConst, qTimespan, compareConstraint);
  } else {
      throw new IllegalArgumentException("Extrema question can only have either 1 <subject> or 1 <count> tag");
  }
  
  for(int i = 0; i < subjLen; i++){
      arrSubj.add(ParserHelper.getStatsSubjectDetails((Element) subjects.item(i)));
  }
  
  for(int i = 0; i < constLen; i++){
      arrConst.add(ParserHelper.getStatsConstraintDetails((Element)constraints.item(i)));
  }
  
  
  
  return retVal;
    }

}




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