FHIR out from the catalog, the FHIR door, ConceptMap routes; round-trip, new-label and Synthea gates
This commit is contained in:
+41
-6
@@ -54,8 +54,18 @@ def test_an_operator_connects_a_site_and_settles_its_review(api, platform, messy
|
||||
}
|
||||
assert len(ok(api.post("/ingest/sources/preview?limit=5", json=notes))) == 5
|
||||
|
||||
# Saving a drawing: broken ones are refused with the reason; good ones get versions.
|
||||
# The site's codes in platform terms: a ConceptMap, saved before the drawing that names
|
||||
# it. One that maps onto a code no field allows is refused, saying which.
|
||||
drawn = json.loads(messy_site.drawn)
|
||||
missing = api.put("/ingest/pipelines/site", json=drawn)
|
||||
assert missing.status_code == 422 and "messy_site" in missing.text
|
||||
codes = json.loads(messy_site.concept_map.read_text())
|
||||
wrong = json.loads(json.dumps(codes).replace('"code": "HSIL"', '"code": "BIRADS-7"'))
|
||||
refused = api.put("/ingest/concept-maps/messy_site", json=wrong)
|
||||
assert refused.status_code == 422 and "BIRADS-7 is not an allowed code" in refused.text
|
||||
assert ok(api.put("/ingest/concept-maps/messy_site", json=codes)) == {"version": 1}
|
||||
|
||||
# Saving a drawing: broken ones are refused with the reason; good ones get versions.
|
||||
broken = {
|
||||
"nodes": [
|
||||
*drawn["nodes"],
|
||||
@@ -88,7 +98,8 @@ def test_an_operator_connects_a_site_and_settles_its_review(api, platform, messy
|
||||
r["_record"]: f"pacientes_his:{r['num']}"
|
||||
for r in ok(api.get("/ingest/pipelines/site/nodes/his_patients/rows?limit=500"))
|
||||
}
|
||||
assert len(ok(api.get("/ingest/pipelines/site/nodes/cytology/rows?limit=500"))) == 53
|
||||
reports = sum(1 for r in truth if r["where"].startswith("ArchivosUni:"))
|
||||
assert len(ok(api.get("/ingest/pipelines/site/nodes/cytology/rows?limit=500"))) == reports
|
||||
|
||||
# Review: reports that contradict each other, rows held because their person is torn
|
||||
# (a record number shared by two patients), and persons that may be one patient.
|
||||
@@ -100,16 +111,21 @@ def test_an_operator_connects_a_site_and_settles_its_review(api, platform, messy
|
||||
|
||||
# The reviewer settles all of it, checking each case against the source documents.
|
||||
patient = messy_site.patients(platform.query)
|
||||
whose = {}
|
||||
whose, before = {}, {}
|
||||
for record, person in platform.query("select _record, person_id from bronze.n__site__persons"):
|
||||
whose.setdefault(person, set()).add(patient[record])
|
||||
before[record] = person
|
||||
# A queued person or candidate is one of its records (decisions are kept by record).
|
||||
whose |= {record: whose[person] for record, person in before.items()}
|
||||
for r in truth:
|
||||
if r.get("flipped"):
|
||||
decision = CYTOLOGY | {"record": record_of[r["where"]], "reason": "flipped HPV"}
|
||||
ok(api.post("/review/rejections", json=decision), status=201)
|
||||
merges = 0
|
||||
for entry in persons["to_settle"]:
|
||||
for c in entry["candidates"]:
|
||||
same = whose[entry["person"]] == whose[c["candidate"]]
|
||||
merges += same
|
||||
decision = {"person": entry["person"], "candidate": c["candidate"], "same": same}
|
||||
ok(api.post("/review/persons", json=decision), status=201)
|
||||
collision = {r["where"]: r for r in truth if r.get("collision")}
|
||||
@@ -121,6 +137,15 @@ def test_an_operator_connects_a_site_and_settles_its_review(api, platform, messy
|
||||
"value": collision[where]["true_record_number"],
|
||||
}
|
||||
ok(api.post("/review/corrections", json=fix), status=201)
|
||||
# A row a rule held because its value is wrong (a scan misread) is rejected after a look
|
||||
# at the document; rows of the torn person wait for the correction above.
|
||||
misread = [
|
||||
h for h in ok(api.get("/review/held", params=CYTOLOGY))
|
||||
if not any("disagree on birth date" in why for why in h["_held"])
|
||||
] # fmt: skip
|
||||
for h in misread:
|
||||
decision = CYTOLOGY | {"record": h["_record"], "reason": "misread in the scan"}
|
||||
ok(api.post("/review/rejections", json=decision), status=201)
|
||||
bad = {"record": "x", "field": "birth_date", "value": "not a date"}
|
||||
assert api.post("/review/corrections", json=bad).status_code == 422
|
||||
|
||||
@@ -136,7 +161,17 @@ def test_an_operator_connects_a_site_and_settles_its_review(api, platform, messy
|
||||
for record, person in platform.query("select _record, person_id from bronze.n__site__persons"):
|
||||
groups.setdefault(person, set()).add(patient[record])
|
||||
assert sorted(map(sorted, groups.values())) == sorted([p] for p in people)
|
||||
|
||||
# Person ids are stable: a person keeps an id her records had, and an id that went
|
||||
# away (merged by the review) resolves to the person that replaced it.
|
||||
after = dict(platform.query("select _record, person_id from bronze.n__site__persons"))
|
||||
gone = set(before.values()) - set(after.values())
|
||||
replaced = dict(platform.query("select person_id, replaced_by from silver.person_link"))
|
||||
assert merges and len(gone) == merges and set(replaced) == gone
|
||||
for old, new in replaced.items():
|
||||
assert new in set(after.values())
|
||||
assert any(before[r] == old and after[r] == new for r in before)
|
||||
assert set(after.values()) <= set(before.values()) # no person got a new id
|
||||
placed = platform.count("silver.cervical_cytology")
|
||||
assert placed == sum(
|
||||
1 for r in truth if r["entity"] == "cervical_cytology" and not r.get("flipped")
|
||||
)
|
||||
reports = sum(1 for r in truth if r["entity"] == "cervical_cytology" and not r.get("flipped"))
|
||||
assert placed == reports - len(misread)
|
||||
|
||||
Reference in New Issue
Block a user