-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
341 lines (317 loc) · 12.5 KB
/
example.py
File metadata and controls
341 lines (317 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
import os
from datetime import datetime, timedelta
from pydrg.helpers.claim_examples import (
claim_example,
json_claim_example,
opps_claim_example,
)
from pydrg.input import (
DiagnosisCode,
LineItem,
PoaType,
Provider,
ValueCode,
OasisAssessment,
IrfPai,
OccurrenceCode,
ProcedureCode,
ICDConvertOptions,
Modules,
ICDConvertOption,
)
from pydrg.pypps import Pypps
def run_groupers(pypps: Pypps):
"""Runs all grouper examples."""
print("""
====================
Running Grouper Examples
====================
""")
# MCE Grouper
print("--- MCE Claim Example ---")
mce_claim = claim_example()
mce_claim.claimid = "MCE_CLAIM_001"
mce_output = pypps.mce_client.process(mce_claim)
print(mce_output.model_dump_json(indent=2))
# MS-DRG Grouper
print("--- MS-DRG Claim Example ---")
drg_claim = json_claim_example()
drg_claim.claimid = "DRG_CLAIM_001"
drg_output = pypps.drg_client.process(drg_claim)
print(drg_output.model_dump_json(indent=2))
# IOCE Grouper
print("--- IOCE Claim Example ---")
ioce_claim = opps_claim_example()
ioce_claim.claimid = "IOCE_CLAIM_001"
ioce_output = pypps.ioce_client.process(ioce_claim)
print(ioce_output.model_dump_json(indent=2))
# IRF Grouper
print("--- IRF Grouper Example ---")
irf_claim = claim_example()
irf_claim.claimid = "IRF_CLAIM_001"
irf_claim.oasis_assessment = None
irf_claim.billing_provider.other_id = "013025"
irf_claim.irf_pai = IrfPai()
irf_claim.principal_dx.code = "D61.03"
irf_claim.admit_date = datetime(2025, 1, 1)
irf_claim.thru_date = datetime(2025, 1, 30)
irf_claim.patient.date_of_birth = datetime(1970, 1, 1)
irf_claim.secondary_dxs.clear()
irf_claim.irf_pai.assessment_system = "IRF-PAI"
irf_claim.irf_pai.transaction_type = 1
irf_claim.irf_pai.impairment_admit_group_code = "0012.9 "
irf_claim.irf_pai.eating_self_admsn_cd = "06"
irf_claim.irf_pai.oral_hygne_admsn_cd = "06"
irf_claim.irf_pai.toileting_hygne_admsn_cd = "06"
irf_claim.irf_pai.bathing_hygne_admsn_cd = "06"
irf_claim.irf_pai.footwear_dressing_cd = "06"
irf_claim.irf_pai.chair_bed_transfer_cd = "06"
irf_claim.irf_pai.toilet_transfer_cd = "06"
irf_claim.irf_pai.walk_10_feet_cd = "06"
irf_claim.irf_pai.walk_50_feet_cd = "06"
irf_claim.irf_pai.walk_150_feet_cd = "06"
irf_claim.irf_pai.step_1_cd = "06"
irf_claim.irf_pai.urinary_continence_cd = "0"
irf_claim.irf_pai.bowel_continence_cd = "0"
irf_output = pypps.irfg_client.process(irf_claim)
print(irf_output.model_dump_json(indent=2))
def run_pricers(pypps: Pypps):
"""Runs all pricer examples."""
print("""
====================
Running Pricer Examples
====================
""")
# IPPS Pricer
if pypps.ipps_client:
print("--- IPPS Pricer Example ---")
ipps_claim = claim_example()
ipps_claim.claimid = "IPPS_CLAIM_001"
drg_output = pypps.drg_client.process(ipps_claim)
ipps_output = pypps.ipps_client.process(ipps_claim, drg_output)
print(ipps_output.model_dump_json(indent=2))
# OPPS Pricer
if pypps.opps_client:
print("--- OPPS Pricer Example ---")
opps_claim = opps_claim_example()
opps_claim.claimid = "OPPS_CLAIM_001"
ioce_output = pypps.ioce_client.process(opps_claim)
opps_output = pypps.opps_client.process(opps_claim, ioce_output)
print(opps_output.model_dump_json(indent=2))
# IPF Pricer
if pypps.ipf_client:
print("--- IPF Pricer Example ---")
ipf_claim = claim_example()
ipf_claim.claimid = "IPF_CLAIM_001"
drg_output = pypps.drg_client.process(ipf_claim)
ipf_output = pypps.ipf_client.process(ipf_claim, drg_output)
print(ipf_output.model_dump_json(indent=2))
# LTCH Pricer
if pypps.ltch_client:
print("--- LTCH Pricer Example ---")
ltch_claim = claim_example()
if ltch_claim.billing_provider is None:
ltch_claim.billing_provider = Provider()
ltch_claim.claimid = "LTCH_CLAIM_001"
ltch_claim.billing_provider.other_id = "012006"
ltch_claim.inpatient_pxs.append(ProcedureCode(code="XW033H4"))
ltch_claim.from_date = datetime(2023, 10, 1)
ltch_claim.thru_date = datetime(2023, 10, 10)
ltch_claim.admit_date = datetime(2023, 10, 1)
ltch_claim.icd_convert = ICDConvertOptions(option=ICDConvertOption.AUTO)
drg_output = pypps.drg_client.process(
ltch_claim,
drg_version="430",
icd_converter=pypps.icd10_converter,
poa_exempt=True,
)
ltch_output = pypps.ltch_client.process(ltch_claim, drg_output)
print(ltch_output.model_dump_json(indent=2))
# Hospice Pricer
if pypps.hospice_client:
print("--- Hospice Pricer Example ---")
hospice_claim = claim_example()
hospice_claim.claimid = "HOSPICE_CLAIM_001"
hospice_claim.bill_type = "812"
hospice_claim.patient_status = "40"
hospice_claim.value_codes.append(ValueCode(code="61", amount=35300.00))
hospice_claim.value_codes.append(ValueCode(code="G8", amount=35300.00))
hospice_claim.thru_date = datetime(2025, 7, 10)
hospice_claim.los = 10
hospice_claim.lines.append(
LineItem(
hcpcs="Q5001",
revenue_code="0651",
service_date=datetime(2025, 7, 1),
units=9,
charges=10_000.00,
)
)
hospice_claim.lines.append(
LineItem(
hcpcs="G0299",
revenue_code="0551",
service_date=datetime(2025, 7, 1),
units=3,
charges=10_000.00,
)
)
hospice_output = pypps.hospice_client.process(hospice_claim)
print(hospice_output.model_dump_json(indent=2))
# HHA Pricer
if pypps.hha_client:
print("--- HHA Pricer Example ---")
hha_claim = claim_example()
hha_claim.claimid = "HHA_CLAIM_001"
hha_claim.patient.age = 65
hha_claim.patient.address.zip = "35300"
hha_claim.from_date = datetime(2025, 1, 1)
hha_claim.admit_date = datetime(2025, 1, 1)
hha_claim.thru_date = datetime(2025, 1, 30)
hha_claim.bill_type = "329"
hha_claim.los = 30
hha_claim.principal_dx.code = "I10"
hha_claim.principal_dx.poa = PoaType.Y
hha_claim.secondary_dxs.append(DiagnosisCode(code="C50911", poa=PoaType.Y))
hha_claim.billing_provider.other_id = "047127"
hha_claim.lines.clear()
hha_claim.lines.append(
LineItem(service_date=datetime(2025, 1, 30), revenue_code="0420", units=20)
)
hha_claim.lines.append(
LineItem(service_date=datetime(2025, 1, 29), revenue_code="0430", units=20)
)
hha_claim.lines.append(
LineItem(service_date=datetime(2025, 1, 28), revenue_code="0440", units=20)
)
hha_claim.lines.append(
LineItem(service_date=datetime(2025, 1, 27), revenue_code="0550", units=20)
)
hha_claim.occurrence_codes.append(
OccurrenceCode(code="61", date=datetime(2024, 12, 15))
)
hha_claim.oasis_assessment = OasisAssessment()
hha_claim.oasis_assessment.fall_risk = 1
hha_claim.oasis_assessment.multiple_hospital_stays = 1
hha_claim.oasis_assessment.grooming = "1"
hhag_output = pypps.hhag_client.process(hha_claim)
hha_pricer = pypps.hha_client.process(hha_claim, hhag_output)
print(hha_pricer.model_dump_json(indent=2))
# IRF Pricer
if pypps.irf_client:
print("--- IRF Pricer Example ---")
irf_claim = claim_example()
irf_claim.claimid = "IRF_CLAIM_001"
irf_claim.oasis_assessment = None
irf_claim.billing_provider.other_id = "013025"
irf_claim.irf_pai = IrfPai()
irf_claim.principal_dx.code = "D61.03"
irf_claim.admit_date = datetime(2025, 1, 1)
irf_claim.thru_date = datetime(2025, 1, 30)
irf_claim.patient.date_of_birth = datetime(1970, 1, 1)
irf_claim.secondary_dxs.clear()
irf_claim.irf_pai.assessment_system = "IRF-PAI"
irf_claim.irf_pai.transaction_type = 1
irf_claim.irf_pai.impairment_admit_group_code = "0012.9 "
irf_claim.irf_pai.eating_self_admsn_cd = "06"
irf_claim.irf_pai.oral_hygne_admsn_cd = "06"
irf_claim.irf_pai.toileting_hygne_admsn_cd = "06"
irf_claim.irf_pai.bathing_hygne_admsn_cd = "06"
irf_claim.irf_pai.footwear_dressing_cd = "06"
irf_claim.irf_pai.chair_bed_transfer_cd = "06"
irf_claim.irf_pai.toilet_transfer_cd = "06"
irf_claim.irf_pai.walk_10_feet_cd = "06"
irf_claim.irf_pai.walk_50_feet_cd = "06"
irf_claim.irf_pai.walk_150_feet_cd = "06"
irf_claim.irf_pai.step_1_cd = "06"
irf_claim.irf_pai.urinary_continence_cd = "0"
irf_claim.irf_pai.bowel_continence_cd = "0"
irf_output = pypps.irfg_client.process(irf_claim)
irf_pricer = pypps.irf_client.process(irf_claim, irf_output)
print(irf_pricer.model_dump_json(indent=2))
# ESRD Pricer
if pypps.esrd_client:
print("--- ESRD Pricer Example ---")
esrd_claim = claim_example()
esrd_claim.claimid = "ESRD_CLAIM_001"
esrd_claim.billing_provider.other_id = "012525"
esrd_claim.patient.date_of_birth = datetime(1960, 1, 1)
esrd_claim.irf_pai = None
esrd_claim.cond_codes.clear()
esrd_claim.cond_codes.append("74")
esrd_claim.value_codes.clear()
esrd_claim.value_codes.append(ValueCode(code="QH", amount=5000.00))
start_date = datetime(2025, 1, 1)
esrd_claim.esrd_initial_date = datetime(2025, 1, 1)
while start_date < datetime(2025, 1, 26):
line = LineItem()
line.revenue_code = "0821"
line.service_date = start_date
esrd_claim.lines.append(line)
start_date += timedelta(days=1)
esrd_claim.value_codes.append(ValueCode(code="A8", amount=70.0))
esrd_claim.value_codes.append(ValueCode(code="A9", amount=180.0))
esrd_output = pypps.esrd_client.process(esrd_claim)
print(esrd_output.model_dump_json(indent=2))
# FQHC Pricer
if pypps.fqhc_client:
print("--- FQHC Pricer Example ---")
fqhc_claim = opps_claim_example()
fqhc_claim.claimid = "FQHC_CLAIM_001"
fqhc_claim.lines.clear()
fqhc_claim.lines.append(
LineItem(
hcpcs="G0466",
revenue_code="0521",
service_date=datetime(2025, 7, 1),
units=1,
charges=300.00,
)
)
fqhc_claim.lines.append(
LineItem(
hcpcs="36415",
revenue_code="0300",
service_date=datetime(2025, 7, 1),
units=1,
charges=250.00,
)
)
fqhc_claim.lines.append(
LineItem(
hcpcs="99203",
revenue_code="0521",
service_date=datetime(2025, 7, 1),
units=1,
charges=350.00,
)
)
fqhc_claim.from_date = datetime(2025, 7, 1)
fqhc_claim.thru_date = datetime(2025, 7, 1)
fqhc_claim.bill_type = "771"
fqhc_claim.billing_provider = Provider()
fqhc_claim.billing_provider.address.zip = "06040"
ioce_output = pypps.ioce_client.process(fqhc_claim)
fqhc_output = pypps.fqhc_client.process(fqhc_claim, ioce_output)
print(fqhc_output.model_dump_json(indent=2))
def run_pypps_process(pypps: Pypps):
claim = claim_example()
claim.modules = [Modules.MCE, Modules.MSDRG, Modules.IPPS, Modules.PSYCH]
claim.claimid = "PYPPPS_CLAIM_001"
results = pypps.process(claim)
print(results.model_dump_json(indent=2, exclude_none=True))
def main():
"""Main function to run all examples."""
jar_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "jars"))
db_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), "data", "pypps.db")
)
# Set build_db=True to create the database if it does not exist
with Pypps(
build_jar_dirs=True, jar_path=jar_path, db_path=db_path, build_db=False
) as pypps:
run_groupers(pypps)
run_pricers(pypps)
run_pypps_process(pypps)
if __name__ == "__main__":
main()