sha-claim 0.1.2__tar.gz

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 (120) hide show
  1. sha_claim-0.1.2/.gitignore +29 -0
  2. sha_claim-0.1.2/CHANGELOG.md +35 -0
  3. sha_claim-0.1.2/LICENSE +176 -0
  4. sha_claim-0.1.2/PKG-INFO +152 -0
  5. sha_claim-0.1.2/README.md +115 -0
  6. sha_claim-0.1.2/docs/GUIDE.md +1593 -0
  7. sha_claim-0.1.2/docs/api/README.md +31 -0
  8. sha_claim-0.1.2/docs/api/spec/auth.json +142 -0
  9. sha_claim-0.1.2/docs/api/spec/eclaims.json +17038 -0
  10. sha_claim-0.1.2/docs/api/spec/examples.json +5478 -0
  11. sha_claim-0.1.2/postman/README.md +18 -0
  12. sha_claim-0.1.2/pyproject.toml +114 -0
  13. sha_claim-0.1.2/src/sha_claim/__init__.py +185 -0
  14. sha_claim-0.1.2/src/sha_claim/adapters/__init__.py +0 -0
  15. sha_claim-0.1.2/src/sha_claim/adapters/wire/__init__.py +0 -0
  16. sha_claim-0.1.2/src/sha_claim/adapters/wire/error_translator.py +53 -0
  17. sha_claim-0.1.2/src/sha_claim/adapters/wire/http_gateways.py +421 -0
  18. sha_claim-0.1.2/src/sha_claim/adapters/wire/mappers.py +509 -0
  19. sha_claim-0.1.2/src/sha_claim/adapters/wire/parsing.py +24 -0
  20. sha_claim-0.1.2/src/sha_claim/adapters/wire/requests.py +626 -0
  21. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/__init__.py +0 -0
  22. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/authorization.py +31 -0
  23. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/benefits.py +81 -0
  24. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/claim.py +148 -0
  25. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/common.py +95 -0
  26. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/eligibility.py +43 -0
  27. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/emergency.py +14 -0
  28. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/files.py +17 -0
  29. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/preauth.py +36 -0
  30. sha_claim-0.1.2/src/sha_claim/adapters/wire/schemas/prescription.py +44 -0
  31. sha_claim-0.1.2/src/sha_claim/adapters/wire/transport.py +57 -0
  32. sha_claim-0.1.2/src/sha_claim/client.py +294 -0
  33. sha_claim-0.1.2/src/sha_claim/domain/__init__.py +0 -0
  34. sha_claim-0.1.2/src/sha_claim/domain/attachments.py +37 -0
  35. sha_claim-0.1.2/src/sha_claim/domain/benefits.py +97 -0
  36. sha_claim-0.1.2/src/sha_claim/domain/claim.py +353 -0
  37. sha_claim-0.1.2/src/sha_claim/domain/codes.py +91 -0
  38. sha_claim-0.1.2/src/sha_claim/domain/consent.py +82 -0
  39. sha_claim-0.1.2/src/sha_claim/domain/eligibility.py +71 -0
  40. sha_claim-0.1.2/src/sha_claim/domain/emergency.py +89 -0
  41. sha_claim-0.1.2/src/sha_claim/domain/enums.py +128 -0
  42. sha_claim-0.1.2/src/sha_claim/domain/files.py +25 -0
  43. sha_claim-0.1.2/src/sha_claim/domain/identifiers.py +81 -0
  44. sha_claim-0.1.2/src/sha_claim/domain/money.py +81 -0
  45. sha_claim-0.1.2/src/sha_claim/domain/practitioner.py +26 -0
  46. sha_claim-0.1.2/src/sha_claim/domain/preauth.py +119 -0
  47. sha_claim-0.1.2/src/sha_claim/domain/prescription.py +125 -0
  48. sha_claim-0.1.2/src/sha_claim/errors.py +86 -0
  49. sha_claim-0.1.2/src/sha_claim/events.py +37 -0
  50. sha_claim-0.1.2/src/sha_claim/infrastructure/__init__.py +0 -0
  51. sha_claim-0.1.2/src/sha_claim/infrastructure/auth.py +104 -0
  52. sha_claim-0.1.2/src/sha_claim/infrastructure/clock.py +12 -0
  53. sha_claim-0.1.2/src/sha_claim/infrastructure/logging.py +27 -0
  54. sha_claim-0.1.2/src/sha_claim/infrastructure/retry.py +34 -0
  55. sha_claim-0.1.2/src/sha_claim/infrastructure/transport.py +167 -0
  56. sha_claim-0.1.2/src/sha_claim/ports/__init__.py +0 -0
  57. sha_claim-0.1.2/src/sha_claim/ports/claim_gateways.py +18 -0
  58. sha_claim-0.1.2/src/sha_claim/ports/clock.py +14 -0
  59. sha_claim-0.1.2/src/sha_claim/ports/consent_gateway.py +27 -0
  60. sha_claim-0.1.2/src/sha_claim/ports/eligibility_gateway.py +42 -0
  61. sha_claim-0.1.2/src/sha_claim/ports/emergency_gateway.py +25 -0
  62. sha_claim-0.1.2/src/sha_claim/ports/file_gateway.py +12 -0
  63. sha_claim-0.1.2/src/sha_claim/ports/preauth_gateway.py +25 -0
  64. sha_claim-0.1.2/src/sha_claim/ports/prescription_gateway.py +19 -0
  65. sha_claim-0.1.2/src/sha_claim/ports/token_provider.py +13 -0
  66. sha_claim-0.1.2/src/sha_claim/ports/virtual_claim_gateway.py +105 -0
  67. sha_claim-0.1.2/src/sha_claim/py.typed +0 -0
  68. sha_claim-0.1.2/src/sha_claim/session.py +408 -0
  69. sha_claim-0.1.2/src/sha_claim/settings.py +85 -0
  70. sha_claim-0.1.2/src/sha_claim/use_cases/__init__.py +0 -0
  71. sha_claim-0.1.2/src/sha_claim/use_cases/capture_consent.py +35 -0
  72. sha_claim-0.1.2/src/sha_claim/use_cases/open_visit.py +29 -0
  73. sha_claim-0.1.2/src/sha_claim/use_cases/submit_claim.py +24 -0
  74. sha_claim-0.1.2/src/sha_claim/use_cases/verify_eligibility.py +28 -0
  75. sha_claim-0.1.2/tests/__init__.py +0 -0
  76. sha_claim-0.1.2/tests/conftest.py +29 -0
  77. sha_claim-0.1.2/tests/contract/__init__.py +0 -0
  78. sha_claim-0.1.2/tests/contract/adapters/__init__.py +0 -0
  79. sha_claim-0.1.2/tests/contract/adapters/test_balances_and_files_wire.py +76 -0
  80. sha_claim-0.1.2/tests/contract/adapters/test_benefit_and_consent_mapping.py +83 -0
  81. sha_claim-0.1.2/tests/contract/adapters/test_claim_mapping.py +130 -0
  82. sha_claim-0.1.2/tests/contract/adapters/test_claim_requests.py +164 -0
  83. sha_claim-0.1.2/tests/contract/adapters/test_eligibility_mapping.py +34 -0
  84. sha_claim-0.1.2/tests/contract/adapters/test_emergency_wire.py +108 -0
  85. sha_claim-0.1.2/tests/contract/adapters/test_error_envelope.py +50 -0
  86. sha_claim-0.1.2/tests/contract/adapters/test_error_translator.py +61 -0
  87. sha_claim-0.1.2/tests/contract/adapters/test_portal_examples.py +114 -0
  88. sha_claim-0.1.2/tests/contract/adapters/test_preauth_wire.py +141 -0
  89. sha_claim-0.1.2/tests/contract/adapters/test_prescription_wire.py +93 -0
  90. sha_claim-0.1.2/tests/contract/adapters/test_requests.py +41 -0
  91. sha_claim-0.1.2/tests/contract/adapters/test_spec_drift.py +187 -0
  92. sha_claim-0.1.2/tests/contract/infrastructure/__init__.py +0 -0
  93. sha_claim-0.1.2/tests/contract/infrastructure/test_auth.py +106 -0
  94. sha_claim-0.1.2/tests/contract/infrastructure/test_events.py +58 -0
  95. sha_claim-0.1.2/tests/contract/infrastructure/test_transport.py +149 -0
  96. sha_claim-0.1.2/tests/contract/test_client.py +370 -0
  97. sha_claim-0.1.2/tests/fixtures/authorization_pending.json +56 -0
  98. sha_claim-0.1.2/tests/fixtures/benefits.json +20 -0
  99. sha_claim-0.1.2/tests/fixtures/eligibility_member_found.json +43 -0
  100. sha_claim-0.1.2/tests/fixtures/interventions.json +220 -0
  101. sha_claim-0.1.2/tests/fixtures/sub_benefits.json +37 -0
  102. sha_claim-0.1.2/tests/fixtures/virtual_claim_opened.json +101 -0
  103. sha_claim-0.1.2/tests/live/__init__.py +0 -0
  104. sha_claim-0.1.2/tests/live/test_uat_smoke.py +156 -0
  105. sha_claim-0.1.2/tests/unit/__init__.py +0 -0
  106. sha_claim-0.1.2/tests/unit/domain/__init__.py +0 -0
  107. sha_claim-0.1.2/tests/unit/domain/test_claim_commands.py +63 -0
  108. sha_claim-0.1.2/tests/unit/domain/test_codes.py +18 -0
  109. sha_claim-0.1.2/tests/unit/domain/test_consent_and_attachments.py +34 -0
  110. sha_claim-0.1.2/tests/unit/domain/test_eligibility.py +41 -0
  111. sha_claim-0.1.2/tests/unit/domain/test_enums.py +25 -0
  112. sha_claim-0.1.2/tests/unit/domain/test_identifiers.py +31 -0
  113. sha_claim-0.1.2/tests/unit/domain/test_money.py +43 -0
  114. sha_claim-0.1.2/tests/unit/domain/test_submission_blockers.py +136 -0
  115. sha_claim-0.1.2/tests/unit/test_parsing_and_logging.py +46 -0
  116. sha_claim-0.1.2/tests/unit/test_session_and_submit.py +606 -0
  117. sha_claim-0.1.2/tests/unit/test_settings.py +37 -0
  118. sha_claim-0.1.2/tests/unit/use_cases/__init__.py +0 -0
  119. sha_claim-0.1.2/tests/unit/use_cases/test_consent_and_visit.py +104 -0
  120. sha_claim-0.1.2/tests/unit/use_cases/test_verify_eligibility.py +31 -0
