fix(pfs): close descriptor test fixtures; deterministic hcpcs_level_2 row (refs #685)
This commit is contained in:
@@ -108,7 +108,7 @@ def descriptor_runs(
|
||||
|
||||
def hcpcs_long_description(con: Any, code: str) -> str:
|
||||
row = con.execute(
|
||||
"SELECT long_description FROM terminology.hcpcs_level_2 WHERE hcpcs = ? LIMIT 1",
|
||||
"SELECT long_description FROM terminology.hcpcs_level_2 WHERE hcpcs = ? ORDER BY CAST(seqnum AS INTEGER) DESC, recid DESC LIMIT 1",
|
||||
[code.upper()],
|
||||
).fetchone()
|
||||
return (row[0] or "") if row else ""
|
||||
|
||||
@@ -32,6 +32,9 @@ class _Store:
|
||||
def _con(self):
|
||||
return self.con
|
||||
|
||||
def close(self):
|
||||
self.con.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store():
|
||||
@@ -82,7 +85,8 @@ def store():
|
||||
"INSERT INTO fr_anchors VALUES (?,?,?,?,?)",
|
||||
[(k, p, pg, p, t) for k, p, pg, t in rows],
|
||||
)
|
||||
return s
|
||||
yield s
|
||||
s.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -95,6 +99,9 @@ def con():
|
||||
c.execute(
|
||||
"INSERT INTO terminology.hcpcs_level_2 VALUES ('G0556','10','3','Advanced primary care management services … per calendar month','Adv prim care mgmt lvl 1')"
|
||||
)
|
||||
c.execute(
|
||||
"INSERT INTO terminology.hcpcs_level_2 VALUES ('G0556','5','1','Lower seqnum description for G0556','Short desc')"
|
||||
)
|
||||
c.execute(
|
||||
"CREATE TABLE pfs.rvu (hcpcs VARCHAR, mod VARCHAR, description VARCHAR, status_code VARCHAR, year INTEGER)"
|
||||
)
|
||||
@@ -106,7 +113,8 @@ def con():
|
||||
("99490", "", "Chrnc care mgmt staff 1st 20", "A", 2022),
|
||||
],
|
||||
)
|
||||
return c
|
||||
yield c
|
||||
c.close()
|
||||
|
||||
|
||||
class TestRuleYear:
|
||||
@@ -152,6 +160,13 @@ class TestDuckDBSources:
|
||||
assert hcpcs_long_description(con, "G0556").startswith("Advanced primary care")
|
||||
assert hcpcs_long_description(con, "99490") == ""
|
||||
|
||||
def test_long_description_deterministic_seqnum(self, con):
|
||||
# With multiple rows for same hcpcs, ORDER BY seqnum DESC picks the highest
|
||||
result = hcpcs_long_description(con, "G0556")
|
||||
assert (
|
||||
result == "Advanced primary care management services … per calendar month"
|
||||
)
|
||||
|
||||
def test_rvu_descriptions_base_rows_only(self, con):
|
||||
assert rvu_descriptions(con, "99490") == [
|
||||
(2015, "A", "Chron care mgmt srvc 20 min"),
|
||||
|
||||
Reference in New Issue
Block a user