コード例 #1
0
        private List <VocabularyCode> GetCodes(TDBValueSet valueSet, DateTime?bindingDate)
        {
            List <ValueSetMember> members         = valueSet.GetActiveMembers(bindingDate);
            List <VocabularyCode> vocabularyCodes = new List <VocabularyCode>();

            foreach (var vc in members)
            {
                VocabularyCode vocabularyCode = new VocabularyCode()
                {
                    Value          = vc.Code,
                    DisplayName    = vc.DisplayName,
                    CodeSystem     = vc.CodeSystem.Oid,
                    CodeSystemName = vc.CodeSystem.Name
                };

                if (this.isCDA && vocabularyCode.CodeSystem.StartsWith("urn:oid:"))
                {
                    vocabularyCode.CodeSystem = vocabularyCode.CodeSystem.Substring(8);
                }

                vocabularyCodes.Add(vocabularyCode);
            }

            return(vocabularyCodes);
        }
コード例 #2
0
        private void PopulateIdentifier(ValueSet valueSet, FhirValueSet fhirValueSet)
        {
            var existingIdentifiers = valueSet.Identifiers.Where(y => y.Type == ValueSetIdentifierTypes.HTTP).ToList();

            // Remove HTTP identifiers that are not found in the FHIR ValueSet's identifiers
            for (var i = existingIdentifiers.Count - 1; i >= 0; i--)
            {
                var existingIdentifier = existingIdentifiers[i];

                if (!fhirValueSet.Identifier.Any(y => y.Value.ToLower().Trim() == existingIdentifier.Identifier.ToLower().Trim()))
                {
                    this.tdb.ValueSetIdentifiers.Remove(existingIdentifier);
                }
            }

            // Add identifiers from the FHIR ValueSet's identifiers that don't already exist
            foreach (var fhirIdentifer in fhirValueSet.Identifier)
            {
                if (!existingIdentifiers.Any(y => y.Identifier.ToLower().Trim() == fhirIdentifer.Value.ToLower().Trim()))
                {
                    valueSet.Identifiers.Add(new ValueSetIdentifier()
                    {
                        Type       = ValueSetIdentifierTypes.HTTP,
                        Identifier = fhirIdentifer.Value
                    });
                }
            }
        }
コード例 #3
0
        public HttpResponseMessage CreateValueSet(
            [FromBody] FhirValueSet fhirValueSet,
            [FromUri(Name = "_format")] string format = null)
        {
            var foundValueSets = (from vs in this.tdb.ValueSets
                                  join vsi in this.tdb.ValueSetIdentifiers on vs.Id equals vsi.ValueSetId
                                  join fvsi in fhirValueSet.Identifier on vsi.Identifier.ToLower().Trim() equals fvsi.Value.ToLower().Trim()
                                  select vs)
                                 .Distinct();

            if (foundValueSets.Count() > 0)
            {
                throw new Exception("ValueSet already exists with this identifier. Use a PUT instead");
            }

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

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

            string location = string.Format("{0}://{1}/api/FHIR3/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));
        }
コード例 #4
0
        public HttpResponseMessage UpdateValueSet(
            [FromBody] FhirValueSet fhirValueSet,
            [FromUri] int valueSetId,
            [FromUri(Name = "_format")] string format = null)
        {
            ValueSetExporter exporter         = new ValueSetExporter(this.tdb);
            ValueSetImporter importer         = new ValueSetImporter(this.tdb);
            ValueSet         originalValueSet = this.tdb.ValueSets.Single(y => y.Id == valueSetId);
            ValueSet         newValueSet      = importer.Convert(fhirValueSet, valueSet: originalValueSet);

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

            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR3/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));
        }
コード例 #5
0
        public HttpResponseMessage GetValueSetExpansion(
            [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));
        }
