Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
fix: round to 5 decimal places by default (#185)
Browse files Browse the repository at this point in the history
* fix: round to 5 decimal places by default

* fix flake8 line too long
  • Loading branch information
chgl authored Aug 8, 2024
1 parent 5230a65 commit 46eeca2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 30 deletions.
8 changes: 5 additions & 3 deletions ahd2fhir/mappers/ahd_to_medication_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,16 @@ def get_medication_dosage_from_annotation(annotation) -> Dosage:

dosage.text = drug["coveredText"]

dose_and_rate = DosageDoseAndRate.construct()
quantity = Quantity.construct()
quantity_value = drug["strength"]["value"]
quantity_value = round(quantity_value, 5)

quantity.value = drug["strength"]["value"]
quantity = Quantity.construct()
quantity.value = quantity_value
quantity.unit = drug["strength"]["unit"]
quantity.code = drug["strength"]["unit"]
quantity.system = "http://unitsofmeasure.org"

dose_and_rate = DosageDoseAndRate.construct()
dose_and_rate.doseQuantity = quantity
dosage.doseAndRate = [dose_and_rate]

Expand Down
1 change: 0 additions & 1 deletion requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ flake8==7.0.0
pycodestyle==2.11.1
pre-commit==3.7.1
flake8-bugbear==24.4.26
pip-tools==7.4.1
isort==5.13.2
26 changes: 0 additions & 26 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ black==24.4.2 \
--hash=sha256:eaea3008c281f1038edb473c1aa8ed8143a5535ff18f978a318f10302b254063 \
--hash=sha256:ef703f83fc32e131e9bcc0a5094cfe85599e7109f896fe8bc96cc402f3eb4b6e
# via -r requirements-dev.in
build==1.2.1 \
--hash=sha256:526263f4870c26f26c433545579475377b2b7588b6f1eac76a001e873ae3e19d \
--hash=sha256:75e10f767a433d9a86e50d83f418e83efc18ede923ee5ff7df93b6cb0306c5d4
# via pip-tools
certifi==2024.7.4 \
--hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \
--hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90
Expand Down Expand Up @@ -197,7 +193,6 @@ click==8.1.7 \
--hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de
# via
# black
# pip-tools
# typer
# uvicorn
coverage[toml]==7.6.0 \
Expand Down Expand Up @@ -623,17 +618,12 @@ packaging==24.1 \
# via
# aiokafka
# black
# build
# deprecation
# pytest
pathspec==0.12.1 \
--hash=sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08 \
--hash=sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712
# via black
pip-tools==7.4.1 \
--hash=sha256:4c690e5fbae2f21e87843e89c26191f0d9454f362d8acdbd695716493ec8b3a9 \
--hash=sha256:864826f5073864450e24dbeeb85ce3920cdfb09848a3d69ebf537b521f14bcc9
# via -r requirements-dev.in
platformdirs==4.2.2 \
--hash=sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee \
--hash=sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3
Expand Down Expand Up @@ -772,12 +762,6 @@ pygments==2.18.0 \
--hash=sha256:786ff802f32e91311bff3889f6e9a86e81505fe99f2735bb6d60ae0c5004f199 \
--hash=sha256:b8e6aca0523f3ab76fee51799c488e38782ac06eafcf95e7ba832985c8e7b13a
# via rich
pyproject-hooks==1.1.0 \
--hash=sha256:4b37730834edbd6bd37f26ece6b44802fb1c1ee2ece0e54ddff8bfc06db86965 \
--hash=sha256:7ceeefe9aec63a1064c18d939bdc3adf2d8aa1988a510afec15151578b232aa2
# via
# build
# pip-tools
pytest==8.2.1 \
--hash=sha256:5046e5b46d8e4cac199c373041f26be56fdb81eb4e67dc11d4e10811fc3408fd \
--hash=sha256:faccc5d332b8c3719f40283d0d44aa5cf101cec36f88cde9ed8f2bc0538612b1
Expand Down Expand Up @@ -1208,13 +1192,3 @@ websockets==12.0 \
--hash=sha256:fc4e7fa5414512b481a2483775a8e8be7803a35b30ca805afa4998a84f9fd9e8 \
--hash=sha256:ffefa1374cd508d633646d51a8e9277763a9b78ae71324183693959cf94635a7
# via uvicorn
wheel==0.43.0 \
--hash=sha256:465ef92c69fa5c5da2d1cf8ac40559a8c940886afcef87dcf14b9470862f1d85 \
--hash=sha256:55c570405f142630c6b9f72fe09d9b67cf1477fcf543ae5b8dcb1f5b7377da81
# via pip-tools

# WARNING: The following packages were not pinned, but pip requires them to be
# pinned when the requirements file includes hashes and the requirement is not
# satisfied by a package already installed. Consider using the --allow-unsafe flag.
# pip
# setuptools
63 changes: 63 additions & 0 deletions tests/test_ahd_to_medication_statement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json
from decimal import Decimal

from fhir.resources.R4B.attachment import Attachment
from fhir.resources.R4B.documentreference import (
Expand All @@ -12,6 +13,7 @@

from ahd2fhir.mappers.ahd_to_medication_statement import (
get_fhir_medication_statement,
get_medication_dosage_from_annotation,
get_medication_interval_from_annotation,
)
from ahd2fhir.utils.resource_handler import AHD_TYPE_MEDICATION
Expand Down Expand Up @@ -71,3 +73,64 @@ def test_fhir_medication_v6():
assert statement_v6.status is not None
assert statement_v6.medicationReference is None
assert statement_v6.medicationCodeableConcept is not None


def test_get_medication_dosage_from_annotation_should_round_quantity_value():
annotation = {
"type": "de.averbis.types.health.Medication",
"coveredText": "Therapie mit Piperacillin 4x4g i.v. sowie 4x500mg",
"id": 82560,
"administrations": ["i.v."],
"drugs": [
{
"begin": 3055,
"end": 3099,
"type": "de.averbis.types.health.Drug",
"coveredText": "antibiotische Therapie mit Piperacillin 4x4g",
"id": 82561,
"ingredient": {
"begin": 3055,
"end": 3077,
"type": "de.averbis.types.health.Ingredient",
"coveredText": "antibiotische Therapie",
"id": 82562,
"matchedTerm": "antibiotische Therapie",
"dictCanon": "Antibakterielle Mittel",
"conceptID": "255631004",
"source": "SNOMED-DrugClasses-DE_2023-11",
"uniqueID": "SNOMED-DrugClasses-DE_2023-11:255631004",
},
"strength": {
"begin": 3097,
"end": 3099,
"type": "de.averbis.types.health.Strength",
"coveredText": "4g",
"id": 82563,
"unit": "g",
"normalizedUnit": "kg",
"normalizedValue": 0.004,
"value": 1.111111111111,
"dimension": "[M]",
},
}
],
"atcCodes": [
{
"begin": 3055,
"end": 3099,
"type": "de.averbis.types.health.ATCCode",
"coveredText": "antibiotische Therapie mit Piperacillin 4x4g",
"id": 82574,
"dictCanon": "ANTIBIOTIKA ZUR SYSTEMISCHEN ANWENDUNG",
"conceptID": "J01",
"source": "ATCA_2024",
}
],
}

dosage = get_medication_dosage_from_annotation(annotation)

assert len(dosage.doseAndRate) == 1
assert dosage.doseAndRate[0].doseQuantity.system == "http://unitsofmeasure.org"
assert dosage.doseAndRate[0].doseQuantity.unit == "g"
assert dosage.doseAndRate[0].doseQuantity.value == Decimal("1.11111")

0 comments on commit 46eeca2

Please sign in to comment.