Example #1
0
        public Attempt <IValueSet> Create(
            string name,
            IValueSetMeta meta,
            IReadOnlyCollection <ICodeSystemCode> codeSetCodes)
        {
            if (!this.NameIsUnique(name))
            {
                return(Attempt <IValueSet> .Failed(new ArgumentException($"A value set named '{name}' already exists.")));
            }

            if (!this.ValidateValueSetMeta(meta, out var msg))
            {
                return(Attempt <IValueSet> .Failed(new ArgumentException(msg)));
            }

            var setCodes = codeSetCodes as IValueSetCode[] ?? codeSetCodes.ToArray();

            var valueSet = new ValueSet(name, meta, setCodes)
            {
                StatusCode      = ValueSetStatus.Draft,
                IsCustom        = true,
                IsLatestVersion = true
            };

            Created?.Invoke(this, valueSet);
            return(Attempt <IValueSet> .Successful(valueSet));
        }
        internal ValueSet(string name, IValueSetMeta meta, IEnumerable <ICodeSystemCode> codeSetCodes)
        {
            this.Name                  = name;
            this.VersionDate           = meta.VersionDate;
            this.ClientCode            = meta.ClientCode;
            this.DefinitionDescription = meta.DefinitionDescription;
            this.AuthorityDescription  = meta.AuthorityDescription;
            this.SourceDescription     = meta.SourceDescription;
            var codes = codeSetCodes.Select(c => new ValueSetCode(c)).ToList();

            this.ValueSetCodes = codes;
            this.CodeCounts    = codes.GetCodeCountsFromCodes();
        }
Example #3
0
        private static bool ValidateValueSetMeta(IValueSetMeta meta, out string msg)
        {
            var errors = new List <string>
            {
                ValidateProperty("AuthoringSourceDescription", meta.AuthoringSourceDescription),
                ValidateProperty("PurposeDescription", meta.PurposeDescription),
                ValidateProperty("SourceDescription", meta.SourceDescription),
                ValidateProperty("VersionDescription", meta.VersionDescription)
            };

            msg = string.Join(", ", errors.Where(m => !m.IsNullOrWhiteSpace()));

            return(msg.IsNullOrWhiteSpace());
        }
Example #4
0
        private bool ValidateValueSetMeta(IValueSetMeta meta, out string msg)
        {
            var errors = new List <string>
            {
                ValidateProperty(nameof(meta.ClientCode), meta.ClientCode),
                ValidateProperty(nameof(meta.AuthorityDescription), meta.AuthorityDescription),
                ValidateProperty(nameof(meta.DefinitionDescription), meta.DefinitionDescription),
                ValidateProperty(nameof(meta.SourceDescription), meta.SourceDescription)
            };

            msg = string.Join(", ", errors.Where(m => !m.IsNullOrWhiteSpace()));

            return(msg.IsNullOrWhiteSpace());
        }
Example #5
0
        public Attempt <IValueSet> Copy(IValueSet originalValueSet, string newName, IValueSetMeta meta)
        {
            var attempt = this.Create(newName, meta, originalValueSet.ValueSetCodes);

            if (!attempt.Success || attempt.Result == null)
            {
                return(attempt);
            }

            var valueSet = attempt.Result;

            ((ValueSet)valueSet).OriginGuid = originalValueSet.ValueSetGuid;
            this.SaveAsNew(valueSet);

            return(Attempt <IValueSet> .Successful(valueSet));
        }
Example #6
0
        public Attempt <IValueSet> Create(
            string name,
            IValueSetMeta meta,
            IEnumerable <ICodeSetCode> codeSetCodes)
        {
            if (!this.NameIsUnique(name))
            {
                return(Attempt <IValueSet> .Failed(new ArgumentException($"A value set named '{name}' already exists.")));
            }

            if (!ValidateValueSetMeta(meta, out string msg))
            {
                return(Attempt <IValueSet> .Failed(new ArgumentException(msg)));
            }

            var setCodes = codeSetCodes as IValueSetCode[] ?? codeSetCodes.ToArray();

            if (!setCodes.Any())
            {
                return(Attempt <IValueSet> .Failed(new ArgumentException("A value set must include at least one code.")));
            }

            var emptyId = Guid.Empty.ToString();

            var valueSet = new ValueSet(
                emptyId,
                name,
                meta.AuthoringSourceDescription,
                meta.PurposeDescription,
                meta.SourceDescription,
                meta.VersionDescription,
                setCodes.Select(code => code.AsCodeForValueSet(emptyId, name)).ToList().AsReadOnly())
            {
                ValueSetCodesCount = setCodes.Length,
                IsCustom           = true
            };

            Created?.Invoke(this, valueSet);

            return(Attempt <IValueSet> .Successful(valueSet));
        }