コード例 #6
0
        private T CreateImportValueSet(Trifolia.DB.ValueSet currentValueSet, VadsClient.ValueSet vadsValueSet)
        {
            T importValueSet = Activator.CreateInstance <T>();

            importValueSet.Oid          = vadsValueSet.oid;
            importValueSet.Code         = vadsValueSet.code;
            importValueSet.Description  = vadsValueSet.definitionText;
            importValueSet.Name         = vadsValueSet.name;
            importValueSet.ImportSource = "PHIN VADS";
            importValueSet.ImportStatus = DetermineValueSetStatus(importValueSet, currentValueSet);

            return(importValueSet);
        }
コード例 #7
0
        private T CreateImportValueSet(Trifolia.DB.ValueSet currentValueSet, VadsClient.ValueSet vadsValueSet, string importSourceId)
        {
            T importValueSet = Activator.CreateInstance <T>();

            importValueSet.Oid            = string.Format("urn:oid:{0}", vadsValueSet.oid);
            importValueSet.Code           = vadsValueSet.code;
            importValueSet.Description    = vadsValueSet.definitionText;
            importValueSet.Name           = vadsValueSet.name;
            importValueSet.ImportSource   = "PHIN VADS";
            importValueSet.ImportSourceId = importSourceId;
            importValueSet.ImportStatus   = DetermineValueSetStatus(importValueSet, currentValueSet);
            importValueSet.SourceUrl      = "https://phinvads.cdc.gov/vads/ViewValueSet.action?oid=" + vadsValueSet.oid;

            return(importValueSet);
        }
コード例 #8
0
        private V CreateImportValueSetMember(Trifolia.DB.ValueSet currentValueSet, VadsClient.ValueSetConcept vadsConcept)
        {
            ValueSetMember currentMember = currentValueSet != null?
                                           currentValueSet.Members.SingleOrDefault(y => y.Code == vadsConcept.conceptCode && y.CodeSystem.Oid == vadsConcept.codeSystemOid) :
                                               null;

            V importValueSetMember = Activator.CreateInstance <V>();

            importValueSetMember.Code          = vadsConcept.conceptCode;
            importValueSetMember.CodeSystemOid = vadsConcept.codeSystemOid;
            importValueSetMember.DisplayName   = vadsConcept.codeSystemConceptName;
            importValueSetMember.Status        = ConvertStatus(vadsConcept.status);
            importValueSetMember.StatusDate    = vadsConcept.statusDate;
            importValueSetMember.ImportStatus  = DetermineValueSetMemberStatus(importValueSetMember, currentMember);

            return(importValueSetMember);
        }
コード例 #9
0
        public HttpResponseMessage CreateValueSet(
            [FromBody] FhirValueSet fhirValueSet,
            [FromUri(Name = "_format")] string format = null)
        {
            var fhirIdentifier      = fhirValueSet.Identifier.Count > 0 ? fhirValueSet.Identifier.First() : null;
            var fhirIdentifierValue = fhirIdentifier != null ? fhirIdentifier.Value : null;

            if (fhirValueSet.Identifier != null && this.tdb.ValueSets.Count(y => y.Oid == fhirIdentifierValue) > 0)
            {
                throw new Exception("ValueSet already exists with this identifier. Use a PUT instead");
            }

            ValueSetImporter importer = new ValueSetImporter(this.tdb);
            ValueSetExporter exporter = new ValueSetExporter(this.tdb);
            ValueSet         valueSet = importer.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/FHIR3/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));
        }
コード例 #10
0
        public int GetValueSetMemberLength(string valueSetOid)
        {
            try
            {
                int count = 0;

                if (tdb.ValueSets.Any(y => y.Oid == valueSetOid))
                {
                    TDBValueSet valueSet = tdb.ValueSets.SingleOrDefault(y => y.Oid == valueSetOid);
                    count = valueSet.Members.Count();
                }

                return(count);
            }
            catch (Exception ex)
            {
                Log.For(this).Critical("Error occurred while retrieving valueset member length for valueset oid '" + valueSetOid + "'.", ex);
                throw;
            }
        }
