def build_analyse_url(measure): params = {"measure": measure.id} if measure.numerator_is_list_of_bnf_codes: if not measure.numerator_bnf_codes: return params["numIds"] = ",".join( simplify_bnf_codes(measure.numerator_bnf_codes)) else: return if measure.denominator_is_list_of_bnf_codes: if not measure.denominator_bnf_codes: return params["denomIds"] = ",".join( simplify_bnf_codes(measure.denominator_bnf_codes)) elif measure.denominator_type == "list_size": params["denom"] = "total_list_size" elif measure.denominator_type == "star_pu_antibiotics": params["denom"] = "star_pu.oral_antibacterials_item" else: return querystring = urlencode(params) url = "{}#{}".format(reverse("analyse"), querystring) if len(url) > 5000: # Anything longer than 5000 characters takes too long to load. In # practice, as of 12/19, only one measure is affected (silver). return return url
def build_analyse_url(measure): params = {"measure": measure.id} if measure.numerator_is_list_of_bnf_codes: if not measure.numerator_bnf_codes: return params["numIds"] = ",".join( simplify_bnf_codes(measure.numerator_bnf_codes)) else: return if measure.denominator_is_list_of_bnf_codes: if not measure.denominator_bnf_codes: return params["denomIds"] = ",".join( simplify_bnf_codes(measure.denominator_bnf_codes)) elif measure.denominator_type == "list_size": params["denom"] = "total_list_size" elif measure.denominator_type == "star_pu_antibiotics": params["denom"] = "star_pu.oral_antibacterials_item" else: return querystring = urlencode(params) url = "{}#{}".format(reverse("analyse"), querystring) if len(url) > 1000: return return url
def _build_analyse_url(objs): bnf_codes = [obj.bnf_code for obj in objs if obj.bnf_code] params = { "numIds": ",".join(simplify_bnf_codes(bnf_codes)), "denom": "total_list_size", } querystring = urlencode(params) url = "{}#{}".format(reverse("analyse"), querystring) if len(url) > 5000: # Anything longer than 5000 characters takes too long to load. This # matches the behaviour of import_measures.build_analyse_url(). return return url
def test_simplify_bnf_codes(self): # These are BNF codes for some of the presentations for two different products, # Co-Careldopa (generic, 0409010N0AA) and Sinemet (branded, 0409010N0BB). # # We check that simplifying a list of BNF codes for the branded presentations # returns the BNF prefix of the branded product. all_bnf_codes = [ "0409010N0AAAAAA", "0409010N0AAABAB", "0409010N0AAACAC", "0409010N0AAADAD", "0409010N0AAAEAE", "0409010N0BBAAAA", "0409010N0BBABAC", "0409010N0BBACAB", "0409010N0BBADAD", ] factory = DataFactory() month = factory.create_months("2018-10-01", 1)[0] practice = factory.create_practices(1)[0] for bnf_code in all_bnf_codes: presentation = factory.create_presentation(bnf_code) factory.create_prescription(presentation, practice, month) branded_bnf_codes = [ "0409010N0BBAAAA", "0409010N0BBABAC", "0409010N0BBACAB", "0409010N0BBADAD", "0409010N0BBAEAE", # This is missing from all_bnf_codes. ] with patched_global_matrixstore_from_data_factory(factory): self.assertEqual(simplify_bnf_codes(branded_bnf_codes), ["0409010N0BB"])