示例#1
0
        /// <summary>Gets group component.</summary>
        /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception>
        /// <param name="field">The field.</param>
        /// <returns>The group component.</returns>
        public static Measure.GroupComponent GetGroupComponent(FormatField field)
        {
            if (field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            Measure.GroupComponent component = null;

            string title       = field.Title ?? field.Name;
            string description = field.Description ?? field.Title ?? field.Name;

            switch (field.Type)
            {
            case FormatField.FieldType.Count:
                component = new Measure.GroupComponent()
                {
                    Code = new CodeableConcept(
                        SanerCommon.CanonicalUrl,
                        field.Name,
                        description),
                    Population = new List <Measure.PopulationComponent>()
                    {
                        new Measure.PopulationComponent()
                        {
                            Code     = FhirTriplet.InitialPopulation.GetConcept(),
                            Criteria = new Expression()
                            {
                                Description = description,
                                Language    = "text/plain",
                                Expression_ = $"Source defined field: {field.Name}",
                            },
                        },
                    },
                };

                break;

            case FormatField.FieldType.Percentage:
                SplitForRatio(
                    description,
                    out string numeratorDescription,
                    out string denominatorDescription);

                component = new Measure.GroupComponent()
                {
                    Code = new CodeableConcept(
                        SanerCommon.CanonicalUrl,
                        field.Name,
                        description),
                    Population = new List <Measure.PopulationComponent>()
                    {
                        new Measure.PopulationComponent()
                        {
                            Code     = FhirTriplet.Numerator.GetConcept(),
                            Criteria = new Expression()
                            {
                                Description = numeratorDescription,
                                Language    = "text/plain",
                                Expression_ = $"Numerator for source defined field: {field.Name}",
                            },
                        },
                        new Measure.PopulationComponent()
                        {
                            Code     = FhirTriplet.Denominator.GetConcept(),
                            Criteria = new Expression()
                            {
                                Description = denominatorDescription,
                                Language    = "text/plain",
                                Expression_ = $"Denominator for source defined field: {field.Name}",
                            },
                        },
                    },
                };

                break;

            case FormatField.FieldType.Date:
            case FormatField.FieldType.Boolean:
            case FormatField.FieldType.Choice:
            case FormatField.FieldType.Text:
            case FormatField.FieldType.ShortString:
                return(null);
            }

            return(component);
        }
示例#2
0
        /// <summary>Group component from flat.</summary>
        /// <param name="grouping">The grouping.</param>
        /// <param name="format">  Describes the format to use.</param>
        /// <returns>A Measure.GroupComponent.</returns>
        private static Measure.GroupComponent GroupComponentFromFlat(
            MeasureGrouping grouping,
            IReportingFormat format)
        {
            FormatField field = format.Fields[grouping.FieldName];

            string title       = string.IsNullOrEmpty(field.Title) ? field.Name : field.Title;
            string description = string.IsNullOrEmpty(field.Description) ? title : field.Description;

            Measure.GroupComponent groupComponent = new Measure.GroupComponent()
            {
                Code = new CodeableConcept(
                    SanerCommon.CanonicalUrl,
                    field.Name,
                    description),
            };

            if ((grouping.GroupAttributes != null) && (grouping.GroupAttributes.Count > 0))
            {
                Extension groupAttributes = new Extension()
                {
                    Url       = "http://hl7.org/fhir/us/saner/StructureDefinition/MeasureGroupAttributes",
                    Extension = new List <Extension>(),
                };

                foreach (MeasureGroupingExtension ext in grouping.GroupAttributes)
                {
                    Extension attribute = new Extension()
                    {
                        Url = ext.Key,
                    };

                    if ((ext.Properties != null) && (ext.Properties.Count > 0))
                    {
                        CodeableConcept value = new CodeableConcept()
                        {
                            Coding = new List <Coding>(),
                        };

                        foreach (FhirTriplet prop in ext.Properties)
                        {
                            value.Coding.Add(prop.GetCoding());
                        }

                        if (!string.IsNullOrEmpty(ext.Text))
                        {
                            value.Text = ext.Text;
                        }

                        attribute.Value = value;
                    }

                    if (!string.IsNullOrEmpty(ext.ValueString))
                    {
                        attribute.Value = new FhirString(ext.ValueString);
                    }

                    groupAttributes.Extension.Add(attribute);
                }

                groupComponent.Extension = new List <Extension>()
                {
                    groupAttributes,
                };
            }

            if ((grouping.PopulationFields != null) && (grouping.PopulationFields.Count > 0))
            {
                groupComponent.Population = new List <Measure.PopulationComponent>();

                foreach (MeasureGroupingPopulation pop in grouping.PopulationFields)
                {
                    if (!format.Fields.ContainsKey(pop.Name))
                    {
                        continue;
                    }

                    FormatField popField = format.Fields[pop.Name];

                    Measure.PopulationComponent populationComponent = new Measure.PopulationComponent()
                    {
                        Code = new FhirTriplet(
                            FhirSystems.SanerPopulation,
                            popField.Name,
                            popField.Title).GetConcept(popField.Description),
                        Description = string.IsNullOrEmpty(field.Description) ? field.Title : field.Description,
                        Criteria    = new Expression()
                        {
                            Name        = pop.Name,
                            Description = popField.Title,
                            Language    = "text/plain",
                            Expression_ = string.IsNullOrEmpty(popField.Description) ? field.Title : popField.Description,
                        },
                    };

                    if (pop.PopulationType != null)
                    {
                        populationComponent.Code.Coding.Add(pop.PopulationType.GetCoding());
                    }

                    groupComponent.Population.Add(populationComponent);
                }
            }
            else if (field.Type == FormatField.FieldType.Boolean)
            {
                string desc = string.IsNullOrEmpty(field.Description) ? field.Title : field.Description;

                groupComponent.Population = new List <Measure.PopulationComponent>();

                Measure.PopulationComponent trueComponent = new Measure.PopulationComponent()
                {
                    Code = new FhirTriplet(
                        FhirSystems.SanerAggregateBool,
                        "true",
                        "Count of 'Yes' or 'True' responses for this field").GetConcept(),
                    Description = $"YES - {desc}",
                    Criteria    = new Expression()
                    {
                        Name        = $"{field.Name}True",
                        Description = field.Title,
                        Language    = "text/plain",
                        Expression_ = "true",
                    },
                };

                Measure.PopulationComponent falseComponent = new Measure.PopulationComponent()
                {
                    Code = new FhirTriplet(
                        FhirSystems.SanerAggregateBool,
                        "false",
                        "Count of 'No' or 'False' responses for this field").GetConcept(),
                    Description = $"NO - {desc}",
                    Criteria    = new Expression()
                    {
                        Name        = $"{field.Name}False",
                        Description = field.Title,
                        Language    = "text/plain",
                        Expression_ = "false",
                    },
                };

                groupComponent.Population.Add(trueComponent);
                groupComponent.Population.Add(falseComponent);
            }
            else if (field.Type == FormatField.FieldType.Choice)
            {
                groupComponent.Population = new List <Measure.PopulationComponent>();

                int choiceNumber = 0;
                foreach (FormatFieldOption populationChoice in field.Options)
                {
                    Measure.PopulationComponent choiceComponent = new Measure.PopulationComponent()
                    {
                        Code = new FhirTriplet(
                            FhirSystems.SanerAggregateChoice,
                            populationChoice.Text,
                            $"Aggregate count of respondents selecting the option: {populationChoice.Text}").GetConcept(),
                        Description = $"{field.Title}:{populationChoice.Text}",
                        Criteria    = new Expression()
                        {
                            Name        = $"{field.Name}Choice{choiceNumber++}",
                            Description = field.Title,
                            Language    = "text/plain",
                            Expression_ = populationChoice.Text,
                        },
                    };

                    groupComponent.Population.Add(choiceComponent);
                }
            }

            return(groupComponent);
        }
示例#3
0
        /// <summary>Group component from nested.</summary>
        /// <param name="grouping">The grouping.</param>
        /// <param name="format">  Describes the format to use.</param>
        /// <returns>A Measure.GroupComponent.</returns>
        private static Measure.GroupComponent GroupComponentFromNested(
            MeasureGrouping grouping,
            IReportingFormat format)
        {
            string description = grouping.CodeText;

            if (string.IsNullOrEmpty(description))
            {
                if (format.Fields.ContainsKey(grouping.FieldName))
                {
                    description = string.IsNullOrEmpty(format.Fields[grouping.FieldName].Description)
                        ? format.Fields[grouping.FieldName].Title
                        : format.Fields[grouping.FieldName].Description;
                }
            }

            Measure.GroupComponent groupComponent = new Measure.GroupComponent()
            {
                Code = grouping.CodeCoding.GetConcept(description),
            };

            if ((grouping.GroupAttributes != null) && (grouping.GroupAttributes.Count > 0))
            {
                Extension groupAttributes = new Extension()
                {
                    Url       = "http://hl7.org/fhir/us/saner/StructureDefinition/MeasureGroupAttributes",
                    Extension = new List <Extension>(),
                };

                foreach (MeasureGroupingExtension ext in grouping.GroupAttributes)
                {
                    Extension attribute = new Extension()
                    {
                        Url = ext.Key,
                    };

                    if ((ext.Properties != null) && (ext.Properties.Count > 0))
                    {
                        CodeableConcept value = new CodeableConcept()
                        {
                            Coding = new List <Coding>(),
                        };

                        foreach (FhirTriplet prop in ext.Properties)
                        {
                            value.Coding.Add(prop.GetCoding());
                        }

                        if (!string.IsNullOrEmpty(ext.Text))
                        {
                            value.Text = ext.Text;
                        }

                        attribute.Value = value;
                    }

                    if (!string.IsNullOrEmpty(ext.ValueString))
                    {
                        attribute.Value = new FhirString(ext.ValueString);
                    }

                    groupAttributes.Extension.Add(attribute);
                }

                groupComponent.Extension = new List <Extension>()
                {
                    groupAttributes,
                };
            }

            if ((grouping.PopulationFields != null) && (grouping.PopulationFields.Count > 0))
            {
                groupComponent.Population = new List <Measure.PopulationComponent>();

                foreach (MeasureGroupingPopulation pop in grouping.PopulationFields)
                {
                    if (!format.Fields.ContainsKey(pop.Name))
                    {
                        continue;
                    }

                    FormatField field = format.Fields[pop.Name];

                    Measure.PopulationComponent populationComponent = new Measure.PopulationComponent()
                    {
                        Code = new FhirTriplet(
                            FhirSystems.SanerPopulation,
                            field.Name,
                            field.Title).GetConcept(field.Description),
                        Description = field.Description ?? field.Title,
                        Criteria    = new Expression()
                        {
                            Name        = pop.Name,
                            Description = field.Title,
                            Language    = "text/plain",
                            Expression_ = field.Description ?? field.Title,
                        },
                    };

                    if (pop.PopulationType != null)
                    {
                        populationComponent.Code.Coding.Add(pop.PopulationType.GetCoding());
                    }

                    groupComponent.Population.Add(populationComponent);
                }
            }

            return(groupComponent);
        }
示例#4
0
        /// <summary>Builds a markdown.</summary>
        /// <param name="format">Describes the format to use.</param>
        /// <returns>A string.</returns>
        private static string BuildMarkdown(IReportingFormat format)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"# {format.Name}");
            sb.AppendLine();
            sb.AppendLine($"{format.Title}");
            sb.AppendLine();
            sb.AppendLine($"{format.Description}");

            if (format.Artifacts != null)
            {
                sb.AppendLine("## Related artifacts");

                foreach (RelatedArtifact artifact in format.Artifacts)
                {
                    sb.AppendLine($"* [{artifact.Display}]({artifact.Url})");
                }

                sb.AppendLine();
                sb.AppendLine();
            }

            if ((format.Definition != null) && (format.Definition.Count > 0))
            {
                sb.AppendLine("## Definitions");

                foreach (string definition in format.Definition)
                {
                    sb.AppendLine($"* {definition}");
                }
            }

            sb.AppendLine("## Group Definitions");
            sb.AppendLine("Group Code|Population Code|System");
            sb.AppendLine("----------|---------------|------");

            List <string> fields = new List <string>();

            foreach (MeasureGrouping grouping in format.MeasureGroupings)
            {
                Measure.GroupComponent component = null;

                if (grouping.CodeCoding != null)
                {
                    component = GroupComponentFromNested(grouping, format);
                }
                else if ((!string.IsNullOrEmpty(grouping.FieldName)) &&
                         format.Fields.ContainsKey(grouping.FieldName))
                {
                    component = GroupComponentFromFlat(grouping, format);
                }

                if (component == null)
                {
                    continue;
                }

                if ((!string.IsNullOrEmpty(grouping.FieldName)) &&
                    format.Fields.ContainsKey(grouping.FieldName))
                {
                    fields.Add(grouping.FieldName);
                }

                sb.AppendLine(
                    $"{component.Code.Coding[0].Code}" +
                    $"|<nobr/>" +
                    $"|{component.Code.Coding[0].System}");

                foreach (Measure.PopulationComponent pop in component.Population)
                {
                    string popSys  = string.Empty;
                    string popCode = string.Empty;

                    foreach (Coding popCoding in pop.Code.Coding)
                    {
                        if (string.IsNullOrEmpty(popSys))
                        {
                            popSys = popCoding.System;
                        }
                        else
                        {
                            popSys += $"<br/>{popCoding.System}";
                        }

                        if (string.IsNullOrEmpty(popCode))
                        {
                            popCode = popCoding.Code;
                        }
                        else
                        {
                            popCode += $"<br/>{popCoding.Code}";
                        }

                        if (format.Fields.ContainsKey(popCoding.Code))
                        {
                            fields.Add(popCoding.Code);
                        }
                    }

                    sb.AppendLine(
                        $"<nobr/>" +
                        $"|{popCode}" +
                        $"|{popSys}");
                }
            }

            sb.AppendLine();
            sb.AppendLine("## Field Definitions");
            sb.AppendLine("Field Name|Title|Description");
            sb.AppendLine("----------|-----|-----------");

            fields.Sort();

            string lastField = string.Empty;

            foreach (string field in fields)
            {
                if (field == lastField)
                {
                    continue;
                }

                lastField = field;

                FormatField formatField = format.Fields[field];

                string title       = formatField.Title;
                string description = string.IsNullOrEmpty(formatField.Description)
                    ? formatField.Title
                    : formatField.Description;

                if ((!string.IsNullOrEmpty(formatField.AdditionalFieldDescription)) &&
                    format.Fields.ContainsKey(formatField.AdditionalFieldDescription))
                {
                    FormatField additional = format.Fields[formatField.AdditionalFieldDescription];

                    title       += $" - {additional.Title}";
                    description += $" - {additional.Description}";
                }

                sb.AppendLine(
                    $"{field}" +
                    $"|{title}" +
                    $"|{description}");
            }

            return(sb.ToString());
        }