コード例 #11
0
        private VocabularySystem GetSystem(IObjectRepository tdb, TDBValueSet valueSet, DateTime?bindingDate)
        {
            if (valueSet == null)
            {
                throw new Exception("Could not find ValueSet specified.");
            }

            VocabularySystems schema         = new VocabularySystems();
            VocabularySystem  schemaValueSet = new VocabularySystem()
            {
                ValueSetOid  = valueSet.Oid,
                ValueSetName = valueSet.Name
            };

            if (isCDA && schemaValueSet.ValueSetOid.StartsWith("urn:oid:"))
            {
                schemaValueSet.ValueSetOid = schemaValueSet.ValueSetOid.Substring(8);
            }

            schemaValueSet.Codes = GetCodes(valueSet, bindingDate).ToArray();

            return(schemaValueSet);
        }
コード例 #12
0
        public string GetValueSet(string valueSetOid, int vocabOutputType, string encoding)
        {
            try
            {
                TDBValueSet valueSet = tdb.ValueSets.SingleOrDefault(y => y.Oid == valueSetOid);

                if (valueSet == null)
                {
                    throw new Exception("Could not find ValueSet specified.");
                }

                VocabularySystems schema = new VocabularySystems();
                schema.Systems = new VocabularySystem[] { GetSystem(tdb, valueSet, DateTime.Now) };
                VocabularyOutputTypeAdapter adapter = new VocabularyOutputTypeAdapter(schema, VocabularyOutputTypeTranslator.FromInt(vocabOutputType), Encoding.GetEncoding(encoding));

                return(adapter.AsXML());
            }
            catch (Exception ex)
            {
                Log.For(this).Critical("Error occurred while retrieving a valueset for oid '" + valueSetOid + "'", ex);
                throw;
            }
        }
コード例 #13
0
        private void PopulateIdentifier(ValueSet valueSet, string fhirIdentifier)
        {
            ValueSetIdentifier vsIdentifier = valueSet.Identifiers.FirstOrDefault(y => y.Type == ValueSetIdentifierTypes.HTTP);

            if (vsIdentifier == null)
            {
                vsIdentifier = new ValueSetIdentifier()
                {
                    Type       = ValueSetIdentifierTypes.HTTP,
                    Identifier = fhirIdentifier
                };

                valueSet.Identifiers.Add(vsIdentifier);
            }
            else
            {
                vsIdentifier.Identifier = fhirIdentifier;
            }

            if (!valueSet.Identifiers.Any(y => y.IsDefault))
            {
                vsIdentifier.IsDefault = true;
            }
        }
コード例 #14
0
        protected override T BaseFindValueSet(IObjectRepository tdb, string oid)
        {
            hessiancsharp.client.CHessianProxyFactory factory = new hessiancsharp.client.CHessianProxyFactory();
            VocabService      vocabService    = (VocabService)factory.Create(typeof(VocabService), AppSettings.PhinVadsServiceUrl);
            ValueSetResultDto valueSetResults = null;

            try
            {
                valueSetResults = vocabService.getValueSetByOid(oid);

                if (!string.IsNullOrEmpty(valueSetResults.errorText))
                {
                    throw new ExternalSourceConnectionException();
                }

                if (valueSetResults == null || valueSetResults.totalResults != 1)
                {
                    return(null);
                }

                VadsClient.ValueSet  valueSetResult  = valueSetResults.valueSet[0];
                Trifolia.DB.ValueSet currentValueSet = tdb.ValueSets.SingleOrDefault(y => y.Oid == oid);

                T importValueSet = CreateImportValueSet(currentValueSet, valueSetResult);

                ValueSetVersionResultDto versionResults = vocabService.getValueSetVersionsByValueSetOid(oid);
                DateTime        latestVersionDate       = versionResults.valueSetVersions.Max(y => y.effectiveDate);
                ValueSetVersion latestVersion           = versionResults.valueSetVersions.Single(y => y.effectiveDate == latestVersionDate);

                int cPage = 1;
                ValueSetConceptResultDto    valueSetConceptResults = vocabService.getValueSetConceptsByValueSetVersionId(latestVersion.id, cPage, MEMBER_PAGE_SIZE);
                Dictionary <string, string> codeSystemNames        = new Dictionary <string, string>();

                while (valueSetConceptResults != null && valueSetConceptResults.valueSetConcepts != null && valueSetConceptResults.valueSetConcepts.Count > 0)
                {
                    foreach (ValueSetConcept cValueSetConceptResult in valueSetConceptResults.valueSetConcepts)
                    {
                        V importValueSetMember = CreateImportValueSetMember(currentValueSet, cValueSetConceptResult);
                        importValueSet.Members.Add(importValueSetMember);

                        // Determine the code system name
                        if (codeSystemNames.ContainsKey(importValueSetMember.CodeSystemOid))
                        {
                            importValueSetMember.CodeSystemName = codeSystemNames[importValueSetMember.CodeSystemOid];
                        }
                        else
                        {
                            CodeSystemResultDto codeSystemResults = vocabService.getCodeSystemByOid(importValueSetMember.CodeSystemOid);
                            string codeSystemName = codeSystemResults.codeSystems[0].name;

                            importValueSetMember.CodeSystemName = codeSystemName;
                            codeSystemNames.Add(importValueSetMember.CodeSystemOid, codeSystemName);
                        }
                    }

                    valueSetConceptResults = vocabService.getValueSetConceptsByValueSetVersionId(latestVersion.id, ++cPage, MEMBER_PAGE_SIZE);
                }

                return(importValueSet);
            }
            catch (hessiancsharp.io.CHessianException che)
            {
                if (che.Message.Contains("404"))
                {
                    return(null);
                }

                throw;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Unable to connect to the remote server"))
                {
                    throw new ExternalSourceConnectionException();
                }

                throw;
            }
        }
コード例 #15
0
        public ValueSet Convert(FhirValueSet fhirValueSet, ValueSet valueSet = null)
        {
            string fhirDescription = fhirValueSet.Description != null ? fhirValueSet.Description.Value : null;

            if (valueSet == null)
            {
                valueSet = new ValueSet();
            }

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

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

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

            this.PopulateIdentifier(valueSet, fhirValueSet);

            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);
        }
    }
コード例 #16
0
        /// <summary>
        /// Converts a Trifolia ValueSet model to a FHIR ValueSet model.
        /// </summary>
        /// <param name="valueSet">The Trifolia ValueSet model to convert to a FHIR model</param>
        /// <param name="summaryType">Does not populate certain fields when a summaryType is specified.</param>
        /// <param name="publishedValueSets">Optional list of ValueSets that are used by a published implementation guide. If not specified, queries the database for implementation guides that this value set may be published under.</param>
        /// <returns>A FHIR ValueSet model</returns>
        public FhirValueSet Convert(ValueSet valueSet, SummaryType?summaryType = null, IEnumerable <ValueSet> publishedValueSets = null, string baseUrl = null)
        {
            bool usedByPublishedIgs = false;

            if (publishedValueSets == null)
            {
                var implementationGuides = (from tc in valueSet.Constraints
                                            join t in this.tdb.Templates on tc.TemplateId equals t.Id
                                            select t.OwningImplementationGuide);
                usedByPublishedIgs = implementationGuides.Count(y => y.PublishStatus != null && y.PublishStatus.IsPublished) > 0;
            }
            else
            {
                usedByPublishedIgs = publishedValueSets.Contains(valueSet);
            }

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

            // Handle urn:oid: and urn:hl7ii: identifiers differently if a base url is provided
            // baseUrl is most likely provided when within the context of an implementation guide
            if (fhirValueSet.Url != null)
            {
                if (fhirValueSet.Url.StartsWith("urn:oid:") && !string.IsNullOrEmpty(baseUrl))
                {
                    fhirValueSet.Url = baseUrl.TrimEnd('/') + "/ValueSet/" + fhirValueSet.Url.Substring(8);
                }
                else if (fhirValueSet.Url.StartsWith("urn:hl7ii:") && !string.IsNullOrEmpty(baseUrl))
                {
                    fhirValueSet.Url = baseUrl.TrimEnd('/') + "/ValueSet/" + fhirValueSet.Url.Substring(10);
                }
            }

            List <ValueSetMember> activeMembers = valueSet.GetActiveMembers(DateTime.Now);

            if (activeMembers.Count > 0)
            {
                // If the value set was created in Trifolia, then Trifolia contains the definition
                // and it should be represented by <compose>
                if (valueSet.ImportSource == null)
                {
                    // Compose
                    var compose = new FhirValueSet.ComposeComponent();
                    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
                            });
                        }
                    }
                }
                else
                {
                    // If the value set was imported, then we have the expansion,
                    // but we don't have the defintion (the <compose>).
                    var expansion = new FhirValueSet.ExpansionComponent();
                    fhirValueSet.Expansion = expansion;
                    expansion.Identifier   = fhirValueSet.Url;
                    expansion.Total        = activeMembers.Count;

                    if (valueSet.LastUpdate != null)
                    {
                        expansion.TimestampElement = new FhirDateTime(valueSet.LastUpdate.Value);
                    }
                    else
                    {
                        expansion.TimestampElement = new FhirDateTime(DateTime.Now);
                    }

                    expansion.Contains = (from m in activeMembers
                                          select new FhirValueSet.ContainsComponent()
                    {
                        System = m.CodeSystem.Oid,
                        Code = m.Code,
                        Display = m.DisplayName
                    }).ToList();
                }
            }

            return(fhirValueSet);
        }
コード例 #17
0
ファイル: ValueSetExporter.cs プロジェクト: BOBO41/trifolia
        /// <summary>
        /// Converts a Trifolia ValueSet model to a FHIR ValueSet model.
        /// </summary>
        /// <param name="valueSet">The Trifolia ValueSet model to convert to a FHIR model</param>
        /// <param name="summaryType">Does not populate certain fields when a summaryType is specified.</param>
        /// <param name="publishedValueSets">Optional list of ValueSets that are used by a published implementation guide. If not specified, queries the database for implementation guides that this value set may be published under.</param>
        /// <returns>A FHIR ValueSet model</returns>
        public FhirValueSet Convert(ValueSet valueSet, SummaryType?summaryType = null, IEnumerable <ValueSet> publishedValueSets = null)
        {
            bool usedByPublishedIgs = false;

            if (publishedValueSets == null)
            {
                var implementationGuides = (from tc in valueSet.Constraints
                                            join t in this.tdb.Templates on tc.TemplateId equals t.Id
                                            select t.OwningImplementationGuide);
                usedByPublishedIgs = implementationGuides.Count(y => y.PublishStatus != null && y.PublishStatus.IsPublished) > 0;
            }
            else
            {
                usedByPublishedIgs = publishedValueSets.Contains(valueSet);
            }

            FhirValueSet fhirValueSet = new FhirValueSet()
            {
                Id          = valueSet.GetFhirId(),
                Name        = valueSet.Name,
                Status      = usedByPublishedIgs ? ConformanceResourceStatus.Active : ConformanceResourceStatus.Draft,
                Description = new Markdown(valueSet.Description),
                Url         = valueSet.Oid
            };

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

                if (activeMembers.Count > 0)
                {
                    // Compose
                    var compose = new FhirValueSet.ComposeComponent();
                    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.ExpansionComponent();
                    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.ContainsComponent()
                        {
                            System  = STU3Helper.FormatIdentifier(vsMember.CodeSystem.Oid),
                            Code    = vsMember.Code,
                            Display = vsMember.DisplayName
                        };

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

            return(fhirValueSet);
        }
コード例 #18
0
        protected override T BaseFindValueSet(IObjectRepository tdb, string oid)
        {
            if (string.IsNullOrEmpty(oid))
            {
                throw new ArgumentNullException("oid");
            }

            oid = oid.Trim();       // Remove trailing spaces

            Logging.Log.For(this).Trace("Creating client to connect to PHIN VADS at URL " + AppSettings.PhinVadsServiceUrl);

            hessiancsharp.client.CHessianProxyFactory factory = new hessiancsharp.client.CHessianProxyFactory();
            VocabService      vocabService    = (VocabService)factory.Create(typeof(VocabService), AppSettings.PhinVadsServiceUrl);
            ValueSetResultDto valueSetResults = null;

            try
            {
                Logging.Log.For(this).Trace("Retrieving value set from PHIN VADS");

                valueSetResults = vocabService.getValueSetByOid(oid);

                if (!string.IsNullOrEmpty(valueSetResults.errorText))
                {
                    throw new ExternalSourceConnectionException();
                }

                if (valueSetResults == null || valueSetResults.totalResults != 1)
                {
                    Logging.Log.For(this).Trace("No value set found when searching PHIN VADS for identifier " + oid);
                    return(null);
                }

                Logging.Log.For(this).Trace("Successfully retrieved one value set from PHIN VADS");

                string searchOid = oid;

                if (!searchOid.StartsWith("urn:oid:"))
                {
                    searchOid = "urn:oid:" + searchOid;
                }

                VadsClient.ValueSet  valueSetResult  = valueSetResults.valueSet[0];
                Trifolia.DB.ValueSet currentValueSet = (from vs in tdb.ValueSets
                                                        join vsi in tdb.ValueSetIdentifiers on vs.Id equals vsi.ValueSetId
                                                        where vsi.Identifier.ToLower().Trim() == searchOid.ToLower().Trim()
                                                        select vs)
                                                       .Distinct()
                                                       .FirstOrDefault();

                T importValueSet = CreateImportValueSet(currentValueSet, valueSetResult, valueSetResult.oid);

                ValueSetVersionResultDto versionResults = vocabService.getValueSetVersionsByValueSetOid(oid);
                DateTime        latestVersionDate       = versionResults.valueSetVersions.Max(y => y.effectiveDate);
                ValueSetVersion latestVersion           = versionResults.valueSetVersions
                                                          .OrderByDescending(y => y.statusDate)
                                                          .First(y => y.effectiveDate == latestVersionDate);

                int cPage = 1;
                ValueSetConceptResultDto    valueSetConceptResults = vocabService.getValueSetConceptsByValueSetVersionId(latestVersion.id, cPage, MEMBER_PAGE_SIZE);
                Dictionary <string, string> codeSystemNames        = new Dictionary <string, string>();

                while (valueSetConceptResults != null && valueSetConceptResults.valueSetConcepts != null && valueSetConceptResults.valueSetConcepts.Count > 0)
                {
                    foreach (ValueSetConcept cValueSetConceptResult in valueSetConceptResults.valueSetConcepts)
                    {
                        V importValueSetMember = CreateImportValueSetMember(currentValueSet, cValueSetConceptResult);
                        importValueSet.Members.Add(importValueSetMember);

                        // Determine the code system name
                        if (codeSystemNames.ContainsKey(importValueSetMember.CodeSystemOid))
                        {
                            importValueSetMember.CodeSystemName = codeSystemNames[importValueSetMember.CodeSystemOid];
                        }
                        else
                        {
                            string vadsCodeSystemOid = importValueSetMember.CodeSystemOid;

                            if (vadsCodeSystemOid.StartsWith("urn:oid:"))
                            {
                                vadsCodeSystemOid = vadsCodeSystemOid.Substring(8);
                            }

                            CodeSystemResultDto codeSystemResults = vocabService.getCodeSystemByOid(vadsCodeSystemOid);
                            string codeSystemName = codeSystemResults.codeSystems[0].name;

                            importValueSetMember.CodeSystemName = codeSystemName;
                            codeSystemNames.Add(importValueSetMember.CodeSystemOid, codeSystemName);
                        }
                    }

                    valueSetConceptResults = vocabService.getValueSetConceptsByValueSetVersionId(latestVersion.id, ++cPage, MEMBER_PAGE_SIZE);
                }

                return(importValueSet);
            }
            catch (hessiancsharp.io.CHessianException che)
            {
                Logging.Log.For(this).Critical("Hessian error communicating with PHIN VADS", che);

                if (che.Message.Contains("404"))
                {
                    return(null);
                }

                throw;
            }
            catch (Exception ex)
            {
                Logging.Log.For(this).Critical("General error finding value set in PHIN VADS", ex);

                if (ex.Message.Contains("Unable to connect to the remote server"))
                {
                    throw new ExternalSourceConnectionException();
                }

                throw;
            }
        }