コード例 #1
0
        /// <summary>
        /// Determine if the concept set contains the specified concept
        /// </summary>
        public bool IsMember(ConceptSet set, Concept concept)
        {
            var persistence = ApplicationContext.Current.GetService <IDataPersistenceService <ConceptSet> >();

            if (persistence == null)
            {
                throw new InvalidOperationException("Cannot locate concept set persistence service");
            }
            return(persistence.Count(o => o.Concepts.Any(c => c.Key == concept.Key)) > 0);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EditConceptSetModel"/> class
 /// with a specific <see cref="ConceptSet"/> instance.
 /// </summary>
 /// <param name="conceptSet">The <see cref="ConceptSet"/> instance.</param>
 public EditConceptSetModel(ConceptSet conceptSet) : this()
 {
     Concepts     = conceptSet.Concepts.Select(c => new ConceptViewModel(c, conceptSet.Key ?? Guid.Empty)).ToList();
     CreationTime = conceptSet.CreationTime.DateTime;
     Id           = conceptSet.Key ?? Guid.Empty;
     Mnemonic     = conceptSet.Mnemonic;
     Name         = conceptSet.Name;
     Oid          = conceptSet.Oid;
     Url          = conceptSet.Url;
 }
コード例 #3
0
        public bool IsMember(ConceptSet set, Concept concept)
        {
            var persistence = ApplicationServiceContext.Current.GetService <IDataPersistenceService <ConceptSet> >();

            if (persistence == null)
            {
                throw new InvalidOperationException($"{nameof(IDataPersistenceService<ConceptSet>)} not found");
            }

            return(persistence.Count(o => o.Key == set.Key && o.ConceptsXml.Any(c => c == concept.Key)) > 0);
        }
コード例 #4
0
        public ConceptSet InsertConceptSet(ConceptSet set)
        {
            var persistenceService = ApplicationContext.Current.GetService <IDataPersistenceService <ConceptSet> >();

            if (persistenceService == null)
            {
                throw new InvalidOperationException($"{nameof(IDataPersistenceService<ConceptSet>)} not found");
            }

            return(persistenceService.Insert(set, AuthenticationContext.Current.Principal, TransactionMode.Commit));
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConceptSetViewModel"/> class.
 /// </summary>
 /// <param name="conceptSet"></param>
 /// <param name="loadConcepts">State that determines if Concepts associated with a Concept Set are loaded</param>
 public ConceptSetViewModel(ConceptSet conceptSet, bool loadConcepts = false) : this()
 {
     if (loadConcepts)
     {
         Concepts = conceptSet.Concepts.Select(c => new ConceptViewModel(c)).ToList();
     }
     CreationTime = conceptSet.CreationTime.DateTime;
     Id           = conceptSet.Key ?? Guid.Empty;
     Mnemonic     = conceptSet.Mnemonic;
     Name         = conceptSet.Name;
     Oid          = conceptSet.Oid;
     Url          = conceptSet.Url;
 }
コード例 #6
0
        public bool IsMember(ConceptSet set, Concept concept)
        {
            var persistence = ApplicationServiceContext.Current.GetService <IDataPersistenceService <ConceptSet> >();

            if (persistence == null)
            {
                throw new InvalidOperationException(this.m_localizationService.FormatString("error.server.core.servicePersistence", new
                {
                    param = nameof(IDataPersistenceService <ConceptSet>)
                }));
            }

            return(persistence.Count(o => o.Key == set.Key && o.ConceptsXml.Any(c => c == concept.Key)) > 0);
        }
コード例 #7
0
        public ActionResult Create(CreateConceptSetModel model)
        {
            try
            {
                var exists = this.ImsiClient.Query <ConceptSet>(c => c.Oid == model.Oid).Item.OfType <ConceptSet>().Any();

                if (exists)
                {
                    ModelState.AddModelError("Oid", Locale.OidMustBeUnique);
                }


                var duplicate = this.ImsiClient.Query <ConceptSet>(c => c.Mnemonic == model.Mnemonic).Item.OfType <ConceptSet>().Any();

                if (duplicate)
                {
                    ModelState.AddModelError("Mnemonic", Locale.MnemonicMustBeUnique);
                }


                if (ModelState.IsValid)
                {
                    var conceptSet = new ConceptSet
                    {
                        Mnemonic = model.Mnemonic,
                        Name     = model.Name,
                        Url      = model.Url,
                        Oid      = model.Oid,
                        Key      = Guid.NewGuid()
                    };

                    var result = this.ImsiClient.Create <ConceptSet>(conceptSet);

                    TempData["success"] = Locale.ConceptSetCreatedSuccessfully;

                    return(RedirectToAction("ViewConceptSet", new { id = result.Key }));
                }
            }
            catch (Exception e)
            {
                Trace.TraceError($"Unable to create concept set: {e}");
            }

            TempData["error"] = Locale.UnableToCreateConceptSet;

            return(View(model));
        }
コード例 #8
0
        /// <summary>
        /// Converts an <see cref="EditConceptSetModel" /> instance to a <see cref="ConceptSet" /> instance.
        /// </summary>
        /// <param name="conceptSet">The concept set.</param>
        /// <returns>Returns the converted concept set.</returns>
        public ConceptSet ToConceptSet(ConceptSet conceptSet)
        {
            conceptSet.Mnemonic = this.Mnemonic;
            conceptSet.Name     = this.Name;
            conceptSet.Oid      = this.Oid;
            conceptSet.Url      = this.Url;

            if (!this.AddConcepts.Any())
            {
                return(conceptSet);
            }

            foreach (var concept in this.AddConcepts)
            {
                Guid id;
                if (Guid.TryParse(concept, out id))
                {
                    conceptSet.ConceptsXml.Add(id);
                }
            }

            return(conceptSet);
        }
コード例 #9
0
        public static void PhinVadsToDataset(String[] args)
        {
            var            options        = new ParameterParser <CvxOptions>().Parse(args);
            DatasetInstall conceptDataset = new DatasetInstall();

            using (var sr = File.OpenText(options.Input))
            {
                // Consume the first line
                sr.ReadLine();
                var components = sr.ReadLine().Split('\t');
                // Next line is the value set information
                // Create  code concept set
                var conceptSet = new ConceptSet()
                {
                    Key          = Guid.NewGuid(),
                    Mnemonic     = options.ConceptSetName ?? components[1],
                    Name         = options.ConceptSetDescription ?? components[0],
                    Oid          = options.ConceptSetOid ?? components[2],
                    CreationTime = DateTime.Parse(String.IsNullOrEmpty(components[6]) ? DateTime.Now.ToString() : components[6]),
                    Url          = !String.IsNullOrEmpty(options.ConceptSetName) ? "http://openiz.org/conceptset/" + options.ConceptSetName :
                                   "http://openiz.org/conceptsets/contrib/" + components[1]
                };

                Dictionary <String, CodeSystem> codeSystems = new Dictionary <string, CodeSystem>();

                // Consume the next set of lines
                while (!sr.ReadLine().StartsWith("Concept Code"))
                {
                    ;
                }

                while (!sr.EndOfStream)
                {
                    components = sr.ReadLine().Split('\t');

                    // Try to get the code system
                    CodeSystem codeSys = null;
                    if (!codeSystems.TryGetValue(components[4], out codeSys))
                    {
                        codeSys = new CodeSystem()
                        {
                            Key          = Guid.NewGuid(),
                            Authority    = components[8],
                            Name         = components[6],
                            Oid          = components[4],
                            Description  = components[5],
                            CreationTime = conceptSet.CreationTime
                        };
                        codeSystems.Add(codeSys.Oid, codeSys);
                        conceptDataset.Action.Add(new DataUpdate()
                        {
                            InsertIfNotExists = true,
                            Element           = codeSys
                        });
                    }

                    // Insert the code
                    var refTerm = new ReferenceTerm()
                    {
                        Key           = Guid.NewGuid(),
                        CodeSystemKey = codeSys.Key,
                        CreationTime  = conceptSet.CreationTime,
                        DisplayNames  = new List <ReferenceTermName>()
                        {
                            new ReferenceTermName()
                            {
                                Name     = components[1],
                                Language = "en"
                            }
                        },
                        Mnemonic = components[0]
                    };
                    var concept = new Concept()
                    {
                        Key              = Guid.NewGuid(),
                        Mnemonic         = components[6] + "-" + components[1].Replace("[", "").Replace("]", "").Replace("-", "").Replace(" ", ""),
                        CreationTime     = conceptSet.CreationTime,
                        StatusConceptKey = StatusKeys.Active,
                        ClassKey         = ConceptClassKeys.Other,
                        ConceptNames     = new List <ConceptName>()
                        {
                            new ConceptName()
                            {
                                Name     = components[1],
                                Language = "en"
                            }
                        },
                        ReferenceTerms = new List <ConceptReferenceTerm>()
                        {
                            new ConceptReferenceTerm()
                            {
                                ReferenceTermKey    = refTerm.Key,
                                RelationshipTypeKey = ConceptRelationshipTypeKeys.SameAs
                            }
                        }
                    };
                    conceptDataset.Action.Add(new DataUpdate()
                    {
                        InsertIfNotExists = true, Element = refTerm
                    });
                    conceptDataset.Action.Add(new DataUpdate()
                    {
                        InsertIfNotExists = true, Element = concept
                    });
                    conceptSet.ConceptsXml.Add(concept.Key.Value);
                }
                conceptDataset.Action.Add(new DataUpdate()
                {
                    InsertIfNotExists = true, Element = conceptSet
                });
            }

            XmlSerializer xsz = new XmlSerializer(typeof(DatasetInstall));

            using (FileStream fs = File.Create(options.Output))
                xsz.Serialize(fs, conceptDataset);
        }
コード例 #10
0
 public ConceptSet SaveConceptSet(ConceptSet set)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
 /// <summary>
 /// Create the specified concept st
 /// </summary>
 public ConceptSet InsertConceptSet(ConceptSet set)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
        /// <summary>
        /// Create a value from an Everest enum
        /// </summary>
        /// TODO: Optimize this
        private ValueSet CreateValueFromEverestEnum(Type enumType)
        {
            StructureAttribute structAtt = enumType.GetCustomAttribute <StructureAttribute>();
            var baseUri = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.BaseUri.ToString();

            ValueSet retVal = new ValueSet();

            retVal.Name       = structAtt.Name;
            retVal.Identifier = structAtt.CodeSystem;
            retVal.Id         = retVal.Identifier;
            // Use the company attribute
            var companyAtt = enumType.Assembly.GetCustomAttribute <AssemblyCompanyAttribute>();

            if (companyAtt != null)
            {
                retVal.Publisher = companyAtt.Company;
            }
            var versionAtt = enumType.Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>();

            if (versionAtt != null)
            {
                retVal.Version = versionAtt.InformationalVersion;
            }
            retVal.VersionId = retVal.Version;

            // Date of the assembly file
            if (!String.IsNullOrEmpty(enumType.Assembly.Location) && File.Exists(enumType.Assembly.Location))
            {
                retVal.Date = new SVC.Messaging.FHIR.DataTypes.DateOnly()
                {
                    DateValue = new FileInfo(enumType.Assembly.Location).LastWriteTime
                }
            }
            ;
            retVal.Timestamp = retVal.Date.DateValue.Value;
            retVal.Status    = new SVC.Messaging.FHIR.DataTypes.PrimitiveCode <string>("published");

            // Compose the codes if it has codes from a known code system
            var  enumFields         = enumType.GetFields();
            bool hasRegisteredCodes = Array.Exists(enumFields, (f) =>
            {
                var enumAtt = f.GetCustomAttribute <EnumerationAttribute>();
                if (enumAtt != null)
                {
                    return(ApplicationContext.ConfigurationService.OidRegistrar.FindData(enumAtt.SupplierDomain) != null);
                }
                else
                {
                    return(false);
                }
            }), hasDifferentSuppliers = Array.Exists(enumFields, (f) => {
                var enumAtt = f.GetCustomAttribute <EnumerationAttribute>();
                if (enumAtt != null)
                {
                    return(Array.Exists(enumFields, (fi) =>
                    {
                        var ienumAtt = fi.GetCustomAttribute <EnumerationAttribute>();
                        if (ienumAtt != null)
                        {
                            return ienumAtt.SupplierDomain != enumAtt.SupplierDomain;
                        }
                        return false;
                    }));
                }
                else
                {
                    return(false);
                }
            });

            // Compose or define
            var sysOid = ApplicationContext.ConfigurationService.OidRegistrar.FindData(retVal.Identifier);

            if (sysOid != null)
            {
                retVal.Compose = new ComposeDefinition();
                retVal.Compose.Import.Add(new SVC.Messaging.FHIR.DataTypes.FhirUri(sysOid.Ref));
            }
            else if (hasRegisteredCodes || hasDifferentSuppliers)
            {
                retVal.Compose = new ComposeDefinition();
                // Group like items
                Array.Sort(enumFields, (a, b) =>
                {
                    EnumerationAttribute aAtt = a.GetCustomAttribute <EnumerationAttribute>(),
                    bAtt = b.GetCustomAttribute <EnumerationAttribute>();
                    if ((aAtt == null) ^ (bAtt == null))
                    {
                        return(aAtt == null ? -1 : 1);
                    }
                    else if (aAtt == bAtt)
                    {
                        return(0);
                    }
                    return(aAtt.SupplierDomain.CompareTo(bAtt.SupplierDomain));
                });
                // Build the concept sets
                ConceptSet currentSet = null;
                foreach (var itm in enumFields)
                {
                    EnumerationAttribute enumValue = itm.GetCustomAttribute <EnumerationAttribute>();
                    if (enumValue == null)
                    {
                        continue;
                    }

                    // Extract code system
                    var oidData    = ApplicationContext.ConfigurationService.OidRegistrar.FindData(enumValue.SupplierDomain);
                    Uri codeSystem = oidData == null ? new Uri(String.Format("urn:oid:{0}", enumValue.SupplierDomain)) : oidData.Ref;

                    // add current set and construct
                    if (currentSet == null || !currentSet.System.Value.Equals(codeSystem))
                    {
                        currentSet = new ConceptSet()
                        {
                            System = codeSystem
                        };
                        retVal.Compose.Include.Add(currentSet);
                    }

                    // Now add mnemonic
                    currentSet.Code.Add(new SVC.Messaging.FHIR.DataTypes.PrimitiveCode <string>(enumValue.Value));
                }
            }
            else
            {
                // Create a definition for a valueset
                retVal.Define        = new ValueSetDefinition();
                retVal.Define.System = new Uri(String.Format("{0}/ValueSet/@v3-{1}", baseUri, structAtt.Name));
                foreach (var itm in enumFields)
                {
                    EnumerationAttribute enumValue = itm.GetCustomAttribute <EnumerationAttribute>();
                    if (enumValue == null)
                    {
                        continue;
                    }
                    DescriptionAttribute description = itm.GetCustomAttribute <DescriptionAttribute>();
                    retVal.Define.Concept.Add(new ConceptDefinition()
                    {
                        Code     = new SVC.Messaging.FHIR.DataTypes.PrimitiveCode <string>(enumValue.Value),
                        Abstract = false,
                        Display  = description == null ? itm.Name : description.Description
                    });
                }
            }

            return(retVal);
        }
    }
コード例 #13
0
 /// <summary>
 /// Checks of the selected concept is already in the concept set list
 /// </summary>
 /// <returns>Returns true if the selected concept exists, false if not found</returns>
 public bool HasSelectedConcept(ConceptSet conceptSet)
 {
     return(AddConcepts.Any() && conceptSet.Concepts.Any(c => c.Key.ToString().Equals(AddConcepts[0])));
 }