示例#1
0
        /// <summary>
        /// Deserialize JSON into a FHIR MeasureReport#Group
        /// </summary>
        public static void DeserializeJson(this MeasureReport.GroupComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options)
        {
            string propertyName;

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    return;
                }

                if (reader.TokenType == JsonTokenType.PropertyName)
                {
                    propertyName = reader.GetString();
                    if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug)
                    {
                        Console.WriteLine($"MeasureReport.GroupComponent >>> MeasureReport#Group.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"MeasureReport.GroupComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
示例#2
0
        /// <summary>
        /// Serialize a FHIR MeasureReport#Group into JSON
        /// </summary>
        public static void SerializeJson(this MeasureReport.GroupComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: MeasureReport#Group, Export: GroupComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

            if (current.Code != null)
            {
                writer.WritePropertyName("code");
                current.Code.SerializeJson(writer, options);
            }

            if ((current.Population != null) && (current.Population.Count != 0))
            {
                writer.WritePropertyName("population");
                writer.WriteStartArray();
                foreach (MeasureReport.PopulationComponent val in current.Population)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (current.MeasureScore != null)
            {
                writer.WritePropertyName("measureScore");
                current.MeasureScore.SerializeJson(writer, options);
            }

            if ((current.Stratifier != null) && (current.Stratifier.Count != 0))
            {
                writer.WritePropertyName("stratifier");
                writer.WriteStartArray();
                foreach (MeasureReport.StratifierComponent val in current.Stratifier)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
示例#3
0
        /// <summary>Adds a group to report to 'reportGroup'.</summary>
        /// <param name="report">     The report.</param>
        /// <param name="reportGroup">Group the report belongs to.</param>
        private static void AddGroupToReport(
            MeasureReport report,
            MeasureReport.GroupComponent reportGroup)
        {
            if (reportGroup.Population.Count == 0)
            {
                reportGroup.Population = null;
            }

            if (reportGroup.Stratifier.Count == 0)
            {
                reportGroup.Stratifier = null;
            }

            report.Group.Add(reportGroup);
        }
        /// <summary>Generates a measure report.</summary>
        /// <param name="org">           The organization.</param>
        /// <param name="parentLocation">The parent location.</param>
        /// <param name="period">        The period.</param>
        /// <param name="bedsByConfig">  The beds by configuration.</param>
        /// <returns>The measure report.</returns>
        public static MeasureReport GenerateBedMeasureReportV01(
            Organization org,
            Location parentLocation,
            Period period,
            Dictionary <BedConfiguration, List <Location> > bedsByConfig)
        {
            if (org == null)
            {
                throw new ArgumentNullException(nameof(org));
            }

            if (parentLocation == null)
            {
                throw new ArgumentNullException(nameof(parentLocation));
            }

            if (period == null)
            {
                throw new ArgumentNullException(nameof(period));
            }

            if (bedsByConfig == null)
            {
                throw new ArgumentNullException(nameof(bedsByConfig));
            }

            int totalBedCount = 0;
            List <MeasureReport.StratifierGroupComponent> stratums = new List <MeasureReport.StratifierGroupComponent>();

            foreach (BedConfiguration bedConfig in bedsByConfig.Keys)
            {
                if (bedsByConfig[bedConfig].Count == 0)
                {
                    continue;
                }

                totalBedCount += bedsByConfig[bedConfig].Count;

                stratums.Add(new MeasureReport.StratifierGroupComponent()
                {
                    MeasureScore = new Quantity(bedsByConfig[bedConfig].Count, "Number"),
                    Component    = new List <MeasureReport.ComponentComponent>()
                    {
                        new MeasureReport.ComponentComponent()
                        {
                            Code  = FhirTriplet.SanerAvailabilityStatus.GetConcept(),
                            Value = FhirTriplet.AvailabilityStatus(bedConfig.Availability).GetConcept(),
                        },
                        new MeasureReport.ComponentComponent()
                        {
                            Code  = FhirTriplet.SanerOperationalStatus.GetConcept(),
                            Value = FhirTriplet.OperationalStatus(bedConfig.Status).GetConcept(),
                        },
                        new MeasureReport.ComponentComponent()
                        {
                            Code  = FhirTriplet.SanerType.GetConcept(),
                            Value = FhirTriplet.BedType(bedConfig.Type).GetConcept(),
                        },
                        new MeasureReport.ComponentComponent()
                        {
                            Code  = FhirTriplet.SanerFeature.GetConcept(),
                            Value = FhirTriplet.BedFeature(bedConfig.Feature).GetConcept(),
                        },
                        new MeasureReport.ComponentComponent()
                        {
                            Code  = FhirTriplet.SanerLocation.GetConcept(),
                            Value = new CodeableConcept(
                                $"{SystemLiterals.SanerCharacteristic}/partOf",
                                $"{parentLocation.ResourceType}/{parentLocation.Id}"),
                        },
                    },
                });
            }

            MeasureReport.GroupComponent component = new MeasureReport.GroupComponent()
            {
                MeasureScore = new Quantity(totalBedCount, "Number"),
                Stratifier   = new List <MeasureReport.StratifierComponent>()
                {
                    new MeasureReport.StratifierComponent()
                    {
                        Stratum = stratums,
                    },
                },
            };

            return(new MeasureReport()
            {
                Id = NextId,
                Status = MeasureReport.MeasureReportStatus.Complete,
                Type = MeasureReport.MeasureReportType.Summary,
                Date = new FhirDateTime(new DateTimeOffset(DateTime.Now)).ToString(),
                Period = period,
                Measure = SystemLiterals.MeasureReportMeasurement,
                Reporter = new ResourceReference($"{org.ResourceType}/{org.Id}"),
                Group = new List <MeasureReport.GroupComponent>()
                {
                    component
                },
                Text = new Narrative()
                {
                    Div = $"<div xmlns=\"http://www.w3.org/1999/xhtml\">" +
                          $" {org.Name} Bed report for" +
                          $" {period.Start.ToString(CultureInfo.InvariantCulture)}" +
                          $" to" +
                          $" {period.End.ToString(CultureInfo.InvariantCulture)}</div>",
                },
            });
        }
示例#5
0
        /// <summary>Reports for cdc grouped measure.</summary>
        /// <param name="id">     [out] The identifier.</param>
        /// <param name="measure">The measure.</param>
        /// <param name="data">   The data.</param>
        /// <returns>A MeasureReport.</returns>
        private static MeasureReport ReportForMeasure(
            out string id,
            Measure measure,
            ReportData data)
        {
            id = FhirIds.NextId;

            MeasureReport report = new MeasureReport()
            {
                Meta = new Meta()
                {
                    Profile = new string[]
                    {
                        FhirSystems.MeasureReport,
                    },
                    Security = FhirTriplet.SecurityTest.GetCodingList(),
                },
                Id      = id,
                Status  = MeasureReport.MeasureReportStatus.Complete,
                Type    = MeasureReport.MeasureReportType.Summary,
                Date    = new FhirDateTime(new DateTimeOffset(DateTime.Now)).ToString(),
                Period  = data.FhirPeriod(),
                Measure = measure.Url,
                Group   = new List <MeasureReport.GroupComponent>(),
            };

            if (data.ReportDate != null)
            {
                report.Date = new FhirDateTime(new DateTimeOffset((DateTime)data.ReportDate !)).ToString();
            }

            if (data.CoveredLocation != null)
            {
                report.Subject = new ResourceReference(
                    $"Location/{data.CoveredLocation.Id}",
                    data.CoveredLocation.Name);

                if (data.CoveredOrganization != null)
                {
                    report.Subject.AddExtension(
                        "http://build.fhir.org/ig/AudaciousInquiry/saner-ig/connectathon/locations",
                        new FhirString(data.CoveredOrganization.Id));
                }

#if false // 2020.05.05 - figure out if we still want contained
                data.CoveredLocation.ToFhir(
                    out ResourceReference resourceReference,
                    out Resource contained);

                report.Subject = resourceReference;

                if (contained != null)
                {
                    if (report.Contained == null)
                    {
                        report.Contained = new List <Resource>();
                    }

                    report.Contained.Add(contained);
                }
#endif
            }

            if (data.Reporter != null)
            {
                report.Reporter = new ResourceReference(
                    $"Organization/{data.Reporter.Id}",
                    data.Reporter.Name);

#if false // 2020.05.05 - figure out if we still want contained
                data.Reporter.ToFhir(
                    out ResourceReference resourceReference,
                    out Resource contained);

                report.Reporter = resourceReference;

                if (contained != null)
                {
                    if (report.Contained == null)
                    {
                        report.Contained = new List <Resource>();
                    }

                    report.Contained.Add(contained);
                }
#endif
            }

            if ((data.Reporter == null) && (data.CoveredOrganization != null))
            {
                report.Reporter = new ResourceReference(
                    $"Organization/{data.CoveredOrganization.Id}",
                    data.CoveredOrganization.Name);

#if false // 2020.05.05 - figure out if we still want contained
                data.CoveredOrganization.ToFhir(
                    out ResourceReference resourceReference,
                    out Resource contained);

                report.Reporter = resourceReference;

                if (contained != null)
                {
                    if (report.Contained == null)
                    {
                        report.Contained = new List <Resource>();
                    }

                    report.Contained.Add(contained);
                }
#endif
            }

            foreach (Measure.GroupComponent measureGroup in measure.Group)
            {
                if ((measureGroup.Code == null) ||
                    (measureGroup.Code.Coding == null) ||
                    (measureGroup.Code.Coding.Count == 0))
                {
                    continue;
                }

                string groupName = measureGroup.Code.Coding[0].Code;

                MeasureReport.GroupComponent reportGroup = new MeasureReport.GroupComponent()
                {
                    Code       = measureGroup.Code,
                    Population = new List <MeasureReport.PopulationComponent>(),
                    Stratifier = new List <MeasureReport.StratifierComponent>(),
                };

                if (data.Values.ContainsKey(groupName))
                {
                    if (data.Values[groupName].Score != null)
                    {
                        reportGroup.MeasureScore = new Quantity()
                        {
                            Value = data.Values[groupName].Score,
                        };
                    }
                }

                if ((measureGroup.Population == null) || (measureGroup.Population.Count == 0))
                {
                    if (data.Values.ContainsKey(groupName))
                    {
                        reportGroup.MeasureScore = new Quantity()
                        {
                            Value = data.Values[groupName].Score,
                        };
                    }

                    AddGroupToReport(report, reportGroup);

                    continue;
                }

                foreach (Measure.PopulationComponent population in measureGroup.Population)
                {
                    if ((population.Code == null) ||
                        (population.Code.Coding == null) ||
                        (population.Code.Coding.Count == 0))
                    {
                        continue;
                    }

                    string populationSystem = null;
                    string populationName   = null;
                    string populationCode   = null;

                    foreach (Coding popCoding in population.Code.Coding)
                    {
                        if ((popCoding.System == FhirSystems.MeasurePopulation) ||
                            (popCoding.System == FhirSystems.SanerAggregateBool) ||
                            (popCoding.System == FhirSystems.SanerAggregateChoice))
                        {
                            populationSystem = popCoding.System;
                            populationCode   = popCoding.Code;
                        }

                        if (data.Values.ContainsKey(popCoding.Code))
                        {
                            populationName = popCoding.Code;
                        }
                    }

                    if (populationSystem == FhirSystems.SanerAggregateBool)
                    {
                        if (populationCode == "true")
                        {
                            reportGroup.Population.Add(new MeasureReport.PopulationComponent()
                            {
                                Code  = population.Code,
                                Count = (data.Values[groupName].BoolValue == true) ? 1 : 0,
                            });
                        }
                        else
                        {
                            {
                                reportGroup.Population.Add(new MeasureReport.PopulationComponent()
                                {
                                    Code  = population.Code,
                                    Count = (data.Values[groupName].BoolValue == false) ? 1 : 0,
                                });
                            }
                        }

                        continue;
                    }

                    if (!string.IsNullOrEmpty(populationName))
                    {
                        switch (populationCode)
                        {
                        case "initial-population":
                            reportGroup.Population.Add(new MeasureReport.PopulationComponent()
                            {
                                Code  = population.Code,
                                Count = (int)data.Values[populationName].Score,
                            });
                            break;

                        case "measure-population":
                            reportGroup.Population.Add(new MeasureReport.PopulationComponent()
                            {
                                Code  = population.Code,
                                Count = (int)data.Values[populationName].Score,
                            });
                            break;

                        case "measure-observation":
                            // ignore
                            break;

                        case "numerator":
                            reportGroup.Population.Add(new MeasureReport.PopulationComponent()
                            {
                                Code  = population.Code,
                                Count = data.Values[populationName].Numerator ?? (int)data.Values[populationName].Score,
                            });
                            break;

                        case "denominator":
                            reportGroup.Population.Add(new MeasureReport.PopulationComponent()
                            {
                                Code  = population.Code,
                                Count = data.Values[populationName].Denominator ?? (int?)data.Values[populationName].Score ?? 1,
                            });
                            break;

                        default:
                            if (data.Values.ContainsKey(populationName))
                            {
                                reportGroup.Population.Add(new MeasureReport.PopulationComponent()
                                {
                                    Code  = population.Code,
                                    Count = (int)data.Values[populationName].Score,
                                });
                            }
                            else
                            {
                                reportGroup.Population.Add(new MeasureReport.PopulationComponent()
                                {
                                    Code = population.Code,
                                });
                            }

                            break;
                        }
                    }
                }

                AddGroupToReport(report, reportGroup);
            }

            return(report);
        }
示例#6
0
        /// <summary>
        /// Deserialize JSON into a FHIR MeasureReport#Group
        /// </summary>
        public static void DeserializeJsonProperty(this MeasureReport.GroupComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "code":
                current.Code = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Code).DeserializeJson(ref reader, options);
                break;

            case "population":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"GroupComponent error reading 'population' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Population = new List <MeasureReport.PopulationComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.MeasureReport.PopulationComponent v_Population = new Hl7.Fhir.Model.MeasureReport.PopulationComponent();
                    v_Population.DeserializeJson(ref reader, options);
                    current.Population.Add(v_Population);

                    if (!reader.Read())
                    {
                        throw new JsonException($"GroupComponent error reading 'population' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Population.Count == 0)
                {
                    current.Population = null;
                }
                break;

            case "measureScore":
                current.MeasureScore = new Hl7.Fhir.Model.Quantity();
                ((Hl7.Fhir.Model.Quantity)current.MeasureScore).DeserializeJson(ref reader, options);
                break;

            case "stratifier":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"GroupComponent error reading 'stratifier' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Stratifier = new List <MeasureReport.StratifierComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.MeasureReport.StratifierComponent v_Stratifier = new Hl7.Fhir.Model.MeasureReport.StratifierComponent();
                    v_Stratifier.DeserializeJson(ref reader, options);
                    current.Stratifier.Add(v_Stratifier);

                    if (!reader.Read())
                    {
                        throw new JsonException($"GroupComponent error reading 'stratifier' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Stratifier.Count == 0)
                {
                    current.Stratifier = null;
                }
                break;

            // Complex: group, Export: GroupComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }