Пример #1
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);
        }
Пример #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);
        }