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;
            }
        }
Exemplo n.º 2
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;
            }
        }