(self, case_trigger_info)
return [cs.candidate for cs in candidate_scores]
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.
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.
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 .
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]
def find_tracked_entity_instances ( self , case_trigger_info ) : # 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 ]