コード例 #1
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  public static List<Question> listAllByTabs(List<Tab> tabs) {

    if (tabs == null || tabs.size() == 0) {
      return new ArrayList();
    }

    Iterator<Tab> iterator = tabs.iterator();
    In in =
        Condition.column(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB))
            .in(Long.toString(iterator.next().getId_tab()));
    while (iterator.hasNext()) {
      in.and(Long.toString(iterator.next().getId_tab()));
    }

    return new Select()
        .from(Question.class)
        .as("q")
        .join(Header.class, Join.JoinType.LEFT)
        .as("h")
        .on(
            Condition.column(ColumnAlias.columnWithTable("q", Question$Table.ID_HEADER))
                .eq(ColumnAlias.columnWithTable("h", Header$Table.ID_HEADER)))
        .join(Tab.class, Join.JoinType.LEFT)
        .as("t")
        .on(
            Condition.column(ColumnAlias.columnWithTable("h", Header$Table.ID_TAB))
                .eq(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB)))
        .where(in)
        .orderBy(Tab$Table.ORDER_POS)
        .orderBy(Question$Table.ORDER_POS)
        .queryList();
  }
コード例 #2
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  /**
   * Returns all the questions that belongs to a program
   *
   * @param tabGroup
   * @return
   */
  public static List<Question> listByTabGroup(TabGroup tabGroup) {
    if (tabGroup == null || tabGroup.getId_tab_group() == null) {
      return new ArrayList();
    }

    // return Question.findWithQuery(Question.class, LIST_ALL_BY_PROGRAM,
    // program.getId().toString());

    return new Select()
        .all()
        .from(Question.class)
        .as("q")
        .join(Header.class, Join.JoinType.LEFT)
        .as("h")
        .on(
            Condition.column(ColumnAlias.columnWithTable("q", Question$Table.ID_HEADER))
                .eq(ColumnAlias.columnWithTable("h", Header$Table.ID_HEADER)))
        .join(Tab.class, Join.JoinType.LEFT)
        .as("t")
        .on(
            Condition.column(ColumnAlias.columnWithTable("h", Header$Table.ID_TAB))
                .eq(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB)))
        .join(TabGroup.class, Join.JoinType.LEFT)
        .as("tg")
        .on(
            Condition.column(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB_GROUP))
                .eq(ColumnAlias.columnWithTable("tg", TabGroup$Table.ID_TAB_GROUP)))
        .where(
            Condition.column(ColumnAlias.columnWithTable("tg", TabGroup$Table.ID_TAB_GROUP))
                .eq(tabGroup.getId_tab_group()))
        .orderBy(Tab$Table.ORDER_POS)
        .orderBy(Question$Table.ORDER_POS)
        .queryList();
  }
コード例 #3
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  /**
   * Gets the value of this question in the given Survey
   *
   * @param idSurvey
   * @return
   */
  public Value getValueBySurvey(float idSurvey) {
    List<Value> returnValues =
        new Select()
            .from(Value.class)
            .indexedBy("Value_id_survey")
            .where(Condition.column(Value$Table.ID_QUESTION).eq(this.getId_question()))
            .and(Condition.column(Value$Table.ID_SURVEY).eq(idSurvey))
            .queryList();

    if (returnValues.size() == 0) {
      return null;
    } else {
      return returnValues.get(0);
    }
  }
コード例 #4
0
  @Override
  @Background
  public void loadListFromFavorite() {
    try {
      String providerUri =
          preferences
              .provider()
              .get()
              .replace(Providers.SCHEME_HTTPS, "")
              .replace(Providers.SCHEME_HTTP, "");

      List<FavoriteImage> favoriteImages =
          new Select()
              .from(FavoriteImage.class)
              .where(Condition.column(FavoriteImage$Table.PREVIEWURL).like("%" + providerUri + "%"))
              .orderBy(false, FavoriteImage$Table.LAST)
              .queryList();
      for (Image image : favoriteImages) {
        this.images.add(image);
      }
      notifyDataSetChanged();
      if (this.images.size() == 0 && context != null) {
        ((MainActivity) context).makeToast(R.string.no_favorite);
        ((MainActivity) context).clearFavoriteMode();
      }
    } catch (Exception e) {
      e.printStackTrace();
      onError(e.getMessage());
    }
  }
