Skip to content

Commit

Permalink
Merge pull request #1697 from opensafely-core/dmd-downloads-with-futu…
Browse files Browse the repository at this point in the history
…re-mappings

Make dmd VMP mappings handle multiple future mappings
  • Loading branch information
rebkwok authored Oct 19, 2023
2 parents c8152a4 + 8a06750 commit 333446e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 10 additions & 4 deletions codelists/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,17 @@ def table_with_fixed_headers(self, include_mapped_vmps=True):
prev_to_vmp_mapping[previous_vmp] = vmp
else:
# if the vmp wasn't in the codelist codes, then the mapped previous one
# must be
# must be. We're mapping in a code that is subsequent to one in the current codelist.
assert previous_vmp in codes
# and it must be in the mapping of vmp to previous that we'll look it up in
# later
assert previous_vmp in vmp_to_prev_mapping

# The mapped code must be in ONE of the direct mappings
# It's either previous to a current code (and in vmp_to_prev_mapping), or previous to
# another previous code of current code,in which case it will be in the
# prev_to_vmp_mapping
if previous_vmp not in vmp_to_prev_mapping:
assert previous_vmp in prev_to_vmp_mapping
# add the mapped VMP into the mapping so we can add in the description
vmp_to_prev_mapping[vmp] = prev_to_vmp_mapping[previous_vmp]
# mapping a code in the codelist to a new code that supercedes it
subsequent_vmps_to_add.add(vmp)

Expand Down
14 changes: 12 additions & 2 deletions codelists/tests/views/test_version_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,27 @@ def test_get_with_mapped_vmps_more_than_one_step_distant(
# create a previous mapping for one of the dmd codes
Mapping.objects.create(id="10514511000001106", vpidprev="999")
# create a previous mapping for this previous code
# create a new mapping for one of the dmd codes; neither of these
# codes are in the codelist, but 777 needs to be mapped in as a previou
# create two more mapping for one of the dmd codes; neither of these
# codes are in the codelist, but 777 and 666 need to be mapped in as a previous
# code to 10514511000001106, which is in the codelist
Mapping.objects.create(id="999", vpidprev="777")
Mapping.objects.create(id="777", vpidprev="666")

# create some new mappings for one of the dmd codes
Mapping.objects.create(id="AAA", vpidprev="10514511000001106")
Mapping.objects.create(id="BBB", vpidprev="AAA")
Mapping.objects.create(id="CCC", vpidprev="BBB")

rsp = client.get(dmd_version_asthma_medication.get_download_url())
data = rsp.content.decode("utf8")
assert csv_data_to_rows(data) == [
["code", "term"],
["10514511000001106", "Adrenaline (base) 220micrograms/dose inhaler"],
["10525011000001107", "Adrenaline (base) 220micrograms/dose inhaler refill"],
["666", "VMP previous to 10514511000001106"],
["777", "VMP previous to 10514511000001106"],
["999", "VMP previous to 10514511000001106"],
["AAA", "VMP subsequent to 10514511000001106"],
["BBB", "VMP subsequent to AAA"],
["CCC", "VMP subsequent to BBB"],
]

0 comments on commit 333446e

Please sign in to comment.