doseframe 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. doseframe/__init__.py +252 -0
  2. doseframe/calculation/__init__.py +34 -0
  3. doseframe/calculation/derivation.py +30 -0
  4. doseframe/calculation/errors.py +16 -0
  5. doseframe/calculation/infusion.py +27 -0
  6. doseframe/calculation/relation.py +129 -0
  7. doseframe/calculation/single_dose.py +54 -0
  8. doseframe/calculation/steps.py +20 -0
  9. doseframe/calculation/strategies.py +105 -0
  10. doseframe/calculation/strategy.py +37 -0
  11. doseframe/checks/__init__.py +20 -0
  12. doseframe/checks/chain.py +212 -0
  13. doseframe/checks/context.py +43 -0
  14. doseframe/findings/__init__.py +58 -0
  15. doseframe/protocols/__init__.py +103 -0
  16. doseframe/protocols/activation.py +51 -0
  17. doseframe/protocols/device.py +51 -0
  18. doseframe/protocols/diff.py +70 -0
  19. doseframe/protocols/errors.py +26 -0
  20. doseframe/protocols/limits.py +74 -0
  21. doseframe/protocols/model.py +40 -0
  22. doseframe/protocols/naming.py +126 -0
  23. doseframe/protocols/reference.py +163 -0
  24. doseframe/protocols/schemes.py +598 -0
  25. doseframe/protocols/single_dose.py +253 -0
  26. doseframe/protocols/version.py +690 -0
  27. doseframe/py.typed +0 -0
  28. doseframe/rounding/__init__.py +23 -0
  29. doseframe/rounding/policy.py +108 -0
  30. doseframe/units/__init__.py +49 -0
  31. doseframe/units/catalog.py +155 -0
  32. doseframe/units/decimal_context.py +17 -0
  33. doseframe/units/errors.py +27 -0
  34. doseframe/units/options.py +52 -0
  35. doseframe/units/quantity.py +144 -0
  36. doseframe/units/unit.py +137 -0
  37. doseframe/use_cases/__init__.py +73 -0
  38. doseframe/use_cases/clinical.py +735 -0
  39. doseframe/use_cases/gate.py +85 -0
  40. doseframe/use_cases/governance.py +460 -0
  41. doseframe/use_cases/ports.py +73 -0
  42. doseframe/use_cases/results.py +182 -0
  43. doseframe-0.2.0.dist-info/METADATA +79 -0
  44. doseframe-0.2.0.dist-info/RECORD +46 -0
  45. doseframe-0.2.0.dist-info/WHEEL +4 -0
  46. doseframe-0.2.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,182 @@
1
+ """What the clinical use cases return. Plain values: the adapters decide how to show them."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from datetime import datetime
7
+ from decimal import Decimal
8
+ from enum import StrEnum
9
+
10
+ from doseframe.calculation import Derivation, InfusedEstimate
11
+ from doseframe.findings import Finding, blocking
12
+ from doseframe.protocols import (
13
+ DosePreparation,
14
+ Preparation,
15
+ ProtocolTitle,
16
+ Range,
17
+ StockSolution,
18
+ WeightScope,
19
+ Workflow,
20
+ )
21
+ from doseframe.protocols.single_dose import DoseOption
22
+ from doseframe.units import Quantity, Unit
23
+
24
+
25
+ @dataclass(frozen=True, slots=True)
26
+ class VersionRef:
27
+ """The protocol version a result is based on, as shown in the context bar."""
28
+
29
+ version_id: str
30
+ protocol_id: str
31
+ protocol_name: str
32
+ """The standard name (V3-12): `title.text()` with the stored weight bounds."""
33
+ medication_name: str
34
+ number: int
35
+ scheme_kind: str
36
+ workflow: Workflow
37
+ dose_unit: Unit
38
+ usual_dose_units: tuple[Unit, ...]
39
+ weight_scope: WeightScope
40
+ stock_solutions: tuple[StockSolution, ...]
41
+ notes: tuple[str, ...]
42
+ fictitious: bool
43
+ review_overdue: bool
44
+ device_name: str | None = None
45
+ title: ProtocolTitle | None = None
46
+
47
+
48
+ @dataclass(frozen=True, slots=True)
49
+ class ProtocolMatch:
50
+ """A published version whose weight range contains the weight; the user confirms one."""
51
+
52
+ version: VersionRef
53
+ concentration: Quantity | None
54
+ reference_dose: Quantity | None
55
+
56
+
57
+ @dataclass(frozen=True, slots=True)
58
+ class SettingStep:
59
+ setting: Quantity
60
+ delivered_dose: Quantity | None
61
+ deviation_pct: Decimal | None
62
+ findings: tuple[Finding, ...]
63
+
64
+
65
+ @dataclass(frozen=True, slots=True)
66
+ class CalculationResult:
67
+ """A new perfusor: preparation, exact rate, and the effect of a pump setting."""
68
+
69
+ version: VersionRef
70
+ weight: Quantity
71
+ dose: Quantity
72
+ dose_entered: Quantity
73
+ stock: StockSolution | None
74
+ preparation: Preparation | None
75
+ concentration: Derivation | None
76
+ exact_rate: Derivation | None
77
+ suggested_setting: Quantity | None
78
+ suggested_dose: Quantity | None
79
+ suggested_deviation_pct: Decimal | None
80
+ setting: Quantity | None
81
+ dose_at_setting: Derivation | None
82
+ deviation_pct: Decimal | None
83
+ usual_range: Range | None
84
+ dose_views: tuple[Quantity, ...]
85
+ findings: tuple[Finding, ...]
86
+
87
+ setting_steps: tuple[SettingStep, ...] = ()
88
+
89
+ def is_usable(self) -> bool:
90
+ """False when any finding blocks; then no number may be shown."""
91
+ return not blocking(self.findings) and self.exact_rate is not None
92
+
93
+
94
+ @dataclass(frozen=True, slots=True)
95
+ class SingleDoseResult:
96
+ """A divided daily dose: the exact amount, the amount that can be drawn up, the deviation."""
97
+
98
+ version: VersionRef
99
+ weight: Quantity
100
+ daily_dose_entered: Quantity
101
+ daily_dose: Quantity
102
+ stock: StockSolution | None
103
+ exact: Derivation | None
104
+ exact_volume: Quantity | None
105
+ options: tuple[DoseOption, ...]
106
+ offers_choice: bool
107
+ doses_per_day: int
108
+ usual_range: Range | None
109
+ findings: tuple[Finding, ...]
110
+
111
+ fallback_note: str | None = None
112
+
113
+ @property
114
+ def legacy_option(self) -> DoseOption | None:
115
+ return self.options[0] if self.options and not self.offers_choice else None
116
+
117
+ @property
118
+ def rounded(self) -> Quantity | None:
119
+ return self.legacy_option.amount if self.legacy_option else None
120
+
121
+ @property
122
+ def rounded_volume(self) -> Quantity | None:
123
+ return self.legacy_option.volume if self.legacy_option else None
124
+
125
+ @property
126
+ def deviation_pct(self) -> Decimal | None:
127
+ return self.legacy_option.deviation_pct if self.legacy_option else None
128
+
129
+ @property
130
+ def preparation(self) -> DosePreparation | None:
131
+ return self.legacy_option.preparation if self.legacy_option else None
132
+
133
+ def is_usable(self) -> bool:
134
+ return not blocking(self.findings) and any(option.is_usable() for option in self.options)
135
+
136
+
137
+ class ConcentrationSource(StrEnum):
138
+ LABEL = "label"
139
+ PROTOCOL = "protocol"
140
+
141
+
142
+ @dataclass(frozen=True, slots=True)
143
+ class ReverseCheckResult:
144
+ """A running perfusor: the dose it delivers at the rate read off the pump."""
145
+
146
+ version: VersionRef
147
+ weight: Quantity
148
+ rate: Quantity
149
+ concentration: Quantity | None
150
+ concentration_source: ConcentrationSource
151
+ protocol_concentration: Quantity | None
152
+ implied_preparation_weight: Quantity | None
153
+ delivered_dose: Derivation | None
154
+ prescribed_dose: Quantity | None
155
+ deviation_pct: Decimal | None
156
+ findings: tuple[Finding, ...]
157
+ dose_views: tuple[Quantity, ...] = ()
158
+ usual_range: Range | None = None
159
+ infused: InfusedEstimate | None = None
160
+
161
+ rate_difference: Quantity | None = None
162
+
163
+ def is_usable(self) -> bool:
164
+ return not blocking(self.findings) and self.delivered_dose is not None
165
+
166
+
167
+ class UnusableReason(StrEnum):
168
+ WITHDRAWN = "withdrawn"
169
+ SUPERSEDED = "superseded"
170
+ NOT_PUBLISHED = "not_published"
171
+ NOT_FOUND = "not_found"
172
+ STORAGE_UNAVAILABLE = "storage_unavailable"
173
+ WRONG_WORKFLOW = "wrong_workflow"
174
+
175
+
176
+ @dataclass(frozen=True, slots=True)
177
+ class Unavailable:
178
+ """No numbers at all: why, since when, and what to do instead (BE-06, AT-08)."""
179
+
180
+ reason: UnusableReason
181
+ fallback_note: str
182
+ since: datetime | None = None
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.5
2
+ Name: doseframe
3
+ Version: 0.2.0
4
+ Summary: A transparent, unit-safe dose calculation framework for perfusors. Not a medical device.
5
+ Author: Simon Bernbeck
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Programming Language :: Python :: 3.13
10
+ Classifier: Typing :: Typed
11
+ Requires-Python: >=3.13
12
+ Description-Content-Type: text/markdown
13
+
14
+ # doseframe
15
+
16
+ A transparent, unit-safe framework for medication calculation and preparation across clinics,
17
+ including perfusors (syringe pumps) and divided daily doses.
18
+
19
+ The invariant kernel includes explicit units, governed protocol versions, approval and a mandatory
20
+ check prefix. Shipped preparation schemes, calculation strategies and rounding policies can be
21
+ selected or extended through their contracts. Every `CheckChain()` begins with `UnitCheck` then
22
+ `LimitCheck`; a clinic can append checks but cannot replace that prefix through the constructor.
23
+ A hospital supplies protocol data, storage and interface wiring.
24
+
25
+ What it ships:
26
+
27
+ - **Infusion schemes:** standard concentration, individual preparation and two-step preparation,
28
+ plus a reverse check of a running pump that changes one unit per step.
29
+ - **Single doses:** a divided daily dose, split into a fixed number of administrations.
30
+ - **Rounding policies:** `NoAutoRounding` (the default), `NearestStepRounding`, and `ChooseStep`,
31
+ which offers the neighbouring device or syringe steps and leaves the choice to a person.
32
+ - **Governance:** draft, review, approval and withdrawal, with four-eyes approval, reference
33
+ cases that must pass before approval, and versions that are never overwritten.
34
+ - **Standard protocol names:** `ProtocolTitle` builds a name from the content, in the order drug
35
+ and strength, carrier or syringe, weight range.
36
+
37
+ ## Installation
38
+
39
+ Doseframe requires Python 3.13 or newer and has no runtime dependencies.
40
+
41
+ ```sh
42
+ python -m pip install doseframe
43
+ ```
44
+
45
+ ## Quickstart
46
+
47
+ This fictitious example converts a weight-based rate to a volume per hour.
48
+
49
+ ```pycon
50
+ >>> from doseframe import Quantity, __version__
51
+ >>> __version__
52
+ '0.2.0'
53
+ >>> rate = (Quantity.of("0.02", "µg/kg/min") * Quantity.of("2.4", "kg")).to("µg/h")
54
+ >>> str(rate / Quantity.of("30", "µg/ml"))
55
+ '0.096 ml/h'
56
+
57
+ ```
58
+
59
+ A pump can only be set in steps. `ChooseStep` offers the two settable values next to the exact
60
+ rate and does not pick one:
61
+
62
+ ```pycon
63
+ >>> from doseframe import ChooseStep, DeviceProfile
64
+ >>> pump = DeviceProfile(id="demo", name="Demo pump", step_size=Quantity.of("0.01", "ml/h"))
65
+ >>> [str(q) for q in ChooseStep().candidates(Quantity.of("0.096", "ml/h"), pump)]
66
+ ['0.09 ml/h', '0.1 ml/h']
67
+
68
+ ```
69
+
70
+ ## Changes
71
+
72
+ - **0.2.0:** `ChooseStep` rounding with per-option findings for single doses; settable pump steps
73
+ next to the exact rate; one unit per step in the reverse calculation; a syringe label of any
74
+ compatible unit; `MatchProtocolsUseCase.label_required()`; generated protocol names
75
+ (`ProtocolTitle`); fields in the name fixed after approval.
76
+ - **0.1.x:** first package build (staged on TestPyPI only).
77
+
78
+ > **Not a medical device.** This library is a study project. It has no clinical validation
79
+ > or conformity assessment and must not be used to guide the treatment of a patient.
@@ -0,0 +1,46 @@
1
+ doseframe/__init__.py,sha256=5XYaPyU9ezHf1OgQOT4NZZ4IwJ7DurWD_WwzgfW3aoE,5834
2
+ doseframe/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ doseframe/calculation/__init__.py,sha256=B-8QpsDwRsOIeuy9zSTVXr4foH-GoxRQTXHmGIQIyrQ,1198
4
+ doseframe/calculation/derivation.py,sha256=mp_bxeRugy1O2rFx_OskdG6k8F9Kluazh37h4ZERLSk,861
5
+ doseframe/calculation/errors.py,sha256=EbjsyOEK8Xe1sevgNpycjxSQ4aeVpYZ5vEnzy-B_CWg,500
6
+ doseframe/calculation/infusion.py,sha256=NgTdEqV0Hx-7Ay1GVduzZ7jnkVIqLxxfpoI4AR8SVak,924
7
+ doseframe/calculation/relation.py,sha256=GzV4ObosbBsWi8VNyfMn2FWGLczf59t9510lavxwXTc,4945
8
+ doseframe/calculation/single_dose.py,sha256=l2bQXSdrZtQcHFes17faVHfDDQaDadqvYlbC0mAGOz8,2301
9
+ doseframe/calculation/steps.py,sha256=2FM6oplpO4V8oVH7wfo3ylieWtB4WifD6jKWUn6aDek,871
10
+ doseframe/calculation/strategies.py,sha256=79DiE0gH8iJQnnyhydxStopqyBaB594BINT_tQb-PGk,3893
11
+ doseframe/calculation/strategy.py,sha256=oDZh80Jmz5YyYOqfvU7jok1Y9yzoxDmn9nzx2dcWZms,1207
12
+ doseframe/checks/__init__.py,sha256=-hQcKvl--tbiE7kq3nS0quWJ7wttYw6JkSQR_k8Z2LM,529
13
+ doseframe/checks/chain.py,sha256=-_E3IJqZq7SsS3BFfaP0Sn7aFgomulF6R90OF6RP2UU,8039
14
+ doseframe/checks/context.py,sha256=jEBrJ-ddvvWPieQ7gj4vMFMhg81wR8rm2RFlKCNdM_I,1537
15
+ doseframe/findings/__init__.py,sha256=DwAlYdRP51IcsWUYqjdcdWgzYYTOTWFZZCHJYGQTtn4,1688
16
+ doseframe/protocols/__init__.py,sha256=vSoZjiNKhIoUZ8g4Mygiz7rH5-kQ0N0bg-DldNMfsqg,2650
17
+ doseframe/protocols/activation.py,sha256=YHhWvxm8MjS8QpicZ6WT8-5Zw5S78cU_zQ0mH6D0iWM,1775
18
+ doseframe/protocols/device.py,sha256=o2Auj2zR5TlbVhpIJRJo8NTVb5CaYOwgc1wrqQQgA9s,1648
19
+ doseframe/protocols/diff.py,sha256=1N2mXpM_zZyb3mWuV6XLlVkVBrYciva4pDfgE9sXwWU,2409
20
+ doseframe/protocols/errors.py,sha256=ZK4EqKwzF9Ht2aEUjItIstpxNLLAl053puF9xz3aKu4,786
21
+ doseframe/protocols/limits.py,sha256=k-WiGr2zejcElNN35jk6MSwSdkRAdaf2hLminMjp4gM,2331
22
+ doseframe/protocols/model.py,sha256=D4_a-wbef9tR4VYdgJhmI6zxzStGPOwh1r9_dXWReRA,1080
23
+ doseframe/protocols/naming.py,sha256=MzWdbvFcXOGayGs4bjJUFAhaxehQ8ld7_e1ACB9LG10,4698
24
+ doseframe/protocols/reference.py,sha256=MlPv8xt5sxQrlGUu0d0AZh8JCQZQR6CqRcAHtqLAT4o,6665
25
+ doseframe/protocols/schemes.py,sha256=FqhWFwCxv_-U2Jik7o0bDcko3uMlPzhDDyV4MT-DtEY,22957
26
+ doseframe/protocols/single_dose.py,sha256=jsoUxyyI84COo_g_uf_j6UVTdCt_0xAoYarIIgcZgis,9019
27
+ doseframe/protocols/version.py,sha256=M-IJ5fWMHKLRlttSEb0FcEfmf_AXx9sCTpmQ6-eVCwY,25917
28
+ doseframe/rounding/__init__.py,sha256=yGSGbChcLHNr5kuDfhjJouIsQP3z5PNbPUM3jA9zOhI,531
29
+ doseframe/rounding/policy.py,sha256=zrT29e-jZLKE9erj-DQRSzG9aAM2RA-wPHxBfPAKBE8,4044
30
+ doseframe/units/__init__.py,sha256=D_ZEwlciN9oGCyfPCwncbjVdsdRBCEZGWifwD5QE8LY,1130
31
+ doseframe/units/catalog.py,sha256=AUrwIvV4DoTMB52NM2rXp5WBk_KaENgaeHWbavsOsEY,5245
32
+ doseframe/units/decimal_context.py,sha256=d7CiDir4i9HtqkhEMpcvbCSEgcLzmPAroggWEBh6qWs,608
33
+ doseframe/units/errors.py,sha256=U7n1VnbF9bTjUN0ebX63XFGqB25UK-GWRaDl9ejQyWo,818
34
+ doseframe/units/options.py,sha256=sD4gcj06LVHZlcCLt0qMbc75otYEpnXdgRxKbRaNlAw,1761
35
+ doseframe/units/quantity.py,sha256=he9_ycv13NJslIvPfsqe-jiKiFwbaBFrcFWW0Esv60c,5999
36
+ doseframe/units/unit.py,sha256=-IvEkHZBdnM3PKCIg7PpAqP9mvCnLXnVIjY0ms5jPiw,5411
37
+ doseframe/use_cases/__init__.py,sha256=_eTlUW1ml1JZzaO0PyljWnKAjfkJtIczRhczYU3K6JM,1745
38
+ doseframe/use_cases/clinical.py,sha256=ylcz7LyvOCUp-jQPsstETK1UhDD1kVUiTYzWrmSZrHA,29245
39
+ doseframe/use_cases/gate.py,sha256=m7C4KrCbLoXi8I-nidPDwZWkm4n6oWfE8vR35OHAufQ,3468
40
+ doseframe/use_cases/governance.py,sha256=69J2B9kSqk-tUPumO4HWOkuUu6_r6ff1D0DR_LLJ2ZI,18529
41
+ doseframe/use_cases/ports.py,sha256=x19Upnq9XCF37q6Z6CvWTi2aRbixePrqOgRNfCJW3m8,2435
42
+ doseframe/use_cases/results.py,sha256=JUfExh4cEw6MbIqj_CUlQvEko9DxA2JhwASj_M9bV9I,5369
43
+ doseframe-0.2.0.dist-info/METADATA,sha256=l8Yf9hupoEvBCIuDJeGd76VygTCXR-5_fzUjPs24P9Q,3252
44
+ doseframe-0.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
45
+ doseframe-0.2.0.dist-info/licenses/LICENSE,sha256=rMRHt3orXPkQAOsx6UaBnBkrf2c68pPLhrneDDwZC6k,1071
46
+ doseframe-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Simon Bernbeck
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.