-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Matches method asymmetrical: encounter1.Matches(encounter2) does not imply that encounter2.Matches(encounter1) #560
Matches method asymmetrical: encounter1.Matches(encounter2) does not imply that encounter2.Matches(encounter1) #560
Comments
Hi @joelmccarthy, the Matches() implements the logic described for "pattern" in the FHIR spec: "(...) any value in the pattern must be found in the instance. Other additional values may be found too. This is effectively constraint by example. The values of elements present in the pattern must match exactly (case-sensitive, accent-sensitive, etc.)." This means that if a pattern has as value for an element, then an instance matches that pattern only if it also has that value. Conversely, if a pattern has no value for an element, the instance will match the pattern, regardless of the value of that element. Hence, pattern matching - as described by the spec - is by definition not symmetrical! It's kind of "match by example" that some ORMs/query languages support: if you don't mention a condition - it matches all, it you do specify a condition - it needs to be matched. So, yes, if your pattern is null, it matches everything (so |
Hi @ewoutkramer, I appreciate the explanation. This makes sense, I was misunderstanding the intended use case for this method. I agree that Thanks again! |
No, there is not. We should add it and probably rename the method. |
At least the code comments 😉 |
The Matches method is asymmetrical, that is, the following can be true:
encounter1.Matches(encounter2) && !encounter2.Matches(encounter1)
. Here is an example of a passing test that exhibits this behavior:This seems only to happen when one object has one or more values set which are null in the other object. If each object has a value set which is null in the other, Matches is false in both directions:
This behavior is unexpected and difficult to rely on, as it is hard to constantly remember which direction to call the method from in order to ensure consistent behavior.
I believe the following method is the source of the behavior (from
Hl7.Fhir.Model.DeepComparable.Matches(IDeepComparable a, IDeepComparable pattern)
):I would think the first line of the method should instead be:
so that the method returns true for both directions in the above test. This would mean that the Matches call only checks the match for values which are set for both compared objects, and ignores any value which is null in either object.
The text was updated successfully, but these errors were encountered: