Ejemplo n.º 1
0
        /// <summary>Builds a questionnaire.</summary>
        /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception>
        /// <param name="format">Describes the format to use.</param>
        /// <returns>A Questionnaire.</returns>
        private static Questionnaire BuildQuestionnaire(
            IReportingFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            if (string.IsNullOrEmpty(format.Name))
            {
                throw new ArgumentNullException(nameof(format), $"Invalid IReportingFormat.Name: {format.Name}");
            }

            if ((format.Fields == null) || (format.Fields.Count == 0))
            {
                throw new ArgumentNullException(nameof(format), $"Invalid IReportingFormat.Fields: {format.Fields}");
            }

            if ((format.QuestionnaireSections == null) || (format.QuestionnaireSections.Count == 0))
            {
                throw new ArgumentNullException(nameof(format), $"Invalid IReportingFormat.QuestionnaireSections: {format.QuestionnaireSections}");
            }

            Questionnaire questionnaire = new Questionnaire()
            {
                Meta = new Meta()
                {
                    Profile = new string[]
                    {
                        FhirSystems.Questionnaire,
                    },
                },
                Id           = format.Name,
                Name         = format.Name,
                Url          = $"{CanonicalUrl}/Questionnaire/{format.Name}",
                Version      = QuestionnaireVersion,
                Title        = format.Title,
                Description  = new Markdown(format.Description),
                Status       = PublicationStatus.Draft,
                Date         = PublicationDate,
                Publisher    = Publisher,
                Jurisdiction = new List <CodeableConcept>()
                {
                    FhirTriplet.UnitedStates.GetConcept(),
                },
                UseContext = new List <UsageContext>()
                {
                    new UsageContext()
                    {
                        Code  = FhirTriplet.GetCode(FhirSystems.UsageContextType, CommonLiterals.ContextFocus),
                        Value = FhirTriplet.SctCovid.GetConcept(),
                    },
                },
                Item = new List <Questionnaire.ItemComponent>(),
            };

            int sectionNumber = -1;
            int itemNumber    = 0;

            foreach (QuestionnaireSection questionnaireSection in format.QuestionnaireSections)
            {
                sectionNumber++;
                itemNumber = 0;

                Questionnaire.ItemComponent section = new Questionnaire.ItemComponent()
                {
                    LinkId  = $"section_{sectionNumber}",
                    Type    = Questionnaire.QuestionnaireItemType.Group,
                    Item    = new List <Questionnaire.ItemComponent>(),
                    Repeats = false,
                };

#if false   // 2020.05.13 - Argonaut extensions aren't valid in R4 yet
                section.AddExtension(
                    "http://fhir.org/guides/argonaut/questionnaire/StructureDefinition/extension-itemOrder",
                    new FhirDecimal(sectionNumber));
#endif

                if (format.Fields.ContainsKey(questionnaireSection.Title))
                {
                    section.Text = $"{format.Fields[questionnaireSection.Title].Title}: {format.Fields[questionnaireSection.Title].Description}";
                }
                else
                {
                    section.Text = questionnaireSection.Title;
                }

                foreach (QuestionnaireQuestion question in questionnaireSection.Fields)
                {
                    Questionnaire.ItemComponent component = ComponentFromQuestion(
                        format,
                        question,
                        ref itemNumber);

                    if (component == null)
                    {
                        continue;
                    }

                    section.Item.Add(component);
                }

                questionnaire.Item.Add(section);
            }

            return(questionnaire);
        }
Ejemplo n.º 2
0
        /// <summary>Builds a measure.</summary>
        /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception>
        /// <param name="format">Describes the format to use.</param>
        /// <returns>A Measure.</returns>
        private static Measure BuildMeasure(
            IReportingFormat format)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            if (string.IsNullOrEmpty(format.Name))
            {
                throw new ArgumentNullException(nameof(format), $"Invalid IReportingFormat.Name: {format.Name}");
            }

            if ((format.Fields == null) || (format.Fields.Count == 0))
            {
                throw new ArgumentNullException(nameof(format), $"Invalid IReportingFormat.Fields: {format.Fields}");
            }

            if ((format.MeasureGroupings == null) || (format.MeasureGroupings.Count == 0))
            {
                throw new ArgumentNullException(nameof(format), $"Invalid IReportingFormat.MeasureGroupings: {format.MeasureGroupings}");
            }

            Measure measure = new Measure()
            {
                Meta = new Meta()
                {
                    Profile = new string[]
                    {
                        FhirSystems.Measure,
                        "http://hl7.org/fhir/us/saner/StructureDefinition/PublicHealthMeasure",
                    },
                },
                Id           = format.Name,
                Name         = format.Name,
                Url          = $"{CanonicalUrl}/Measure/{format.Name}",
                Version      = MeasureVersion,
                Title        = format.Title,
                Description  = new Markdown(format.Description),
                Status       = PublicationStatus.Draft,
                Experimental = true,
                Subject      = FhirTriplet.ResourceLocation.GetConcept(),
                Date         = PublicationDate,
                Publisher    = Publisher,
                Jurisdiction = new List <CodeableConcept>()
                {
                    FhirTriplet.UnitedStates.GetConcept(),
                },
                UseContext = new List <UsageContext>()
                {
                    new UsageContext()
                    {
                        Code  = FhirTriplet.GetCode(FhirSystems.UsageContextType, CommonLiterals.ContextFocus),
                        Value = FhirTriplet.SctCovid.GetConcept(),
                    },
                },
                Type = new List <CodeableConcept>()
                {
                    FhirTriplet.MeasureTypeComposite.GetConcept(),
                },
                Group   = new List <Measure.GroupComponent>(),
                Contact = SanerCommon.Contacts,
                Author  = format.Authors,
            };

            if ((format.Definition != null) && (format.Definition.Count > 0))
            {
                measure.Definition = new List <Markdown>();
                foreach (string definition in format.Definition)
                {
                    measure.Definition.Add(new Markdown(definition));
                }
            }

            if (format.Artifacts != null)
            {
                measure.RelatedArtifact = new List <RelatedArtifact>();
                measure.RelatedArtifact.AddRange(format.Artifacts);
            }

            foreach (MeasureGrouping grouping in format.MeasureGroupings)
            {
                if (grouping.CodeCoding != null)
                {
                    measure.Group.Add(GroupComponentFromNested(grouping, format));
                    continue;
                }

                if ((!string.IsNullOrEmpty(grouping.FieldName)) &&
                    format.Fields.ContainsKey(grouping.FieldName))
                {
                    measure.Group.Add(GroupComponentFromFlat(grouping, format));
                }
            }

            return(measure);
        }