Closed richiecroker closed 4 months ago
Having run this code:
WITH bnf_map_codes AS (SELECT DISTINCT former_bnf_code AS code, 'former' AS status
FROM ebmdatalab.hscic.bnf_map
WHERE former_bnf_code IS NOT NULL
UNION ALL
SELECT DISTINCT current_bnf_code AS code, 'current' AS status
FROM ebmdatalab.hscic.bnf_map
WHERE current_bnf_code IS NOT NULL)
SELECT * from bnf_map_codes
WHERE
code IN (
'0301040V0AAAAAA',
'0301040V0BBAAAA',
'0302000W0AAAAAA',
'0302000W0BBAAAA',
'0304020Z0AAAAAA',
'0304020Z0BBAAAA',
'0408010AHBBAGAG',
'0604011L0AABMBM',
'0604011L0CCAABM',
'0703010S0AAAAAA',
'0703010S0BBAAAA',
'1306010ACAAAAAA',
'1306010ACBBAAAA',
'1306030B0AAAAAA',
'1306030B0BBAAAA',
'1404000X0AAAHAH',
'1404000X0BKAAAH',
'0301020U0AAAAAA',
'0301020U0BBAAAA',
'0407010X0CDACBF'
)
I get the following codes:
code | status |
---|---|
0302000W0AAAAAA | former |
0302000W0BBAAAA | former |
0407010X0CDACBF | former |
0604011L0AABMBM | former |
0604011L0CCAABM | former |
1306010ACAAAAAA | former |
1306010ACBBAAAA | former |
1404000X0AAAHAH | former |
1404000X0BKAAAH | former |
0304020Z0AAAAAA | current |
0304020Z0BBAAAA | current |
0703010S0AAAAAA | current |
0703010S0BBAAAA | current |
1306030B0AAAAAA | current |
1306030B0BBAAAA | current |
I think we need to identify any rows in ebmdatalab.hscic.bnf_map
which have a former_bnf_code
listed as a "former" in the above table, and remove those rows, as the map to a current bnf_code is incorrect.
For convenience, the codes this relates to are: ('0302000W0AAAAAA','0302000W0BBAAAA','0407010X0CDACBF','0604011L0AABMBM','0604011L0CCAABM','1306010ACAAAAAA','1306010ACBBAAAA','1404000X0AAAHAH','1404000X0BKAAAH')
For
I think this is finally fixed. Below are the steps I took to get this working (eliding all the missteps and various bits of detective work and local testing it took to get there).
After merging these two PRs:
And running:
./manage.py generate_presentation_replacements
I confirmed by running the SQL given above in BiqQuery that all the entries with a status of former
were no longer being returned.
I then built and activated a new MatrixStore file:
./manage.py matrixstore_build 2024-04
./manage.py matrixstore_set_live
However the product I expected to now be visible on the Analyse page was still not visible:
Enerzair Breezhaler 114microg / 46microg / 136microg/dose
0302000W0BBAAAA
Searching for that BNF code in the database revealed that (a) it was still flagged as is_current = False
and (b) it had completely the wrong name:
[local] postgres@prescribing=# SELECT * FROM frontend_presentation WHERE bnf_code = '0302000W0BBAAAA';
┌─[ RECORD 1 ]────────┬─────────────────────────────────────────────────────────────────┐
│ bnf_code │ 0302000W0BBAAAA │
│ name │ Cinqaero 100mg/10ml concentrate for inf vials │
│ is_generic │ f │
│ replaced_by_id │ ¤ │
│ is_current │ f │
│ adq_per_quantity │ ¤ │
│ quantity_means_pack │ f │
│ dmd_name │ Cinqaero 100mg/10ml concentrate for solution for infusion vials │
└─────────────────────┴─────────────────────────────────────────────────────────────────┘
I was able to fix the is_current
problem by running this command:
./manage.py refresh_bnf_class_currency
I was able to fix the name
field issue by running the below (2024_06
is what happened to be the latest downloaded version):
./manage.py import_bnf_codes --filename /mnt/volume-fra1-02/openprescribing-data/bnf_codes/2024_06/bnf_codes.csv
At this point the product was now visible via the Analyse page. However the dmd_name
field still contained the old name.
To fix this I needed to reimport the dm+d download, however this refused to run because there was already an ImportLog entry for that download. So I first deleted that entry using:
DELETE FROM frontend_importlog WHERE id=16395;
And I was then able to fix the dmd_name
field by running:
./manage.py import_dmd
I wrote to the NHSBSA a few months ago:
Their response was: