Beispiel #1
0
        public HttpResponseMessage UpdateValueSet(
            [FromBody] FhirValueSet fhirValueSet,
            [FromUri] int valueSetId,
            [FromUri(Name = "_format")] string format = null)
        {
            ValueSetExporter exporter         = new ValueSetExporter(this.tdb);
            ValueSet         originalValueSet = this.tdb.ValueSets.Single(y => y.Id == valueSetId);
            ValueSet         newValueSet      = exporter.Convert(fhirValueSet, valueSet: originalValueSet);

            if (originalValueSet == null)
            {
                this.tdb.ValueSets.AddObject(newValueSet);
            }

            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR2/ValueSet/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            fhirValueSet.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            FhirValueSet updatedFhirValueSet = exporter.Convert(newValueSet);

            return(Shared.GetResponseMessage(this.Request, format, updatedFhirValueSet, originalValueSet != null ? 200 : 201, headers));
        }
Beispiel #2
0
        public HttpResponseMessage GetValueSet(
            [FromUri] int valueSetId,
            [FromUri(Name = "_format")] string format        = null,
            [FromUri(Name = "_summary")] SummaryType?summary = null)
        {
            ValueSet         valueSet     = this.tdb.ValueSets.Single(y => y.Id == valueSetId);
            ValueSetExporter exporter     = new ValueSetExporter(this.tdb);
            FhirValueSet     fhirValueSet = exporter.Convert(valueSet, summary);

            return(Shared.GetResponseMessage(this.Request, format, fhirValueSet));
        }
Beispiel #3
0
        public HttpResponseMessage CreateValueSet(
            [FromBody] FhirValueSet fhirValueSet,
            [FromUri(Name = "_format")] string format = null)
        {
            if (fhirValueSet.Identifier != null && this.tdb.ValueSets.Count(y => y.Oid == fhirValueSet.Identifier.Value) > 0)
            {
                throw new Exception("ValueSet already exists with this identifier. Use a PUT instead");
            }

            ValueSetExporter exporter = new ValueSetExporter(this.tdb);
            ValueSet         valueSet = exporter.Convert(fhirValueSet);

            if (valueSet.Oid == null)
            {
                valueSet.Oid = string.Empty;
            }

            if (this.tdb.ValueSets.Count(y => y.Oid == valueSet.Oid) > 0)
            {
                throw new Exception("A ValueSet with that identifier already exists");
            }

            this.tdb.ValueSets.AddObject(valueSet);
            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR2/ValueSet/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            fhirValueSet.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            FhirValueSet createdFhirValueSet = exporter.Convert(valueSet);

            return(Shared.GetResponseMessage(this.Request, format, createdFhirValueSet, statusCode: 201, headers: headers));
        }
        public HttpResponseMessage CreateValueSet(
            [FromBody] FhirValueSet fhirValueSet,
            [FromUri(Name = "_format")] string format = null)
        {
            if (fhirValueSet.Identifier != null)
            {
                ValueSet foundValueSet = (from vs in tdb.ValueSets
                                          join vsi in tdb.ValueSetIdentifiers on vs.Id equals vsi.ValueSetId
                                          where vsi.Identifier.ToLower().Trim() == fhirValueSet.Identifier.Value.ToLower().Trim()
                                          select vs)
                                         .Distinct()
                                         .FirstOrDefault();

                if (foundValueSet != null)
                {
                    throw new Exception("ValueSet already exists with this identifier. Use a PUT instead");
                }
            }

            ValueSetExporter exporter = new ValueSetExporter(this.tdb);
            ValueSet         valueSet = exporter.Convert(fhirValueSet);

            this.tdb.ValueSets.Add(valueSet);
            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR2/ValueSet/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            fhirValueSet.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            FhirValueSet createdFhirValueSet = exporter.Convert(valueSet);

            return(Shared.GetResponseMessage(this.Request, format, createdFhirValueSet, statusCode: 201, headers: headers));
        }
