(Moved from lhncbc/fhirpath.js, originally by niquola.)
It looks like you are testing whether the name is capitalized to determine whether it is a resource name, which I think is not the right test. Bryn said, "That when resolving an identifier that is also the root of a FHIRPath expression, it is resolved as a type name first, and if it resolves to a type, it must resolve to the type of the context (or a supertype). Otherwise, it is resolved as a path on the context." (From https://chat.fhir.org/#narrow/stream/115-fhirpath/topic/Resource.20names.20in.20FHIRPath).
Also, per that comment, it sounds like MemberInvocation is not the right place to make the check for a resource name, since in "Patient.name.given" it also gets called for "name" and "given" (i.e., non-root nodes).
Discuss topic in fhir chat, design better implementation and make decision
(Moved from lhncbc/fhirpath.js, originally by niquola.)
Discuss topic in fhir chat, design better implementation and make decision