Example #1
0
        internal static T ToThingBase <T>(this DomainResource fhirResource) where T : ThingBase, new()
        {
            T baseThing = new T();

            Guid id;

            if (Guid.TryParse(fhirResource.Id, out id))
            {
                baseThing.Key = new ThingKey(id);
            }

            Guid version;

            if (fhirResource.Meta != null && fhirResource.Meta.VersionId != null && Guid.TryParse(fhirResource.Meta.VersionId, out version))
            {
                baseThing.Key.VersionStamp = version;
            }

            ThingFlags flags;
            var        extensionFlag = fhirResource.GetExtension(HealthVaultExtensions.FlagsFhirExtensionName);

            if (extensionFlag != null)
            {
                if (extensionFlag.Value is FhirString && Enum.TryParse <ThingFlags>((extensionFlag.Value as FhirString).ToString(), out flags))
                {
                    baseThing.Flags = flags;
                }
            }

            return(baseThing);
        }
Example #2
0
        ResourceMap.Node CreateMapNode(DomainResource r)
        {
            String structureName = r.TypeName;
            String resourceUrl;
            String baseName = null;
            String title;

            switch (r)
            {
            case ValueSet vs:
                resourceUrl = vs.Url;
                title       = vs.Title;
                break;

            case StructureDefinition sd:
                resourceUrl = sd.Url;
                baseName    = sd.BaseDefinition.LastUriPart();
                title       = sd.Title;
                break;

            default:
                return(null);
            }

            string mapName = r.GetStringExtension(Global.ResourceMapNameUrl);

            if (String.IsNullOrEmpty(mapName) == true)
            {
                throw new Exception($"Mapname missing from {resourceUrl}");
            }
            String[] mapNameArray = mapName.Split('/');

            Extension isFragmentExtension = r.GetExtension(Global.IsFragmentExtensionUrl);

            ResourceMap.Node retVal = this.CreateMapNode(resourceUrl,
                                                         title,
                                                         mapNameArray,
                                                         structureName,
                                                         isFragmentExtension != null);

            foreach (Extension link in r.GetExtensions(Global.ResourceMapLinkUrl))
            {
                FhirString s = (FhirString)link.Value;

                dynamic mapLink = JObject.Parse(s.Value);
                mapLink.LinkSource = resourceUrl;
                this.links.Add(mapLink);
                retVal.AddLink(mapLink);
            }

            return(retVal);
        }