Not is sometimes Knotty, or perhaps nutty.
As I'm building out queries in my FHIR Server, I recall one of the challenges I had in interpretation of negation in relationship to tests the last time I did this.
Here are a couple of queries, see if you can sort them out the same way I did. For context, assume that you've got some labs, some radiology, and some other stuff, and perhaps the only way you can find the other stuff (e.g., an EKG) is that it isn't actually coded in any way. That's sometimes the case for the other stuff after all.
DiagnosticReport?patient=99999&category:not=LAB,RAD
DiagnosticReport?patient=99999&category:not=LAB&category:not=RAD
If you recall, DiagnosticReport.category is multi-valued as well making it even more interesting.
Before diving in, let's talk about some queries and some data. Perhaps you have some tests that are EKG results (neither labs, nor radiology).
Now, let's look at it the other way first:
DiagnosticReport?patient=99999&category=LAB,RAD
Returns any report where DiagnosticReport.category is coded using LAB, OR is coded using RAD, or is coded both ways.
Since category is a list (effectively a set of codes), the interpretation here is DiagnosticReport.category intersect (LAB, RAD) is non-null. Another way to say this is |DiagnosticReport.category intersect (LAB, RAD)| > 0 (where |set| is the cardinality or size operator).
DiagnosticReport?patient=99999&category=LAB&category=RAD
Returns any report where DiagnosticReport.category is coded both as LAB, and as RAD.
And the interpretation here is DiagnosticReport.category intersect (LAB) is non null AND DiagnosticReport.category intersect (RAD) is non null. We could also say DiagnosticReport.category is a superset of (LAB) AND DiagnosticReport.category is a superset of (RAD). Which allows us to join this second one as DiagnosticReport.category is a superset of (RAD, LAB) or yet another way: |DiagnosticReport.category intersect (LAB, RAD)| = 2.
Now, throw :not at the problem, and it becomes knotty indeed.
DiagnosticReport?patient=99999&category:not=LAB,RAD
The way I want to read this is that DiagnosticReport.category contains neither LAB, nor RAD (or DiagnosticReport.category intersect (LAB, RAD) is null OR |DiagnosticReport.category intersect (LAB, RAD)| = 0.
But what then is this?
DiagnosticReport?patient=99999&category:not=LAB&category:not=RAD
Well, follow the logic (bomb). DiagnosticReport.category is NOT a superset of (RAD, LAB), or yet another way |DiagnosticReport.category intersect (LAB, RAD)| != 2. These are the reports that aren't both.
Did that all make sense to you? Because I'm still scratching my head.
Oh but wait, there's more: If DiagnosticReport.category is missing, does this work? Actually, yes, because it would be returned for both queries using :not, which would be correct.
But that probably isn't how you thought you'd write those queries in FHIR, is it? Yeah, me either. Or is is it me neither? Either way, I think I've got it right now (and written too).
Isn't this just DeMorgan's law?
ReplyDelete