Beispiel #5
0
        public FhirValueSet Convert(ValueSet valueSet, SummaryType?summaryType = null)
        {
            var implementationGuides = (from tc in valueSet.Constraints
                                        join t in this.tdb.Templates on tc.TemplateId equals t.Id
                                        select t.OwningImplementationGuide);
            bool usedByPublishedIgs = implementationGuides.Count(y => y.PublishStatus != null && y.PublishStatus.Status == PublishStatus.PUBLISHED_STATUS) > 0;

            FhirValueSet fhirValueSet = new FhirValueSet()
            {
                Id          = valueSet.Id.ToString(),
                Name        = valueSet.Name,
                Status      = usedByPublishedIgs ? ConformanceResourceStatus.Active : ConformanceResourceStatus.Draft,
                Description = valueSet.Description,
                Url         = valueSet.GetIdentifier(ValueSetIdentifierTypes.HTTP)
            };

            if (summaryType == null || summaryType == SummaryType.Data)
            {
                var activeMembers = valueSet.GetActiveMembers(DateTime.Now);

                if (activeMembers.Count > 0)
                {
                    // Compose
                    var compose = new FhirValueSet.ValueSetComposeComponent();
                    fhirValueSet.Compose = compose;

                    foreach (var groupedMember in activeMembers.GroupBy(y => y.CodeSystem, y => y))
                    {
                        var include = new FhirValueSet.ConceptSetComponent();
                        compose.Include.Add(include);

                        include.System = groupedMember.Key.Oid;

                        foreach (var member in groupedMember)
                        {
                            include.Concept.Add(new FhirValueSet.ConceptReferenceComponent()
                            {
                                Code    = member.Code,
                                Display = member.DisplayName
                            });
                        }
                    }

                    // Expansion
                    var expansion = new FhirValueSet.ValueSetExpansionComponent();
                    expansion.Identifier   = string.Format("urn:uuid:{0}", Guid.NewGuid());
                    expansion.Timestamp    = FhirDateTime.Now().ToString();
                    fhirValueSet.Expansion = expansion;

                    foreach (ValueSetMember vsMember in activeMembers)
                    {
                        var fhirMember = new FhirValueSet.ValueSetExpansionContainsComponent()
                        {
                            System  = DSTU2Helper.FormatIdentifier(vsMember.CodeSystem.Oid),
                            Code    = vsMember.Code,
                            Display = vsMember.DisplayName
                        };

                        expansion.Contains.Add(fhirMember);
                    }
                }
            }

            return(fhirValueSet);
        }
Beispiel #6
0
        public ValueSet Convert(FhirValueSet fhirValueSet, ValueSet valueSet = null)
        {
            if (valueSet == null)
            {
                valueSet = new ValueSet();
            }

            if (valueSet.Name != fhirValueSet.Name)
            {
                valueSet.Name = fhirValueSet.Name;
            }

            if (valueSet.Description != fhirValueSet.Description)
            {
                valueSet.Description = fhirValueSet.Description;
            }

            if (fhirValueSet.Identifier == null)
            {
                throw new Exception("ValueSet.identifier.value is required");
            }

            this.PopulateIdentifier(valueSet, fhirValueSet.Identifier.Value);

            if (fhirValueSet.Expansion != null)
            {
                foreach (var expContains in fhirValueSet.Expansion.Contains)
                {
                    // Skip members that don't have a code or a code system
                    if (string.IsNullOrEmpty(expContains.Code) || string.IsNullOrEmpty(expContains.System))
                    {
                        continue;
                    }

                    CodeSystem codeSystem = this.tdb.CodeSystems.SingleOrDefault(y => y.Oid == expContains.System);

                    if (codeSystem == null)
                    {
                        codeSystem = new CodeSystem()
                        {
                            Oid  = expContains.System,
                            Name = expContains.System
                        };
                        this.tdb.CodeSystems.Add(codeSystem);
                    }

                    ValueSetMember newMember = valueSet.Members.SingleOrDefault(y => y.CodeSystem == codeSystem && y.Code == expContains.Code);

                    if (newMember == null)
                    {
                        newMember = new ValueSetMember()
                        {
                            CodeSystem = codeSystem,
                            Code       = expContains.Code
                        }
                    }
                    ;

                    if (newMember.DisplayName != expContains.Display)
                    {
                        newMember.DisplayName = expContains.Display;
                    }

                    DateTime versionDateVal = DateTime.MinValue;
                    if (!DateTime.TryParse(fhirValueSet.Version, out versionDateVal))
                    {
                        DateTime.TryParse(fhirValueSet.Date, out versionDateVal);
                    }
                    DateTime?versionDate = versionDateVal != DateTime.MinValue ? (DateTime?)versionDateVal : null;

                    if (newMember.StatusDate != versionDate)
                    {
                        newMember.StatusDate = versionDate;
                    }

                    if (newMember.StatusDate != null && newMember.Status != "active")
                    {
                        newMember.Status = "active";
                    }

                    valueSet.Members.Add(newMember);
                }
            }

            return(valueSet);
        }
    }