コード例 #5
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
 public boolean hasParent() {
   if (parent == null) {
     long countChildQuestionRelations =
         new Select()
             .count()
             .from(QuestionRelation.class)
             .indexedBy("QuestionRelation_operation")
             .where(Condition.column(QuestionRelation$Table.ID_QUESTION).eq(this.getId_question()))
             .and(
                 Condition.column(QuestionRelation$Table.OPERATION)
                     .eq(QuestionRelation.PARENT_CHILD))
             .count();
     parent = countChildQuestionRelations > 0;
   }
   return parent;
 }
コード例 #6
0
  private void init() {
    int tipoRelatorio = getIntent().getIntExtra(RelatoriosView.EXTRA_TIPO_RELATORIO, 0);
    if (tipoRelatorio <= 0) return;

    String nomeColuna = null;
    if (tipoRelatorio == RelatoriosView.TIPO_REL_ALT_DURACAO_SONO) {
      nomeColuna = PerfilFisico$Table.ALTERACAODSONO;
    } else if (tipoRelatorio == RelatoriosView.TIPO_REL_ALT_DURACAO_JORNADA_TRABALHO) {
      nomeColuna = PerfilFisico$Table.ALTERACAODJTRABALHO;
    } else if (tipoRelatorio == RelatoriosView.TIPO_REL_ALT_PESO) {
      nomeColuna = PerfilFisico$Table.ALTERACAOPESO;
    } else if (tipoRelatorio == RelatoriosView.TIPO_REL_ALT_TIPO_ALIMENTACAO) {
      nomeColuna = PerfilFisico$Table.ALTERACAOTALIMENTACAO;
    }

    final List<PerfilFisico> perfilFisicos =
        new Select()
            .from(PerfilFisico.class)
            .where(Condition.column(nomeColuna).eq(true))
            .queryList();
    if (perfilFisicos.size() <= 0) return;

    List<CharSequence> listaNomes = new ArrayList<CharSequence>();

    if (tipoRelatorio == RelatoriosView.TIPO_REL_ALT_DURACAO_SONO) {
      for (PerfilFisico pf : perfilFisicos) {
        String s =
            String.format("Duração Sono: %s em %s", pf.getDuracaoSonoAsString(), pf.dataAlteracao);
        listaNomes.add(s);
      }
    } else if (tipoRelatorio == RelatoriosView.TIPO_REL_ALT_TIPO_ALIMENTACAO) {
      for (PerfilFisico pf : perfilFisicos) {
        String s =
            String.format(
                "Tipo Alimentação: %s em %s", pf.getTipoAlimentacaoAsString(), pf.dataAlteracao);
        listaNomes.add(s);
      }
    } else if (tipoRelatorio == RelatoriosView.TIPO_REL_ALT_PESO) {
      for (PerfilFisico pf : perfilFisicos) {
        String s = String.format("Peso: %.2f em %s", pf.peso, pf.dataAlteracao);
        listaNomes.add(s);
      }
    } else if (tipoRelatorio == RelatoriosView.TIPO_REL_ALT_DURACAO_JORNADA_TRABALHO) {
      for (PerfilFisico pf : perfilFisicos) {
        String s =
            String.format(
                "Jornada Trabalho: %s em %s",
                pf.getDuracaoJornadaTrabalhoAsString(), pf.dataAlteracao);
        listaNomes.add(s);
      }
    }

    final ArrayAdapter adapter =
        new ArrayAdapter<CharSequence>(this, android.R.layout.simple_list_item_1, listaNomes);

    final ListView alteracoesListView =
        (ListView) findViewById(R.id.activity_relatorio_relatorios_list);

    alteracoesListView.setAdapter(adapter);
  }