@@ -0,0 +1,29 @@
1
+ # secrets — never commit
2
+ .env
3
+ .env.*
4
+ !.env.example
5
+
6
+ # python
7
+ __pycache__/
8
+ *.py[cod]
9
+ *.egg-info/
10
+ dist/
11
+ build/
12
+ .venv/
13
+ venv/
14
+ /.venv/
15
+ /.venv
16
+ .mypy_cache/
17
+ .pytest_cache/
18
+ .ruff_cache/
19
+ .import_linter_cache/
20
+ .hypothesis/
21
+ .coverage
22
+ coverage.xml
23
+ htmlcov/
24
+
25
+ # os / ide
26
+ .DS_Store
27
+ .idea/
28
+ .vscode/
29
+ postman/*.local.json
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. Format: [Keep a Changelog](https://keepachangelog.com), versioning: [SemVer](https://semver.org).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.1.2] — 2026-09-20
8
+
9
+ First public release. 49/49 published eClaims endpoints. Live-verified on DHA UAT through visit → diagnosis → line →
10
+ preview; `submit` verified up to the doctor-attachment rule (needs an HWR-registered practitioner). Pre-auth nested
11
+ request arrays remain unverified (docs/api/WORKFLOWS.md Q3). API is 0.x: expect breaking changes before 1.0.
12
+ ### Added
13
+ - `consent.send_otp()` (`POST /claims/otp`), `consent.list(patient)`, `session.add_doctor()`; `submit()` takes `discharge_reason` + discharge `otp` (all required by UAT, none documented). `discharge()` now takes a tz-aware `discharged_at`.
14
+ - Wire models treat `null` as absent. `ClaimWorkflowState` / `AuthorizationStatus` populated from live observations.
15
+ - `on_event` hook on `AsyncSHAClient`: one `SDKEvent` per HTTP attempt (operation, status, duration, attempt, trace_id, redacted consent token, error). Emit-only.
16
+ - `VirtualClaim.submission_blockers()` — pure pre-submit check over the server's preview snapshot.
17
+ - `.github/workflows/live.yml` — scheduled UAT smoke run.
18
+ - `docs/GUIDE.md` — consumer guide: every method with parameters, wire call and result fields; recipes; gotchas; generated appendix.
19
+ - Project skeleton, quality gates (ruff, mypy strict, import-linter, pytest ≥ 90 % coverage), CI.
20
+ - Endpoint reference and workflow documentation generated from the DHA AfyaConnect portal, including the portal's example request/response JSON for every endpoint.
21
+ - `Invoice` (with `lines`) on `VirtualClaim`; typed `PayerClaimRecord` (`workflow_state`, `tracking_number`, `proposed_value`, …).
22
+ - `AsyncSHAClient` with OAuth2 client-credentials auth (cached, single-flight refresh, 401 replay), idempotent-only retries with jittered backoff, typed error translation (incl. `trace_id`).
23
+ - `sha.eligibility.check()` — `GET /patients/eligibility` mapped to an `Eligibility` read model; verified against DHA UAT.
24
+ - `sha.eligibility.benefits/sub_benefits/interventions()` — benefit hierarchy with tariffs and preauth flags; `InterventionCoverage.service_type_for_authorization` encodes the CAPITATION rule observed on UAT.
25
+ - `sha.consent.authorize/get/reject()` — two-step OTP consent (authorize sends the OTP); verified live incl. reject.
26
+ - `sha.claims.open_visit()` — opens the virtual claim with `Otp`, `BiometricGuid` or `MatchId` proof; returns `VirtualClaim` with a redacted `ConsentToken`.
27
+ - `ClaimSession` (from `sha.claims.open_visit()` or `sha.claims.resume(token)`): add/retire/restore interventions, add/remove diagnoses, add/remove/edit billing lines, attach/remove documents, `preview`, `submit` (attempted once; ambiguity → `SubmissionOutcomeUnknownError`), `close`, `payer_status`. 15 endpoints, contract-tested against the published spec.
28
+ - Pre-authorisation on `ClaimSession`: `request_preauth`, `preauths`, `remove_preauth_diagnosis`, `remove_preauth_doctor`, `cancel_preauth`, `request_doctor_consent`. Nested array encoding follows the API's own field vocabulary and is isolated in one function pending UAT confirmation.
29
+ - Inpatient discharge (`send_discharge_otp`, `discharge`), `add_next_of_kin`, `resubmit_lines` on `ClaimSession`.
30
+ - ePrescriptions on `ClaimSession`: `prescribe` (`MedicationOrder` items), `prescription`, `dispense` (`DispensedProduct`), `remove_prescription_doctor`. Request bodies asserted against the portal's published item shapes.
31
+ - Emergency: `sha.emergency.open_case()` (identified or unidentified casualty) → `ClaimSession`; `sha.emergency.protocols()`; on the session `add_protocol`, `add_emergency_doctor`, `remove_emergency_doctor`, `open_emt_claim`.
32
+ - `ClaimGateways` bundle: `ClaimSession` takes one gateway set instead of a growing argument list.
33
+ - `switch_intervention` on `ClaimSession`; `sha.eligibility.utilization / pomsf_balances / bed_occupancy`; `sha.files.upload / download_link`. All 49 published endpoints now have a request builder, guarded by a test.
34
+ - Error translation unwraps upstream JSON blobs in `error`, `details[]`, and trailing JSON in `message`.
35
+ - Domain value objects: identifiers (redacted `ConsentToken`), ICD/intervention codes, `Money`, documented enums, lenient server-status enums.
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.5
2
+ Name: sha-claim
3
+ Version: 0.1.2
4
+ Summary: Python SDK for Kenya SHA claims via the DHA AfyaConnect HIE eClaims API
5
+ Project-URL: Homepage, https://github.com/kahdichienja/rocket
6
+ Project-URL: Documentation, https://github.com/kahdichienja/rocket/blob/main/docs/GUIDE.md
7
+ Project-URL: Changelog, https://github.com/kahdichienja/rocket/blob/main/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/kahdichienja/rocket/issues
9
+ Author: NaCare
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: afyaconnect,claims,dha,health,hie,kenya,sha
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Healthcare Industry
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: httpx>=0.27
25
+ Requires-Dist: pydantic>=2.7
26
+ Provides-Extra: dev
27
+ Requires-Dist: hypothesis>=6; extra == 'dev'
28
+ Requires-Dist: import-linter>=2; extra == 'dev'
29
+ Requires-Dist: mypy>=1.11; extra == 'dev'
30
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
31
+ Requires-Dist: pytest-cov>=5; extra == 'dev'
32
+ Requires-Dist: pytest>=8; extra == 'dev'
33
+ Requires-Dist: python-dotenv>=1; extra == 'dev'
34
+ Requires-Dist: respx>=0.21; extra == 'dev'
35
+ Requires-Dist: ruff>=0.6; extra == 'dev'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # sha-claim
39
+
40
+ Python SDK for **Social Health Authority (SHA, Kenya)** claims through the Digital Health Agency's
41
+ **AfyaConnect HIE eClaims API**. Async-first, typed, framework-free.
42
+
43
+ > Status: pre-release (`0.1.0.dev0`). All 49 published endpoints implemented. Eligibility, benefits and consent are
44
+ > verified live against DHA UAT; the claim lifecycle (`ClaimSession`) is contract-tested against the published
45
+ > spec and awaits a UAT beneficiary with a reachable phone for live verification. See [PLAN.md](PLAN.md).
46
+
47
+ ## Install
48
+
49
+ ```bash
50
+ pip install sha-claim
51
+ ```
52
+
53
+ ## Configure
54
+
55
+ Credentials come from DHA onboarding. The facility is implied by the credential (it is embedded in the token).
56
+
57
+ ```bash
58
+ export SHA_ENVIRONMENT=uat # uat | production (production also needs SHA_BASE_URL)
59
+ export SHA_CLIENT_ID=...
60
+ export SHA_CLIENT_SECRET=...
61
+ ```
62
+
63
+ ## Use
64
+
65
+ ```python
66
+ import asyncio
67
+ from datetime import date
68
+ from sha_claim import AsyncSHAClient, IdentificationType, BadRequestError
69
+
70
+
71
+ async def main() -> None:
72
+ async with AsyncSHAClient.from_env() as sha:
73
+ try:
74
+ e = await sha.eligibility.check("12345678", IdentificationType.NATIONAL_ID)
75
+ except BadRequestError as err: # server-side validation, carries trace_id
76
+ print(err.trace_id, err)
77
+ return
78
+ if e.is_covered_on(date.today()):
79
+ print(e.full_name, e.patient_id, [s.name for s in e.active_schemes_on(date.today())])
80
+
81
+
82
+ asyncio.run(main())
83
+ ```
84
+
85
+ ### A claim, end to end
86
+
87
+ ```python
88
+ from sha_claim import (
89
+ AsyncSHAClient,
90
+ Money,
91
+ Otp,
92
+ ServiceType,
93
+ DocumentType,
94
+ Attachment,
95
+ SubmissionOutcomeUnknownError,
96
+ )
97
+
98
+ async with AsyncSHAClient.from_env() as sha:
99
+ patient = (await sha.eligibility.check("12345678", IdentificationType.NATIONAL_ID)).patient_id
100
+ coverage = await sha.eligibility.interventions(patient, "SHA-12-SC-01")
101
+ consultation = next(c for c in coverage if c.name == "Consultation")
102
+
103
+ # 1. consent: this sends the OTP to the beneficiary's registered phone
104
+ auth = await sha.consent.authorize(
105
+ patient, consultation.service_type_for_authorization, [consultation.code]
106
+ )
107
+
108
+ # 2. open the server-side virtual claim with the OTP the patient read out
109
+ session = await sha.claims.open_visit(
110
+ patient, consultation.service_type_for_authorization, [consultation.code], Otp("123456")
111
+ )
112
+
113
+ # 3. build it — every call is keyed by the session's consent_token
114
+ await session.add_diagnosis("1A00", consultation.code)
115
+ await session.add_line(consultation.code, Money.kes("1500"), quantity=1, diagnoses=["1A00"])
116
+ await session.attach(Attachment.from_path("invoice.pdf", DocumentType.INVOICE), consultation.code)
117
+
118
+ # 4. verify, then submit exactly once
119
+ preview = await session.preview()
120
+ try:
121
+ claim = await session.submit(invoice_number="INV-2026-000123")
122
+ except SubmissionOutcomeUnknownError:
123
+ claim = await session.preview() # the server knows whether it went through; ask it
124
+
125
+ # later, from any process that persisted the token:
126
+ status = await sha.claims.resume(claim.consent_token).payer_status("INV-2026-000123")
127
+ ```
128
+
129
+ Every error is a subclass of `sha_claim.SHAClaimError`; see `sha_claim.errors`.
130
+
131
+ **New to the SDK?** Read the [Consumer Guide](docs/GUIDE.md) — every method, its parameters, the HTTP call it makes, and the object it returns, plus end-to-end recipes.
132
+
133
+ ## Design in one paragraph
134
+
135
+ The server owns the claim: you open a *virtual claim*, receive a `consent_token`, mutate the claim
136
+ call by call, then submit. The SDK mirrors that faithfully — it holds **snapshots**, not a local
137
+ state machine — and only rejects locally what the server will certainly reject. Reads are retried
138
+ with backoff; `submit` is attempted exactly once. Layers follow Clean Architecture and are enforced
139
+ by `import-linter`. Details: [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md); API reference generated
140
+ from the official portal: [docs/api/](docs/api/README.md).
141
+
142
+ ## Develop
143
+
144
+ ```bash
145
+ make install # venv + editable install with dev extras
146
+ make check # ruff, mypy --strict, import-linter, pytest (≥ 90 % coverage)
147
+ make live # RUN_LIVE=1: smoke tests against DHA UAT (needs .env)
148
+ ```
149
+
150
+ ## License
151
+
152
+ Apache-2.0
@@ -0,0 +1,115 @@
1
+ # sha-claim
2
+
3
+ Python SDK for **Social Health Authority (SHA, Kenya)** claims through the Digital Health Agency's
4
+ **AfyaConnect HIE eClaims API**. Async-first, typed, framework-free.
5
+
6
+ > Status: pre-release (`0.1.0.dev0`). All 49 published endpoints implemented. Eligibility, benefits and consent are
7
+ > verified live against DHA UAT; the claim lifecycle (`ClaimSession`) is contract-tested against the published
8
+ > spec and awaits a UAT beneficiary with a reachable phone for live verification. See [PLAN.md](PLAN.md).
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pip install sha-claim
14
+ ```
15
+
16
+ ## Configure
17
+
18
+ Credentials come from DHA onboarding. The facility is implied by the credential (it is embedded in the token).
19
+
20
+ ```bash
21
+ export SHA_ENVIRONMENT=uat # uat | production (production also needs SHA_BASE_URL)
22
+ export SHA_CLIENT_ID=...
23
+ export SHA_CLIENT_SECRET=...
24
+ ```
25
+
26
+ ## Use
27
+
28
+ ```python
29
+ import asyncio
30
+ from datetime import date
31
+ from sha_claim import AsyncSHAClient, IdentificationType, BadRequestError
32
+
33
+
34
+ async def main() -> None:
35
+ async with AsyncSHAClient.from_env() as sha:
36
+ try:
37
+ e = await sha.eligibility.check("12345678", IdentificationType.NATIONAL_ID)
38
+ except BadRequestError as err: # server-side validation, carries trace_id
39
+ print(err.trace_id, err)
40
+ return
41
+ if e.is_covered_on(date.today()):
42
+ print(e.full_name, e.patient_id, [s.name for s in e.active_schemes_on(date.today())])
43
+
44
+
45
+ asyncio.run(main())
46
+ ```
47
+
48
+ ### A claim, end to end
49
+
50
+ ```python
51
+ from sha_claim import (
52
+ AsyncSHAClient,
53
+ Money,
54
+ Otp,
55
+ ServiceType,
56
+ DocumentType,
57
+ Attachment,
58
+ SubmissionOutcomeUnknownError,
59
+ )
60
+
61
+ async with AsyncSHAClient.from_env() as sha:
62
+ patient = (await sha.eligibility.check("12345678", IdentificationType.NATIONAL_ID)).patient_id
63
+ coverage = await sha.eligibility.interventions(patient, "SHA-12-SC-01")
64
+ consultation = next(c for c in coverage if c.name == "Consultation")
65
+
66
+ # 1. consent: this sends the OTP to the beneficiary's registered phone
67
+ auth = await sha.consent.authorize(
68
+ patient, consultation.service_type_for_authorization, [consultation.code]
69
+ )
70
+
71
+ # 2. open the server-side virtual claim with the OTP the patient read out
72
+ session = await sha.claims.open_visit(
73
+ patient, consultation.service_type_for_authorization, [consultation.code], Otp("123456")
74
+ )
75
+
76
+ # 3. build it — every call is keyed by the session's consent_token
77
+ await session.add_diagnosis("1A00", consultation.code)
78
+ await session.add_line(consultation.code, Money.kes("1500"), quantity=1, diagnoses=["1A00"])
79
+ await session.attach(Attachment.from_path("invoice.pdf", DocumentType.INVOICE), consultation.code)
80
+
81
+ # 4. verify, then submit exactly once
82
+ preview = await session.preview()
83
+ try:
84
+ claim = await session.submit(invoice_number="INV-2026-000123")
85
+ except SubmissionOutcomeUnknownError:
86
+ claim = await session.preview() # the server knows whether it went through; ask it
87
+
88
+ # later, from any process that persisted the token:
89
+ status = await sha.claims.resume(claim.consent_token).payer_status("INV-2026-000123")
90
+ ```
91
+
92
+ Every error is a subclass of `sha_claim.SHAClaimError`; see `sha_claim.errors`.
93
+
94
+ **New to the SDK?** Read the [Consumer Guide](docs/GUIDE.md) — every method, its parameters, the HTTP call it makes, and the object it returns, plus end-to-end recipes.
95
+
96
+ ## Design in one paragraph
97
+
98
+ The server owns the claim: you open a *virtual claim*, receive a `consent_token`, mutate the claim
99
+ call by call, then submit. The SDK mirrors that faithfully — it holds **snapshots**, not a local
100
+ state machine — and only rejects locally what the server will certainly reject. Reads are retried
101
+ with backoff; `submit` is attempted exactly once. Layers follow Clean Architecture and are enforced
102
+ by `import-linter`. Details: [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md); API reference generated
103
+ from the official portal: [docs/api/](docs/api/README.md).
104
+
105
+ ## Develop
106
+
107
+ ```bash
108
+ make install # venv + editable install with dev extras
109
+ make check # ruff, mypy --strict, import-linter, pytest (≥ 90 % coverage)
110
+ make live # RUN_LIVE=1: smoke tests against DHA UAT (needs .env)
111
+ ```
112
+
113
+ ## License
114
+
115
+ Apache-2.0