Example #1
0
        /// <summary>
        /// Returns the id for the specified resource type from the provided reference.  If the reference doesn't match the provided type null will be returned.
        /// </summary>
        /// <typeparam name="TResource">Expected resource type the reference represents.</typeparam>
        /// <param name="reference">Resource  reference to extract the id from.</param>
        /// <returns>The id for the specified resource type if it exists, null otherwise.</returns>
        public static string GetId <TResource>(this Hl7.Fhir.Model.ResourceReference reference)
        {
            var referenceType = $"{typeof(TResource).Name}/";

            return(reference?.Reference == null || !reference.Reference.StartsWith(referenceType, StringComparison.InvariantCultureIgnoreCase)
                ? null : reference.Reference.Substring(referenceType.Length));
        }
Example #2
0
        /// <summary>
        /// Returns the id for the specified resource type from the provided reference.  If the reference doesn't match the provided type null will be returned.
        /// </summary>
        /// <typeparam name="TResource">Expected resource type the reference represents.</typeparam>
        /// <param name="reference">Resource  reference to extract the id from.</param>
        /// <returns>The id for the specified resource type if it exists, null otherwise.</returns>
        public static string GetId <TResource>(this Hl7.Fhir.Model.ResourceReference reference)
        {
            string id;
            var    referenceType = $"{typeof(TResource).Name}/";

            if (reference?.Reference == null || !reference.Reference.StartsWith(referenceType, StringComparison.InvariantCultureIgnoreCase))
            {
                return(null);
            }

            // Reference should be in the form: ResourceType/Identifier
            var relativeReferenceIdentifier = reference.Reference.Substring(referenceType.Length);
            var matches = _idMatcherRegex.Match(relativeReferenceIdentifier);

            if (!matches.Success)
            {
                return(null);
            }
            else
            {
                id = matches?.Groups?[0].Value;
                return(id);
            }
        }
Example #3
0
 /// <summary>
 /// Conditionally add search parameter for the specified value to the parameter collection.
 /// </summary>
 /// <param name="searchParams">The search parameter collection to modify.</param>
 /// <param name="searchParam">Search parameter to add.</param>
 /// <param name="resourceRefValue">The resource reference add to the collection. If value is null no search parameter will be added.</param>
 /// <param name="searchPrefix">Optional prefix for value matching.</param>
 /// <returns>The modified search parameter collection.</returns>
 public static Hl7.Fhir.Rest.SearchParams WhenParamValue(this Hl7.Fhir.Rest.SearchParams searchParams, SearchParam searchParam, Hl7.Fhir.Model.ResourceReference resourceRefValue, SearchPrefix searchPrefix = null)
 {
     return(searchParams.WhenParamValue(searchParam?.ToString(), resourceRefValue, searchPrefix));
 }