コード例 #7
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  public List<Question> getChildren() {
    if (this.children == null) {

      List<Match> matches = getMatches();
      if (matches.size() == 0) {
        this.children = new ArrayList<>();
        return this.children;
      }

      Iterator<Match> matchesIterator = matches.iterator();
      In in =
          Condition.column(ColumnAlias.columnWithTable("m", Match$Table.ID_MATCH))
              .in(Long.toString(matchesIterator.next().getId_match()));
      while (matchesIterator.hasNext()) {
        in.and(Long.toString(matchesIterator.next().getId_match()));
      }

      // Select question from questionrelation where operator=1 and id_match in (..)
      this.children =
          new Select()
              .from(Question.class)
              .as("q")
              // Question + QuestioRelation
              .join(QuestionRelation.class, Join.JoinType.LEFT)
              .as("qr")
              .on(
                  Condition.column(ColumnAlias.columnWithTable("q", Question$Table.ID_QUESTION))
                      .eq(ColumnAlias.columnWithTable("qr", QuestionRelation$Table.ID_QUESTION)))
              // +Match
              .join(Match.class, Join.JoinType.LEFT)
              .as("m")
              .on(
                  Condition.column(
                          ColumnAlias.columnWithTable(
                              "qr", QuestionRelation$Table.ID_QUESTION_RELATION))
                      .eq(ColumnAlias.columnWithTable("m", Match$Table.ID_QUESTION_RELATION)))
              // Parent child relationship
              .where(in)
              // In clause
              .and(
                  Condition.column(
                          ColumnAlias.columnWithTable("qr", QuestionRelation$Table.OPERATION))
                      .eq(QuestionRelation.PARENT_CHILD))
              .queryList();
    }
    return this.children;
  }
コード例 #8
0
 static void sendEventChanges(DhisApi dhisApi) throws APIException {
   List<Event> events =
       new Select()
           .from(Event.class)
           .where(Condition.column(Event$Table.FROMSERVER).is(false))
           .queryList();
   sendEventChanges(dhisApi, events);
 }
コード例 #9
0
 @Override
 public TrackedEntity queryByUid(String uid) {
   TrackedEntity$Flow trackedEntityFlow =
       new Select()
           .from(TrackedEntity$Flow.class)
           .where(Condition.column(TrackedEntity$Flow$Table.UID).is(uid))
           .querySingle();
   return TrackedEntity$Flow.toModel(trackedEntityFlow);
 }
コード例 #10
0
  private static void updateEventReferences(long localId, String newReference) {
    new Update(DataValue.class)
        .set(Condition.column(DataValue$Table.EVENT).is(newReference))
        .where(Condition.column(DataValue$Table.LOCALEVENTID).is(localId))
        .async()
        .execute();

    new Update(Event.class)
        .set(
            Condition.column(Event$Table.EVENT).is(newReference),
            Condition.column(Event$Table.FROMSERVER).is(true))
        .where(Condition.column(Event$Table.LOCALID).is(localId))
        .async()
        .execute();
    Event event = new Event();
    event.save();
    event.delete(); // for triggering modelchangelistener
  }
コード例 #11
0
  private static void updateEnrollmentReferences(long localId, String newReference) {
    // updating any local events that had reference to local enrollment to new
    // reference from server.
    Log.d(CLASS_TAG, "updating enrollment references");
    new Update(Event.class)
        .set(Condition.column(Event$Table.ENROLLMENT).is(newReference))
        .where(Condition.column(Event$Table.LOCALENROLLMENTID).is(localId))
        .async()
        .execute();

    new Update(Enrollment.class)
        .set(
            Condition.column(Enrollment$Table.ENROLLMENT).is(newReference),
            Condition.column(Enrollment$Table.FROMSERVER).is(true))
        .where(Condition.column(Enrollment$Table.LOCALID).is(localId))
        .async()
        .execute();
  }
コード例 #12
0
 static void sendTrackedEntityInstanceChanges(DhisApi dhisApi, boolean sendEnrollments)
     throws APIException {
   List<TrackedEntityInstance> trackedEntityInstances =
       new Select()
           .from(TrackedEntityInstance.class)
           .where(Condition.column(TrackedEntityInstance$Table.FROMSERVER).is(false))
           .queryList();
   sendTrackedEntityInstanceChanges(dhisApi, trackedEntityInstances, sendEnrollments);
 }
コード例 #13
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
 public List<Match> getMatches() {
   if (matches == null) {
     matches =
         new Select()
             .from(Match.class)
             .as("m")
             .join(QuestionOption.class, Join.JoinType.LEFT)
             .as("qo")
             .on(
                 Condition.column(ColumnAlias.columnWithTable("m", Match$Table.ID_MATCH))
                     .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_MATCH)))
             .where(
                 Condition.column(
                         ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_QUESTION))
                     .eq(this.getId_question()))
             .queryList();
   }
   return matches;
 }
コード例 #14
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
 public Question getQuestion() {
   if (question == null) {
     question =
         new Select()
             .from(Question.class)
             .where(Condition.column(Question$Table.ID_QUESTION).is(id_parent))
             .querySingle();
   }
   return question;
 }
コード例 #15
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
 public Answer getAnswer() {
   if (answer == null) {
     if (id_answer == null) return null;
     answer =
         new Select()
             .from(Answer.class)
             .where(Condition.column(Answer$Table.ID_ANSWER).is(id_answer))
             .querySingle();
   }
   return answer;
 }
コード例 #16
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
 public Header getHeader() {
   if (header == null) {
     if (id_header == null) return null;
     header =
         new Select()
             .from(Header.class)
             .where(Condition.column(Header$Table.ID_HEADER).is(id_header))
             .querySingle();
   }
   return header;
 }
コード例 #17
0
 @Override
 public List<ProgramStageSection> query(ProgramStage programStage) {
   List<ProgramStageSection$Flow> programStageSectionFlows =
       new Select()
           .from(ProgramStageSection$Flow.class)
           .where(
               Condition.column(ProgramStageSection$Flow$Table.PROGRAMSTAGE)
                   .is(programStage.getUId()))
           .queryList();
   return getMapper().mapToModels(programStageSectionFlows);
 }
コード例 #18
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
 public List<QuestionRelation> getQuestionRelations() {
   if (questionRelations == null) {
     this.questionRelations =
         new Select()
             .from(QuestionRelation.class)
             .indexedBy("QuestionRelation_id_question")
             .where(Condition.column(QuestionRelation$Table.ID_QUESTION).eq(this.getId_question()))
             .queryList();
   }
   return this.questionRelations;
 }
コード例 #19
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
 public CompositeScore getCompositeScore() {
   if (compositeScore == null) {
     if (id_composite_score == null) return null;
     compositeScore =
         new Select()
             .from(CompositeScore.class)
             .where(
                 Condition.column(CompositeScore$Table.ID_COMPOSITE_SCORE).is(id_composite_score))
             .querySingle();
   }
   return compositeScore;
 }
コード例 #20
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  /**
   * Checks if this question is triggered according to the current values of the given survey. Only
   * applies to question with answers DROPDOWN_DISABLED
   *
   * @param idSurvey
   * @return
   */
  public boolean isTriggered(float idSurvey) {

    // Only disabled dropdowns
    if (this.getOutput() != Constants.DROPDOWN_LIST_DISABLED) {
      return false;
    }

    // Find questionoptions for q1 and q2 and check same match
    List<QuestionOption> questionOptions =
        new Select()
            .from(QuestionOption.class)
            .as("qo")
            .join(Match.class, Join.JoinType.LEFT)
            .as("m")
            .on(
                Condition.column(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_MATCH))
                    .eq(ColumnAlias.columnWithTable("m", Match$Table.ID_MATCH)))
            .join(QuestionRelation.class, Join.JoinType.LEFT)
            .as("qr")
            .on(
                Condition.column(ColumnAlias.columnWithTable("m", Match$Table.ID_QUESTION_RELATION))
                    .eq(
                        ColumnAlias.columnWithTable(
                            "qr", QuestionRelation$Table.ID_QUESTION_RELATION)))
            .join(Value.class, Join.JoinType.LEFT)
            .as("v")
            .on(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_QUESTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_QUESTION)),
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_OPTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_OPTION)))
            .where(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_SURVEY))
                    .eq(idSurvey))
            .and(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.ID_QUESTION))
                    .eq(this.getId_question()))
            .and(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.OPERATION))
                    .eq(Constants.OPERATION_TYPE_MATCH))
            .queryList();

    // No values no match
    if (questionOptions.size() != 2) {
      return false;
    }

    // Match is triggered if questionoptions have same matchid
    long idmatchQ1 = questionOptions.get(0).getMatch().getId_match();
    long idmatchQ2 = questionOptions.get(1).getMatch().getId_match();
    return idmatchQ1 == idmatchQ2;
  }
コード例 #21
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
 @OneToMany(
     methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE},
     variableName = "values")
 public List<Value> getValues() {
   if (values == null) {
     values =
         new Select()
             .from(Value.class)
             .where(Condition.column(Value$Table.ID_QUESTION).eq(this.getId_question()))
             .queryList();
   }
   return values;
 }
コード例 #22
0
  @Override
  public List<DashboardItem> queryByDashboard(Dashboard dashboard) {
    isNull(dashboard, "Dashboard must not be null");

    List<DashboardItem$Flow> dashboardItemFlows =
        new Select()
            .from(DashboardItem$Flow.class)
            .where(
                Condition.column(DashboardItem$Flow$Table.DASHBOARD_DASHBOARD)
                    .is(dashboard.getId()))
            .queryList();

    return getMapper().mapToModels(dashboardItemFlows);
  }
コード例 #23
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  /**
   * Checks if this question is shown according to the values of the given survey
   *
   * @param idSurvey
   * @return
   */
  public boolean isHiddenBySurvey(float idSurvey) {
    // No question relations
    if (!hasParent()) {
      return false;
    }
    long hasParentOptionActivated =
        new Select()
            .count()
            .from(Value.class)
            .as("v")
            .join(QuestionOption.class, Join.JoinType.LEFT)
            .as("qo")
            .on(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_QUESTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_QUESTION)),
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_OPTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_OPTION)))
            .join(Match.class, Join.JoinType.LEFT)
            .as("m")
            .on(
                Condition.column(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_MATCH))
                    .eq(ColumnAlias.columnWithTable("m", Match$Table.ID_MATCH)))
            .join(QuestionRelation.class, Join.JoinType.LEFT)
            .as("qr")
            .on(
                Condition.column(ColumnAlias.columnWithTable("m", Match$Table.ID_QUESTION_RELATION))
                    .eq(
                        ColumnAlias.columnWithTable(
                            "qr", QuestionRelation$Table.ID_QUESTION_RELATION)))
            // Parent child relationship
            .where(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.OPERATION))
                    .eq(1))
            // For the given survey
            .and(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_SURVEY))
                    .eq(idSurvey))
            // The child question in the relationship is 'this'
            .and(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.ID_QUESTION))
                    .eq(this.getId_question()))
            .count();

    // Parent with the right value -> not hidden
    return hasParentOptionActivated > 0 ? false : true;
  }
コード例 #24
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  /**
   * Checks if a unique question UID is shown according to the values of the given survey
   *
   * @param uid
   * @param id_survey
   * @return
   */
  public static boolean isHiddenQuestionByUidAndSurvey(String uid, Long id_survey) {
    // get question by uid
    Question question = getQuestionByUid(uid);
    if (question == null) return false;

    Long id_question = question.getId_question();
    long hasParentOptionActivated =
        new Select()
            .count()
            .from(Value.class)
            .as("v")
            .join(QuestionOption.class, Join.JoinType.LEFT)
            .as("qo")
            .on(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_QUESTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_QUESTION)),
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_OPTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_OPTION)))
            .join(Match.class, Join.JoinType.LEFT)
            .as("m")
            .on(
                Condition.column(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_MATCH))
                    .eq(ColumnAlias.columnWithTable("m", Match$Table.ID_MATCH)))
            .join(QuestionRelation.class, Join.JoinType.LEFT)
            .as("qr")
            .on(
                Condition.column(ColumnAlias.columnWithTable("m", Match$Table.ID_QUESTION_RELATION))
                    .eq(
                        ColumnAlias.columnWithTable(
                            "qr", QuestionRelation$Table.ID_QUESTION_RELATION)))
            // Parent child relationship
            .where(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.OPERATION))
                    .eq(1))
            // For the given survey
            .and(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_SURVEY))
                    .eq(id_survey))
            // The child question in the relationship is 'this'
            .and(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.ID_QUESTION))
                    .eq(id_question))
            .count();
    return hasParentOptionActivated > 0 ? false : true;
  }
コード例 #25
0
 @Override
 public boolean delete(ProgramStageSection object) {
   List<ProgramIndicatorToProgramStageSectionRelation$Flow>
       programIndicatorToProgramStageSectionRelationFlows =
           new Select()
               .from(ProgramIndicatorToProgramStageSectionRelation$Flow.class)
               .where(
                   Condition.column(
                           ProgramIndicatorToProgramStageSectionRelation$Flow$Table
                               .PROGRAMSTAGESECTION_PROGRAMSTAGESECTION)
                       .is(object.getUId()))
               .queryList();
   for (ProgramIndicatorToProgramStageSectionRelation$Flow
       programIndicatorToProgramStageSectionRelationFlow :
           programIndicatorToProgramStageSectionRelationFlows) {
     programIndicatorToProgramStageSectionRelationFlow.delete();
   }
   getMapper().mapToDatabaseEntity(object).delete();
   return true;
 }
コード例 #26
0
  private static void updateTrackedEntityInstanceReferences(
      long localId,
      String newTrackedEntityInstanceReference,
      String oldTempTrackedEntityInstanceReference) {
    // update references with uid received from server
    new Update(TrackedEntityAttributeValue.class)
        .set(
            Condition.column(TrackedEntityAttributeValue$Table.TRACKEDENTITYINSTANCEID)
                .is(newTrackedEntityInstanceReference))
        .where(
            Condition.column(TrackedEntityAttributeValue$Table.LOCALTRACKEDENTITYINSTANCEID)
                .is(localId))
        .async()
        .execute();

    new Update(Event.class)
        .set(
            Condition.column(Event$Table.TRACKEDENTITYINSTANCE)
                .is(newTrackedEntityInstanceReference))
        .where(
            Condition.column(Event$Table.TRACKEDENTITYINSTANCE)
                .is(oldTempTrackedEntityInstanceReference))
        .async()
        .execute();

    new Update(Enrollment.class)
        .set(
            Condition.column(Enrollment$Table.TRACKEDENTITYINSTANCE)
                .is(newTrackedEntityInstanceReference))
        .where(
            Condition.column(Enrollment$Table.TRACKEDENTITYINSTANCE)
                .is(oldTempTrackedEntityInstanceReference))
        .async()
        .execute();

    long updated =
        new Update(Relationship.class)
            .set(
                Condition.column(Relationship$Table.TRACKEDENTITYINSTANCEA)
                    .is(newTrackedEntityInstanceReference))
            .where(
                Condition.column(Relationship$Table.TRACKEDENTITYINSTANCEA)
                    .is(oldTempTrackedEntityInstanceReference))
            .count();

    updated +=
        new Update(Relationship.class)
            .set(
                Condition.column(Relationship$Table.TRACKEDENTITYINSTANCEB)
                    .is(newTrackedEntityInstanceReference))
            .where(
                Condition.column(Relationship$Table.TRACKEDENTITYINSTANCEB)
                    .is(oldTempTrackedEntityInstanceReference))
            .count();

    Log.d(CLASS_TAG, "updated relationships: " + updated);

    /* mechanism for triggering updating of relationships
     * a relationship can only be uploaded if both involved teis are sent to server
     * and have a valid UID.
     * So, we check if this tei was just updated with a valid reference, and if there now
     * exist >0 relationships that are valid. If >0 relationship is valid, it
     * should get uploaded, as it is the first time it has been valid. */
    boolean hasValidRelationship = false;
    if (Utils.isLocal(oldTempTrackedEntityInstanceReference)) {
      List<Relationship> teiIsB =
          new Select()
              .from(Relationship.class)
              .where(
                  Condition.column(Relationship$Table.TRACKEDENTITYINSTANCEB)
                      .is(newTrackedEntityInstanceReference))
              .queryList();
      List<Relationship> teiIsA =
          new Select()
              .from(Relationship.class)
              .where(
                  Condition.column(Relationship$Table.TRACKEDENTITYINSTANCEA)
                      .is(newTrackedEntityInstanceReference))
              .queryList();
      if (teiIsB != null) {
        for (Relationship relationship : teiIsB) {
          if (!Utils.isLocal(relationship.getTrackedEntityInstanceA())) {
            hasValidRelationship = true;
          }
        }
      }
      if (teiIsA != null) {
        for (Relationship relationship : teiIsA) {
          if (!Utils.isLocal(relationship.getTrackedEntityInstanceB())) {
            hasValidRelationship = true;
          }
        }
      }
    }
    boolean fullySynced = !(hasValidRelationship && updated > 0);

    new Update(TrackedEntityInstance.class)
        .set(
            Condition.column(TrackedEntityInstance$Table.TRACKEDENTITYINSTANCE)
                .is(newTrackedEntityInstanceReference),
            Condition.column(TrackedEntityInstance$Table.FROMSERVER).is(fullySynced))
        .where(Condition.column(TrackedEntityInstance$Table.LOCALID).is(localId))
        .async()
        .execute();
  }
コード例 #27
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  /**
   * Counts the number of compulsory questions (without a parent question).
   *
   * @param tabGroup
   * @return
   */
  public static int countCompulsoryByProgram(TabGroup tabGroup) {
    if (tabGroup == null || tabGroup.getId_tab_group() == null) {
      return 0;
    }

    // Count all the quesions that may have an answer
    long totalAnswerableQuestions =
        new Select()
            .count()
            .from(Question.class)
            .as("q")
            .join(Header.class, Join.JoinType.LEFT)
            .as("h")
            .on(
                Condition.column(ColumnAlias.columnWithTable("q", Question$Table.ID_HEADER))
                    .eq(ColumnAlias.columnWithTable("h", Header$Table.ID_HEADER)))
            .join(Tab.class, Join.JoinType.LEFT)
            .as("t")
            .on(
                Condition.column(ColumnAlias.columnWithTable("h", Header$Table.ID_TAB))
                    .eq(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB)))
            .where(
                Condition.column(ColumnAlias.columnWithTable("q", Question$Table.COMPULSORY))
                    .is(true))
            .and(
                Condition.column(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB_GROUP))
                    .eq(tabGroup.getId_tab_group()))
            .count();

    // Count children questions from the given taggroup
    long numChildrenQuestion =
        new Select()
            .count()
            .from(QuestionRelation.class)
            .as("qr")
            .join(Question.class, Join.JoinType.LEFT)
            .as("q")
            .on(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.ID_QUESTION))
                    .eq(ColumnAlias.columnWithTable("q", Question$Table.ID_QUESTION)))
            .join(Header.class, Join.JoinType.LEFT)
            .as("h")
            .on(
                Condition.column(ColumnAlias.columnWithTable("q", Question$Table.ID_HEADER))
                    .eq(ColumnAlias.columnWithTable("h", Header$Table.ID_HEADER)))
            .join(Tab.class, Join.JoinType.LEFT)
            .as("t")
            .on(
                Condition.column(ColumnAlias.columnWithTable("h", Header$Table.ID_TAB))
                    .eq(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB)))
            .where(
                Condition.column(ColumnAlias.columnWithTable("q", Question$Table.COMPULSORY))
                    .is(true))
            .and(
                Condition.column(ColumnAlias.columnWithTable("t", Tab$Table.ID_TAB_GROUP))
                    .eq(tabGroup.getId_tab_group()))
            .and(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.OPERATION))
                    .eq(Constants.OPERATION_TYPE_PARENT))
            .count();

    // Return number of parents (total - children)
    return (int) (totalAnswerableQuestions - numChildrenQuestion);
  }
