title: Finding a resource in a bundle by reference using FHIR nuget package
body: <p>I'm consuming a FHIR bundle, and trying to resolve references to resources within the bundle, usin the .net FHIR R4 nuget package.  I'm using <a href="https://www.hl7.org/FHIR/bundle.html#references" rel="nofollow noreferrer">this</a> information as a reference. </p>
  
  <p>How to resolve a reference in a Bundle:</p>
  
  <blockquote>
    <ul>
    <li>If the reference is not an absolute reference, convert it to an absolute URL:
    
    <ul>
    <li>if the reference has the format [type]/[id], and</li>
    <li>if the fullUrl for the bundle entry containing the resource is a RESTful one (see the RESTful URL regex)
    
    <ul>
    <li>extract the [root] from the fullUrl, and append the reference (type/id) to it</li>
    <li>then try to resolve within the bundle as for a RESTful URL reference.</li>
    <li>If no resolution is possible, then the reference has no defined meaning within this specification</li>
    </ul></li>
    <li>else no resolution is possible and the reference has no defined meaning within this specification</li>
    </ul></li>
    <li>else
    
    <ul>
    <li>Look for an entry with a fullUrl that matches the URI in the reference</li>
    <li>if no match is found, and the URI is a URL that can be resolved (e.g. if an http: URL), try accessing it directly)</li>
    </ul></li>
    </ul>
    
    <p>Note, in addition, that a reference may be by identifier, and if it
    is, and there is no URL, it may be resolved by scanning the ids in the
    bundle. Note also that transactions may contain conditional references
    that must be resolved by the server before processing the matches.</p>
    
    <p>If the reference is version specific (either relative or absolute),
    then remove the version from the URL before matching fullUrl, and then
    match the version based on Resource.meta.versionId. Note that the
    rules for resolving references in contained resources are the same as
    those for resolving resources in the resource that contains the
    contained resource.</p>
    
    <p>If multiple matches are found, it is ambiguous which is correct.
    Applications MAY return an error or take some other action as they
    deem appropriate.</p>
  </blockquote>
  
  <p>The Bundle.FindEntry extension method appears to only work on absolute references such as this...</p>
  
  <pre><code>&lt;entry&gt;
      &lt;fullUrl value="http://example.org/fhir/Observation/124"/&gt;
      &lt;resource&gt;
          &lt;Observation&gt;
              &lt;id value="124"/&gt;
  
              &lt;subject&gt;
                  &lt;!--    this is reference to the first patient above    --&gt;
                  &lt;reference value="http://example.org/fhir/Patient/23"/&gt;
              &lt;/subject&gt;
          &lt;/Observation&gt;
      &lt;/resource&gt;
  &lt;/entry&gt; 
  </code></pre>
  
  <p>...but it throws an exception if the reference is not absolute such as this:</p>
  
  <pre><code>&lt;entry&gt;
      &lt;fullUrl value="http://example.org/fhir/Observation/123"/&gt;
      &lt;resource&gt;
          &lt;Observation&gt;
              &lt;id value="123"/&gt;
  
              &lt;subject&gt;
                  &lt;!--    this is reference to the first patient above    --&gt;
                  &lt;reference value="Patient/23"/&gt;
              &lt;/subject&gt;
          &lt;/Observation&gt;
      &lt;/resource&gt;
  &lt;/entry&gt;
  </code></pre>
  
  <p>Is there any functionality provided that can resolve relative references?
  Failing something already provided,  How would I write my own?  </p>
  
  <ul>
  <li>How do you convert arelative url to absolute as stated should be done in the spec?</li>
  <li>What would be the logic for extracting the root from the EntryComponent's FullUrl to resolve?  How do I know what the root is?  </li>
  <li>How do I know that a reference is by identifier?  it looks just like a relative reference.</li>
  </ul>