original_docstring: 
          Search DHIS2 for potential matches of the CommCare case. Score
          search results and keep those with score > 1. If more than one
          result has a score > 1, select the best candidate if it exceeds
          a confidence margin. Otherwise return all results with score > 1.
          
docstring: Search DHIS2 for potential matches of the CommCare case. Score
  search results and keep those with score > 1. If more than one
  result has a score > 1, select the best candidate if it exceeds
  a confidence margin. Otherwise return all results with score > 1.
docstring_tokens: Search DHIS2 for potential matches of the CommCare case . Score search results and keep those with score > 1 . If more than one result has a score > 1 select the best candidate if it exceeds a confidence margin . Otherwise return all results with score > 1 .
code: def find_tracked_entity_instances(self, case_trigger_info):
          """
          Search DHIS2 for potential matches of the CommCare case. Score
          search results and keep those with score > 1. If more than one
          result has a score > 1, select the best candidate if it exceeds
          a confidence margin. Otherwise return all results with score > 1.
          """
          # For new cases, this is the first API query. If something is
          # wrong with the configuration or the API, this is the first
          # chance to find out about it.
          try:
              results = self.fetch_query_results(case_trigger_info)
          except HTTPError as err:
              err.args += (_(
                  "An error occurred on the first API request to DHIS2. Please "
                  "refer to Remote API Logs to confirm that the URL and the "
                  "request parameters are correct."
              ),)
              raise
          candidate_scores = []
          for instance in results:
              score = self.get_score(instance, case_trigger_info)
              if score >= 1:
                  candidate_scores.append(CandidateScore(instance, score))
  
          if len(candidate_scores) > 1:
              candidate_scores = sorted(candidate_scores, key=lambda cs: cs.score, reverse=True)
              if candidate_scores[0].score / candidate_scores[1].score > 1 + self.confidence_margin:
                  return [candidate_scores[0].candidate]
          return [cs.candidate for cs in candidate_scores]
code_tokens: def find_tracked_entity_instances ( self , case_trigger_info ) : try : results = self . fetch_query_results ( case_trigger_info ) except HTTPError as err : err . args += ( _ ( "An error occurred on the first API request to DHIS2. Please " "refer to Remote API Logs to confirm that the URL and the " "request parameters are correct." ) , ) raise candidate_scores = [ ] for instance in results : score = self . get_score ( instance , case_trigger_info ) if score >= 1 : candidate_scores . append ( CandidateScore ( instance , score ) ) if len ( candidate_scores ) > 1 : candidate_scores = sorted ( candidate_scores , key = lambda cs : cs . score , reverse = True ) if candidate_scores [ 0 ] . score / candidate_scores [ 1 ] . score > 1 + self . confidence_margin : return [ candidate_scores [ 0 ] . candidate ] return [ cs . candidate for cs in candidate_scores ]
short_docstring: Search DHIS2 for potential matches of the CommCare case.
short_docstring_tokens: Search DHIS2 for potential matches of the CommCare case .
comment: """
          Search DHIS2 for potential matches of the CommCare case. Score
          search results and keep those with score > 1. If more than one
          result has a score > 1, select the best candidate if it exceeds
          a confidence margin. Otherwise return all results with score > 1.
          """$SEP$# For new cases, this is the first API query. If something is$SEP$# wrong with the configuration or the API, this is the first$SEP$# chance to find out about it.