コード例 #28
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
  /**
   * Gets all the children compulsory questions, and returns the number of active children
   *
   * @param
   * @return
   */
  public static int countChildrenCompulsoryBySurvey(Long id_survey) {
    int numActiveChildrens = 0;
    // This query returns a list of children compulsory questions
    // But the id_question is not correct, because is the the parent id_questions from the
    // questionOption relation.
    List<Question> questions =
        new Select()
            .from(Question.class)
            .as("q")
            .join(QuestionRelation.class, Join.JoinType.LEFT)
            .as("qr")
            .on(
                Condition.column(ColumnAlias.columnWithTable("q", Question$Table.ID_QUESTION))
                    .eq(ColumnAlias.columnWithTable("qr", QuestionRelation$Table.ID_QUESTION)))
            .join(Match.class, Join.JoinType.LEFT)
            .as("m")
            .on(
                Condition.column(
                        ColumnAlias.columnWithTable(
                            "qr", QuestionRelation$Table.ID_QUESTION_RELATION))
                    .eq(ColumnAlias.columnWithTable("m", Match$Table.ID_QUESTION_RELATION)))
            .join(QuestionOption.class, Join.JoinType.LEFT)
            .as("qo")
            .on(
                Condition.column(ColumnAlias.columnWithTable("m", Match$Table.ID_MATCH))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_MATCH)))
            .join(Value.class, Join.JoinType.LEFT)
            .as("v")
            .on(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_QUESTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_QUESTION)),
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_OPTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_OPTION)))
            // Parent Child relationship
            .where(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.OPERATION))
                    .eq(1))
            // For the given survey
            .and(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_SURVEY))
                    .eq(id_survey))
            // The child question requires an answer
            .and(
                Condition.column(ColumnAlias.columnWithTable("q", Question$Table.OUTPUT))
                    .isNot(Constants.NO_ANSWER))
            .and(
                Condition.column(ColumnAlias.columnWithTable("q", Question$Table.COMPULSORY))
                    .eq(true))
            .queryList();

    // checks if the children questions are active by UID
    // Note: the question id_question is wrong because dbflow query overwrites the children
    // id_question with the parent id_question.
    for (Question question : questions) {
      if (!Question.isHiddenQuestionByUidAndSurvey(question.getUid(), id_survey)) {
        numActiveChildrens++;
      }
    }
    // Return number of active compulsory children
    return (int) (numActiveChildrens);
  }
コード例 #29
0
ファイル: Question.java プロジェクト: EyeSeeTea/QAApp
 /**
  * Returns a Question by a UID
  *
  * @param uid
  * @return
  */
 public static Question getQuestionByUid(String uid) {
   return new Select()
       .from(Question.class)
       .where(Condition.column(ColumnAlias.column(Question$Table.UID)).eq(uid))
       .querySingle();
 }