/// <summary>
        /// Parse Extension
        /// </summary>
        public static Hl7.Fhir.Model.Extension ParseExtension(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Extension existingInstance = null)
        {
            Hl7.Fhir.Model.Extension result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Extension();
            string currentElementName       = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element url
                else if (atName == "url")
                {
                    result.UrlElement = FhirUriParser.ParseFhirUri(reader, errors);
                }

                // Parse element isModifier
                else if (atName == "isModifier")
                {
                    result.IsModifierElement = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                }

                // Parse element value
                else if (atName.StartsWith("value"))
                {
                    result.Value = FhirParser.ParseElement(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
        /// <summary>
        /// Parse PrescriptionMedicineInactiveIngredientComponent
        /// </summary>
        public static Prescription.PrescriptionMedicineInactiveIngredientComponent ParsePrescriptionMedicineInactiveIngredientComponent(IFhirReader reader, ErrorList errors, Prescription.PrescriptionMedicineInactiveIngredientComponent existingInstance = null)
        {
            Prescription.PrescriptionMedicineInactiveIngredientComponent result = existingInstance != null ? existingInstance : new Prescription.PrescriptionMedicineInactiveIngredientComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "extension"))
                    {
                        result.Extension = new List <Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element internalId
                    else if (reader.IsAtRefIdElement())
                    {
                        result.InternalId = Id.Parse(reader.ReadRefIdContents());
                    }

                    // Parse element identification
                    else if (ParserUtils.IsAtFhirElement(reader, "identification"))
                    {
                        result.Identification = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element quantity
                    else if (ParserUtils.IsAtFhirElement(reader, "quantity", true))
                    {
                        result.Quantity = FhirParser.ParseElement(reader, errors);
                    }

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }
        /// <summary>
        /// Parse ProtocolStepPreconditionConditionComponent
        /// </summary>
        public static Hl7.Fhir.Model.Protocol.ProtocolStepPreconditionConditionComponent ParseProtocolStepPreconditionConditionComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Protocol.ProtocolStepPreconditionConditionComponent existingInstance = null)
        {
            Hl7.Fhir.Model.Protocol.ProtocolStepPreconditionConditionComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Protocol.ProtocolStepPreconditionConditionComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "extension"))
                    {
                        result.Extension = new List <Hl7.Fhir.Model.Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element _id
                    else if (ParserUtils.IsAtFhirElement(reader, "_id"))
                    {
                        result.LocalId = Id.Parse(reader.ReadPrimitiveContents("id"));
                    }

                    // Parse element type
                    else if (ParserUtils.IsAtFhirElement(reader, "type"))
                    {
                        result.Type = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element value
                    else if (ParserUtils.IsAtFhirElement(reader, "value", true))
                    {
                        result.Value = FhirParser.ParseElement(reader, errors);
                    }

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }
Example #4
0
        /// <summary>
        /// Parse ObservationReferenceRangeComponent
        /// </summary>
        public static Hl7.Fhir.Model.Observation.ObservationReferenceRangeComponent ParseObservationReferenceRangeComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Observation.ObservationReferenceRangeComponent existingInstance = null)
        {
            Hl7.Fhir.Model.Observation.ObservationReferenceRangeComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Observation.ObservationReferenceRangeComponent();
            string currentElementName = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element meaning
                else if (atName == "meaning")
                {
                    result.Meaning = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element range
                else if (atName.StartsWith("range"))
                {
                    result.Range = FhirParser.ParseElement(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
        private static Resource getContents(JToken token, ErrorList errors)
        {
            //TODO: This is quite inefficient. The Json parser has just parsed this
            //entry's Resource from json, now we are going to serialize it to as string
            //just to read from it again using a JsonTextReader. But that is what my
            //parser takes as input, so no choice for now...

            //Maybe: JsonTextReader r = token.CreateReader(); is a way out?

            string         contents = token.ToString();
            JsonTextReader r        = new JsonTextReader(new StringReader(contents));

            return(FhirParser.ParseResource(new JsonFhirReader(r), errors));
        }
        public static Resource ParseContainedResource(IFhirReader reader, ErrorList errors)
        {
            Resource result = null;

            // Read into "contained" element
            reader.EnterElement();

            result = FhirParser.ParseResource(reader, errors);

            // Exit from "contained" element
            reader.LeaveElement();

            return(result);
        }
        private static Resource getContents(XElement content, ErrorList errors)
        {
            string contentType = Util.StringValueOrNull(content.Attribute(XATOM_CONTENT_TYPE));

            if (contentType != "text/xml")
            {
                errors.Add("Entry should have contents of type 'text/xml'");
                return(null);
            }

            //TODO: This is quite inefficient. The Xml parser has just parsed this
            //entry's Resource from text, now we are going to serialize it to as string
            //just to read from it again using a Xml parser. But that is what my
            //parser takes as input, so no choice for now...
            return(FhirParser.ParseResourceFromXml(content.FirstNode.ToString(), errors));
        }
        /// <summary>
        /// Parse Condition
        /// </summary>
        public static Hl7.Fhir.Model.Condition ParseCondition(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Condition existingInstance = null)
        {
            Hl7.Fhir.Model.Condition result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Condition();
            string currentElementName       = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element language
                else if (atName == "language")
                {
                    result.LanguageElement = CodeParser.ParseCode(reader, errors);
                }

                // Parse element text
                else if (atName == "text")
                {
                    result.Text = NarrativeParser.ParseNarrative(reader, errors);
                }

                // Parse element contained
                else if (atName == "contained")
                {
                    result.Contained = new List <Hl7.Fhir.Model.Resource>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contained"))
                    {
                        result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element subject
                else if (atName == "subject")
                {
                    result.Subject = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element encounter
                else if (atName == "encounter")
                {
                    result.Encounter = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element asserter
                else if (atName == "asserter")
                {
                    result.Asserter = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element dateAsserted
                else if (atName == "dateAsserted")
                {
                    result.DateAssertedElement = DateParser.ParseDate(reader, errors);
                }

                // Parse element code
                else if (atName == "code")
                {
                    result.Code = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element category
                else if (atName == "category")
                {
                    result.Category = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element status
                else if (atName == "status")
                {
                    result.StatusElement = CodeParser.ParseCode <Hl7.Fhir.Model.Condition.ConditionStatus>(reader, errors);
                }

                // Parse element certainty
                else if (atName == "certainty")
                {
                    result.Certainty = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element severity
                else if (atName == "severity")
                {
                    result.Severity = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element onset
                else if (atName.StartsWith("onset"))
                {
                    result.Onset = FhirParser.ParseElement(reader, errors);
                }

                // Parse element abatement
                else if (atName.StartsWith("abatement"))
                {
                    result.Abatement = FhirParser.ParseElement(reader, errors);
                }

                // Parse element stage
                else if (atName == "stage")
                {
                    result.Stage = ConditionParser.ParseConditionStageComponent(reader, errors);
                }

                // Parse element evidence
                else if (atName == "evidence")
                {
                    result.Evidence = new List <Hl7.Fhir.Model.Condition.ConditionEvidenceComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "evidence"))
                    {
                        result.Evidence.Add(ConditionParser.ParseConditionEvidenceComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element location
                else if (atName == "location")
                {
                    result.Location = new List <Hl7.Fhir.Model.Condition.ConditionLocationComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "location"))
                    {
                        result.Location.Add(ConditionParser.ParseConditionLocationComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element relatedItem
                else if (atName == "relatedItem")
                {
                    result.RelatedItem = new List <Hl7.Fhir.Model.Condition.ConditionRelatedItemComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "relatedItem"))
                    {
                        result.RelatedItem.Add(ConditionParser.ParseConditionRelatedItemComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element notes
                else if (atName == "notes")
                {
                    result.NotesElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
        /// <summary>
        /// Parse PrescriptionAdministrationRequestDosageInstructionComponent
        /// </summary>
        public static Prescription.PrescriptionAdministrationRequestDosageInstructionComponent ParsePrescriptionAdministrationRequestDosageInstructionComponent(IFhirReader reader, ErrorList errors, Prescription.PrescriptionAdministrationRequestDosageInstructionComponent existingInstance = null)
        {
            Prescription.PrescriptionAdministrationRequestDosageInstructionComponent result = existingInstance != null ? existingInstance : new Prescription.PrescriptionAdministrationRequestDosageInstructionComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "extension"))
                    {
                        result.Extension = new List <Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element internalId
                    else if (reader.IsAtRefIdElement())
                    {
                        result.InternalId = Id.Parse(reader.ReadRefIdContents());
                    }

                    // Parse element precondition
                    else if (ParserUtils.IsAtFhirElement(reader, "precondition"))
                    {
                        result.Precondition = new List <CodeableConcept>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "precondition"))
                        {
                            result.Precondition.Add(CodeableConceptParser.ParseCodeableConcept(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element prn
                    else if (ParserUtils.IsAtFhirElement(reader, "prn"))
                    {
                        result.Prn = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                    }

                    // Parse element additionalInstruction
                    else if (ParserUtils.IsAtFhirElement(reader, "additionalInstruction"))
                    {
                        result.AdditionalInstruction = new List <CodeableConcept>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "additionalInstruction"))
                        {
                            result.AdditionalInstruction.Add(CodeableConceptParser.ParseCodeableConcept(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element route
                    else if (ParserUtils.IsAtFhirElement(reader, "route"))
                    {
                        result.Route = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element dose
                    else if (ParserUtils.IsAtFhirElement(reader, "dose", true))
                    {
                        result.Dose = FhirParser.ParseElement(reader, errors);
                    }

                    // Parse element rate
                    else if (ParserUtils.IsAtFhirElement(reader, "rate"))
                    {
                        result.Rate = QuantityParser.ParseQuantity(reader, errors);
                    }

                    // Parse element schedule
                    else if (ParserUtils.IsAtFhirElement(reader, "schedule"))
                    {
                        result.Schedule = new List <Schedule>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "schedule"))
                        {
                            result.Schedule.Add(ScheduleParser.ParseSchedule(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }
Example #10
0
        /// <summary>
        /// Parse Visit
        /// </summary>
        public static Hl7.Fhir.Model.Visit ParseVisit(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Visit existingInstance = null)
        {
            Hl7.Fhir.Model.Visit result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Visit();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    var atName = reader.CurrentElementName;
                    // Parse element extension
                    if (atName == "extension")
                    {
                        result.Extension = new List <Hl7.Fhir.Model.Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element language
                    else if (atName == "language")
                    {
                        result.Language = CodeParser.ParseCode(reader, errors);
                    }

                    // Parse element text
                    else if (atName == "text")
                    {
                        result.Text = NarrativeParser.ParseNarrative(reader, errors);
                    }

                    // Parse element contained
                    else if (atName == "contained")
                    {
                        result.Contained = new List <Hl7.Fhir.Model.Resource>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "contained"))
                        {
                            result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element _id
                    else if (atName == "_id")
                    {
                        result.LocalId = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                    }

                    // Parse element identifier
                    else if (atName == "identifier")
                    {
                        result.Identifier = new List <Hl7.Fhir.Model.Identifier>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "identifier"))
                        {
                            result.Identifier.Add(IdentifierParser.ParseIdentifier(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element status
                    else if (atName == "status")
                    {
                        result.Status = CodeParser.ParseCode <Hl7.Fhir.Model.Visit.EncounterState>(reader, errors);
                    }

                    // Parse element class
                    else if (atName == "class")
                    {
                        result.Class = CodeParser.ParseCode <Hl7.Fhir.Model.Visit.EncounterClass>(reader, errors);
                    }

                    // Parse element type
                    else if (atName == "type")
                    {
                        result.Type = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element subject
                    else if (atName == "subject")
                    {
                        result.Subject = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element participant
                    else if (atName == "participant")
                    {
                        result.Participant = new List <Hl7.Fhir.Model.Visit.VisitParticipantComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "participant"))
                        {
                            result.Participant.Add(VisitParser.ParseVisitParticipantComponent(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element fulfills
                    else if (atName == "fulfills")
                    {
                        result.Fulfills = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element length
                    else if (atName == "length")
                    {
                        result.Length = DurationParser.ParseDuration(reader, errors);
                    }

                    // Parse element reason
                    else if (atName.StartsWith("reason"))
                    {
                        result.Reason = FhirParser.ParseElement(reader, errors);
                    }

                    // Parse element indication
                    else if (atName == "indication")
                    {
                        result.Indication = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element priority
                    else if (atName == "priority")
                    {
                        result.Priority = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element hospitalization
                    else if (atName == "hospitalization")
                    {
                        result.Hospitalization = VisitParser.ParseVisitHospitalizationComponent(reader, errors);
                    }

                    // Parse element location
                    else if (atName == "location")
                    {
                        result.Location = new List <Hl7.Fhir.Model.Visit.VisitLocationComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "location"))
                        {
                            result.Location.Add(VisitParser.ParseVisitLocationComponent(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element serviceProvider
                    else if (atName == "serviceProvider")
                    {
                        result.ServiceProvider = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }
        /// <summary>
        /// Parse FamilyHistoryRelationComponent
        /// </summary>
        public static Hl7.Fhir.Model.FamilyHistory.FamilyHistoryRelationComponent ParseFamilyHistoryRelationComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.FamilyHistory.FamilyHistoryRelationComponent existingInstance = null)
        {
            Hl7.Fhir.Model.FamilyHistory.FamilyHistoryRelationComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.FamilyHistory.FamilyHistoryRelationComponent();
            string currentElementName = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element name
                else if (atName == "name")
                {
                    result.NameElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element relationship
                else if (atName == "relationship")
                {
                    result.Relationship = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element deceased
                else if (atName.StartsWith("deceased"))
                {
                    result.Deceased = FhirParser.ParseElement(reader, errors);
                }

                // Parse element note
                else if (atName == "note")
                {
                    result.NoteElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element condition
                else if (atName == "condition")
                {
                    result.Condition = new List <Hl7.Fhir.Model.FamilyHistory.FamilyHistoryRelationConditionComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "condition"))
                    {
                        result.Condition.Add(FamilyHistoryParser.ParseFamilyHistoryRelationConditionComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
        /// <summary>
        /// Parse Patient
        /// </summary>
        public static Hl7.Fhir.Model.Patient ParsePatient(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Patient existingInstance = null)
        {
            Hl7.Fhir.Model.Patient result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Patient();
            string currentElementName     = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element language
                else if (atName == "language")
                {
                    result.LanguageElement = CodeParser.ParseCode(reader, errors);
                }

                // Parse element text
                else if (atName == "text")
                {
                    result.Text = NarrativeParser.ParseNarrative(reader, errors);
                }

                // Parse element contained
                else if (atName == "contained")
                {
                    result.Contained = new List <Hl7.Fhir.Model.Resource>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contained"))
                    {
                        result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element identifier
                else if (atName == "identifier")
                {
                    result.Identifier = new List <Hl7.Fhir.Model.Identifier>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "identifier"))
                    {
                        result.Identifier.Add(IdentifierParser.ParseIdentifier(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element name
                else if (atName == "name")
                {
                    result.Name = new List <Hl7.Fhir.Model.HumanName>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "name"))
                    {
                        result.Name.Add(HumanNameParser.ParseHumanName(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element telecom
                else if (atName == "telecom")
                {
                    result.Telecom = new List <Hl7.Fhir.Model.Contact>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "telecom"))
                    {
                        result.Telecom.Add(ContactParser.ParseContact(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element gender
                else if (atName == "gender")
                {
                    result.Gender = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element birthDate
                else if (atName == "birthDate")
                {
                    result.BirthDateElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                }

                // Parse element deceased
                else if (atName.StartsWith("deceased"))
                {
                    result.Deceased = FhirParser.ParseElement(reader, errors);
                }

                // Parse element address
                else if (atName == "address")
                {
                    result.Address = new List <Hl7.Fhir.Model.Address>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "address"))
                    {
                        result.Address.Add(AddressParser.ParseAddress(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element maritalStatus
                else if (atName == "maritalStatus")
                {
                    result.MaritalStatus = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element multipleBirth
                else if (atName.StartsWith("multipleBirth"))
                {
                    result.MultipleBirth = FhirParser.ParseElement(reader, errors);
                }

                // Parse element photo
                else if (atName == "photo")
                {
                    result.Photo = new List <Hl7.Fhir.Model.Attachment>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "photo"))
                    {
                        result.Photo.Add(AttachmentParser.ParseAttachment(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element contact
                else if (atName == "contact")
                {
                    result.Contact = new List <Hl7.Fhir.Model.Patient.ContactComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contact"))
                    {
                        result.Contact.Add(PatientParser.ParseContactComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element animal
                else if (atName == "animal")
                {
                    result.Animal = PatientParser.ParseAnimalComponent(reader, errors);
                }

                // Parse element communication
                else if (atName == "communication")
                {
                    result.Communication = new List <Hl7.Fhir.Model.CodeableConcept>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "communication"))
                    {
                        result.Communication.Add(CodeableConceptParser.ParseCodeableConcept(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element provider
                else if (atName == "provider")
                {
                    result.Provider = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element link
                else if (atName == "link")
                {
                    result.Link = new List <Hl7.Fhir.Model.ResourceReference>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "link"))
                    {
                        result.Link.Add(ResourceReferenceParser.ParseResourceReference(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element active
                else if (atName == "active")
                {
                    result.ActiveElement = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
Example #13
0
        /// <summary>
        /// Parse Observation
        /// </summary>
        public static Hl7.Fhir.Model.Observation ParseObservation(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Observation existingInstance = null)
        {
            Hl7.Fhir.Model.Observation result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Observation();
            string currentElementName         = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element language
                else if (atName == "language")
                {
                    result.LanguageElement = CodeParser.ParseCode(reader, errors);
                }

                // Parse element text
                else if (atName == "text")
                {
                    result.Text = NarrativeParser.ParseNarrative(reader, errors);
                }

                // Parse element contained
                else if (atName == "contained")
                {
                    result.Contained = new List <Hl7.Fhir.Model.Resource>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contained"))
                    {
                        result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element name
                else if (atName == "name")
                {
                    result.Name = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element value
                else if (atName.StartsWith("value"))
                {
                    result.Value = FhirParser.ParseElement(reader, errors);
                }

                // Parse element interpretation
                else if (atName == "interpretation")
                {
                    result.Interpretation = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element comments
                else if (atName == "comments")
                {
                    result.CommentsElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element applies
                else if (atName.StartsWith("applies"))
                {
                    result.Applies = FhirParser.ParseElement(reader, errors);
                }

                // Parse element issued
                else if (atName == "issued")
                {
                    result.IssuedElement = InstantParser.ParseInstant(reader, errors);
                }

                // Parse element status
                else if (atName == "status")
                {
                    result.StatusElement = CodeParser.ParseCode <Hl7.Fhir.Model.ObservationStatus>(reader, errors);
                }

                // Parse element reliability
                else if (atName == "reliability")
                {
                    result.ReliabilityElement = CodeParser.ParseCode <Hl7.Fhir.Model.Observation.ObservationReliability>(reader, errors);
                }

                // Parse element bodySite
                else if (atName == "bodySite")
                {
                    result.BodySite = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element method
                else if (atName == "method")
                {
                    result.Method = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element identifier
                else if (atName == "identifier")
                {
                    result.Identifier = IdentifierParser.ParseIdentifier(reader, errors);
                }

                // Parse element subject
                else if (atName == "subject")
                {
                    result.Subject = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element performer
                else if (atName == "performer")
                {
                    result.Performer = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element referenceRange
                else if (atName == "referenceRange")
                {
                    result.ReferenceRange = new List <Hl7.Fhir.Model.Observation.ObservationReferenceRangeComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "referenceRange"))
                    {
                        result.ReferenceRange.Add(ObservationParser.ParseObservationReferenceRangeComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element component
                else if (atName == "component")
                {
                    result.Component = new List <Hl7.Fhir.Model.Observation.ObservationComponentComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "component"))
                    {
                        result.Component.Add(ObservationParser.ParseObservationComponentComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
        /// <summary>
        /// Parse QuestionComponent
        /// </summary>
        public static Hl7.Fhir.Model.Questionnaire.QuestionComponent ParseQuestionComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Questionnaire.QuestionComponent existingInstance = null)
        {
            Hl7.Fhir.Model.Questionnaire.QuestionComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Questionnaire.QuestionComponent();
            string currentElementName = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element name
                else if (atName == "name")
                {
                    result.Name = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element text
                else if (atName == "text")
                {
                    result.TextElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element answer
                else if (atName.StartsWith("answer"))
                {
                    result.Answer = FhirParser.ParseElement(reader, errors);
                }

                // Parse element choice
                else if (atName == "choice")
                {
                    result.Choice = new List <Hl7.Fhir.Model.Coding>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "choice"))
                    {
                        result.Choice.Add(CodingParser.ParseCoding(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element options
                else if (atName.StartsWith("options"))
                {
                    result.Options = FhirParser.ParseElement(reader, errors);
                }

                // Parse element data
                else if (atName.StartsWith("data"))
                {
                    result.Data = FhirParser.ParseElement(reader, errors);
                }

                // Parse element remarks
                else if (atName == "remarks")
                {
                    result.RemarksElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
        /// <summary>
        /// Parse ActivityDefinition
        /// </summary>
        public static Hl7.Fhir.Model.ActivityDefinition ParseActivityDefinition(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.ActivityDefinition existingInstance = null)
        {
            Hl7.Fhir.Model.ActivityDefinition result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.ActivityDefinition();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "extension"))
                    {
                        result.Extension = new List <Hl7.Fhir.Model.Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element _id
                    else if (ParserUtils.IsAtFhirElement(reader, "_id"))
                    {
                        result.LocalId = Id.Parse(reader.ReadPrimitiveContents("id"));
                    }

                    // Parse element category
                    else if (ParserUtils.IsAtFhirElement(reader, "category"))
                    {
                        result.Category = CodeParser.ParseCode <Hl7.Fhir.Model.ActivityDefinition.ActivityDefinitionCategory>(reader, errors);
                    }

                    // Parse element code
                    else if (ParserUtils.IsAtFhirElement(reader, "code"))
                    {
                        result.Code = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element timing
                    else if (ParserUtils.IsAtFhirElement(reader, "timing", true))
                    {
                        result.Timing = FhirParser.ParseElement(reader, errors);
                    }

                    // Parse element location
                    else if (ParserUtils.IsAtFhirElement(reader, "location"))
                    {
                        result.Location = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element performer
                    else if (ParserUtils.IsAtFhirElement(reader, "performer"))
                    {
                        result.Performer = new List <Hl7.Fhir.Model.ResourceReference>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "performer"))
                        {
                            result.Performer.Add(ResourceReferenceParser.ParseResourceReference(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element product
                    else if (ParserUtils.IsAtFhirElement(reader, "product"))
                    {
                        result.Product = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element quantity
                    else if (ParserUtils.IsAtFhirElement(reader, "quantity"))
                    {
                        result.Quantity = QuantityParser.ParseQuantity(reader, errors);
                    }

                    // Parse element details
                    else if (ParserUtils.IsAtFhirElement(reader, "details"))
                    {
                        result.Details = FhirStringParser.ParseFhirString(reader, errors);
                    }

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }
        /// <summary>
        /// Parse MedicationPrescription
        /// </summary>
        public static Hl7.Fhir.Model.MedicationPrescription ParseMedicationPrescription(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.MedicationPrescription existingInstance = null)
        {
            Hl7.Fhir.Model.MedicationPrescription result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.MedicationPrescription();
            string currentElementName = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element language
                else if (atName == "language")
                {
                    result.LanguageElement = CodeParser.ParseCode(reader, errors);
                }

                // Parse element text
                else if (atName == "text")
                {
                    result.Text = NarrativeParser.ParseNarrative(reader, errors);
                }

                // Parse element contained
                else if (atName == "contained")
                {
                    result.Contained = new List <Hl7.Fhir.Model.Resource>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contained"))
                    {
                        result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element identifier
                else if (atName == "identifier")
                {
                    result.Identifier = new List <Hl7.Fhir.Model.Identifier>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "identifier"))
                    {
                        result.Identifier.Add(IdentifierParser.ParseIdentifier(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element dateWritten
                else if (atName == "dateWritten")
                {
                    result.DateWrittenElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                }

                // Parse element status
                else if (atName == "status")
                {
                    result.StatusElement = CodeParser.ParseCode <Hl7.Fhir.Model.MedicationPrescription.MedicationPrescriptionStatus>(reader, errors);
                }

                // Parse element patient
                else if (atName == "patient")
                {
                    result.Patient = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element prescriber
                else if (atName == "prescriber")
                {
                    result.Prescriber = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element encounter
                else if (atName == "encounter")
                {
                    result.Encounter = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element reasonForPrescribing
                else if (atName.StartsWith("reasonForPrescribing"))
                {
                    result.ReasonForPrescribing = FhirParser.ParseElement(reader, errors);
                }

                // Parse element medication
                else if (atName == "medication")
                {
                    result.Medication = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element dosageInstruction
                else if (atName == "dosageInstruction")
                {
                    result.DosageInstruction = new List <Hl7.Fhir.Model.MedicationPrescription.MedicationPrescriptionDosageInstructionComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "dosageInstruction"))
                    {
                        result.DosageInstruction.Add(MedicationPrescriptionParser.ParseMedicationPrescriptionDosageInstructionComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element dispense
                else if (atName == "dispense")
                {
                    result.Dispense = MedicationPrescriptionParser.ParseMedicationPrescriptionDispenseComponent(reader, errors);
                }

                // Parse element substitution
                else if (atName == "substitution")
                {
                    result.Substitution = MedicationPrescriptionParser.ParseMedicationPrescriptionSubstitutionComponent(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
        /// <summary>
        /// Parse MedicationDispenseDispenseDosageComponent
        /// </summary>
        public static Hl7.Fhir.Model.MedicationDispense.MedicationDispenseDispenseDosageComponent ParseMedicationDispenseDispenseDosageComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.MedicationDispense.MedicationDispenseDispenseDosageComponent existingInstance = null)
        {
            Hl7.Fhir.Model.MedicationDispense.MedicationDispenseDispenseDosageComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.MedicationDispense.MedicationDispenseDispenseDosageComponent();
            string currentElementName = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element additionalInstructions
                else if (atName.StartsWith("additionalInstructions"))
                {
                    result.AdditionalInstructions = FhirParser.ParseElement(reader, errors);
                }

                // Parse element timing
                else if (atName.StartsWith("timing"))
                {
                    result.Timing = FhirParser.ParseElement(reader, errors);
                }

                // Parse element site
                else if (atName == "site")
                {
                    result.Site = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element route
                else if (atName == "route")
                {
                    result.Route = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element method
                else if (atName == "method")
                {
                    result.Method = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element quantity
                else if (atName == "quantity")
                {
                    result.Quantity = QuantityParser.ParseQuantity(reader, errors);
                }

                // Parse element rate
                else if (atName == "rate")
                {
                    result.Rate = RatioParser.ParseRatio(reader, errors);
                }

                // Parse element maxDosePerPeriod
                else if (atName == "maxDosePerPeriod")
                {
                    result.MaxDosePerPeriod = RatioParser.ParseRatio(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
        /// <summary>
        /// Parse ElementDefinitionComponent
        /// </summary>
        public static Hl7.Fhir.Model.Profile.ElementDefinitionComponent ParseElementDefinitionComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Profile.ElementDefinitionComponent existingInstance = null)
        {
            Hl7.Fhir.Model.Profile.ElementDefinitionComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Profile.ElementDefinitionComponent();
            string currentElementName = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element short
                else if (atName == "short")
                {
                    result.ShortElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element formal
                else if (atName == "formal")
                {
                    result.FormalElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element comments
                else if (atName == "comments")
                {
                    result.CommentsElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element requirements
                else if (atName == "requirements")
                {
                    result.RequirementsElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element synonym
                else if (atName == "synonym")
                {
                    result.SynonymElement = new List <Hl7.Fhir.Model.FhirString>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "synonym"))
                    {
                        result.SynonymElement.Add(FhirStringParser.ParseFhirString(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element min
                else if (atName == "min")
                {
                    result.MinElement = IntegerParser.ParseInteger(reader, errors);
                }

                // Parse element max
                else if (atName == "max")
                {
                    result.MaxElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element type
                else if (atName == "type")
                {
                    result.Type = new List <Hl7.Fhir.Model.Profile.TypeRefComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "type"))
                    {
                        result.Type.Add(ProfileParser.ParseTypeRefComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element nameReference
                else if (atName == "nameReference")
                {
                    result.NameReferenceElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element value
                else if (atName.StartsWith("value"))
                {
                    result.Value = FhirParser.ParseElement(reader, errors);
                }

                // Parse element example
                else if (atName.StartsWith("example"))
                {
                    result.Example = FhirParser.ParseElement(reader, errors);
                }

                // Parse element maxLength
                else if (atName == "maxLength")
                {
                    result.MaxLengthElement = IntegerParser.ParseInteger(reader, errors);
                }

                // Parse element condition
                else if (atName == "condition")
                {
                    result.ConditionElement = new List <Hl7.Fhir.Model.Id>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "condition"))
                    {
                        result.ConditionElement.Add(IdParser.ParseId(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element constraint
                else if (atName == "constraint")
                {
                    result.Constraint = new List <Hl7.Fhir.Model.Profile.ElementDefinitionConstraintComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "constraint"))
                    {
                        result.Constraint.Add(ProfileParser.ParseElementDefinitionConstraintComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element mustSupport
                else if (atName == "mustSupport")
                {
                    result.MustSupportElement = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                }

                // Parse element isModifier
                else if (atName == "isModifier")
                {
                    result.IsModifierElement = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                }

                // Parse element binding
                else if (atName == "binding")
                {
                    result.BindingElement = FhirUriParser.ParseFhirUri(reader, errors);
                }

                // Parse element mapping
                else if (atName == "mapping")
                {
                    result.Mapping = new List <Hl7.Fhir.Model.Profile.ElementDefinitionMappingComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "mapping"))
                    {
                        result.Mapping.Add(ProfileParser.ParseElementDefinitionMappingComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
Example #19
0
        /// <summary>
        /// Parse StudyInterventionComponent
        /// </summary>
        public static Hl7.Fhir.Model.Study.StudyInterventionComponent ParseStudyInterventionComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Study.StudyInterventionComponent existingInstance = null)
        {
            Hl7.Fhir.Model.Study.StudyInterventionComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Study.StudyInterventionComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "extension"))
                    {
                        result.Extension = new List <Hl7.Fhir.Model.Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element _id
                    else if (ParserUtils.IsAtFhirElement(reader, "_id"))
                    {
                        result.LocalId = Id.Parse(reader.ReadPrimitiveContents("id"));
                    }

                    // Parse element type
                    else if (ParserUtils.IsAtFhirElement(reader, "type"))
                    {
                        result.Type = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element model
                    else if (ParserUtils.IsAtFhirElement(reader, "model"))
                    {
                        result.Model = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element randomized
                    else if (ParserUtils.IsAtFhirElement(reader, "randomized"))
                    {
                        result.Randomized = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                    }

                    // Parse element blindingScheme
                    else if (ParserUtils.IsAtFhirElement(reader, "blindingScheme"))
                    {
                        result.BlindingScheme = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element randomizationQuotient
                    else if (ParserUtils.IsAtFhirElement(reader, "randomizationQuotient", true))
                    {
                        result.RandomizationQuotient = FhirParser.ParseElement(reader, errors);
                    }

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }
        /// <summary>
        /// Parse ProfileBindingComponent
        /// </summary>
        public static Hl7.Fhir.Model.Profile.ProfileBindingComponent ParseProfileBindingComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Profile.ProfileBindingComponent existingInstance = null)
        {
            Hl7.Fhir.Model.Profile.ProfileBindingComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Profile.ProfileBindingComponent();
            string currentElementName = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element name
                else if (atName == "name")
                {
                    result.NameElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element isExtensible
                else if (atName == "isExtensible")
                {
                    result.IsExtensibleElement = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                }

                // Parse element conformance
                else if (atName == "conformance")
                {
                    result.ConformanceElement = CodeParser.ParseCode <Hl7.Fhir.Model.Profile.BindingConformance>(reader, errors);
                }

                // Parse element description
                else if (atName == "description")
                {
                    result.DescriptionElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element reference
                else if (atName.StartsWith("reference"))
                {
                    result.Reference = FhirParser.ParseElement(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
        /// <summary>
        /// Parse Problem
        /// </summary>
        public static Hl7.Fhir.Model.Problem ParseProblem(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Problem existingInstance = null)
        {
            Hl7.Fhir.Model.Problem result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Problem();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "extension"))
                    {
                        result.Extension = new List <Hl7.Fhir.Model.Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element language
                    else if (ParserUtils.IsAtFhirElement(reader, "language"))
                    {
                        result.Language = CodeParser.ParseCode(reader, errors);
                    }

                    // Parse element text
                    else if (ParserUtils.IsAtFhirElement(reader, "text"))
                    {
                        result.Text = NarrativeParser.ParseNarrative(reader, errors);
                    }

                    // Parse element contained
                    else if (ParserUtils.IsAtFhirElement(reader, "contained"))
                    {
                        result.Contained = new List <Hl7.Fhir.Model.Resource>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "contained"))
                        {
                            result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element _id
                    else if (ParserUtils.IsAtFhirElement(reader, "_id"))
                    {
                        result.LocalId = Id.Parse(reader.ReadPrimitiveContents("id"));
                    }

                    // Parse element subject
                    else if (ParserUtils.IsAtFhirElement(reader, "subject"))
                    {
                        result.Subject = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element visit
                    else if (ParserUtils.IsAtFhirElement(reader, "visit"))
                    {
                        result.Visit = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element asserter
                    else if (ParserUtils.IsAtFhirElement(reader, "asserter"))
                    {
                        result.Asserter = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element dateAsserted
                    else if (ParserUtils.IsAtFhirElement(reader, "dateAsserted"))
                    {
                        result.DateAsserted = DateParser.ParseDate(reader, errors);
                    }

                    // Parse element code
                    else if (ParserUtils.IsAtFhirElement(reader, "code"))
                    {
                        result.Code = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element category
                    else if (ParserUtils.IsAtFhirElement(reader, "category"))
                    {
                        result.Category = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element status
                    else if (ParserUtils.IsAtFhirElement(reader, "status"))
                    {
                        result.Status = CodeParser.ParseCode <Hl7.Fhir.Model.Problem.ProblemStatus>(reader, errors);
                    }

                    // Parse element certainty
                    else if (ParserUtils.IsAtFhirElement(reader, "certainty"))
                    {
                        result.Certainty = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element severity
                    else if (ParserUtils.IsAtFhirElement(reader, "severity"))
                    {
                        result.Severity = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element onset
                    else if (ParserUtils.IsAtFhirElement(reader, "onset", true))
                    {
                        result.Onset = FhirParser.ParseElement(reader, errors);
                    }

                    // Parse element abatement
                    else if (ParserUtils.IsAtFhirElement(reader, "abatement", true))
                    {
                        result.Abatement = FhirParser.ParseElement(reader, errors);
                    }

                    // Parse element stage
                    else if (ParserUtils.IsAtFhirElement(reader, "stage"))
                    {
                        result.Stage = ProblemParser.ParseProblemStageComponent(reader, errors);
                    }

                    // Parse element evidence
                    else if (ParserUtils.IsAtFhirElement(reader, "evidence"))
                    {
                        result.Evidence = new List <Hl7.Fhir.Model.Problem.ProblemEvidenceComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "evidence"))
                        {
                            result.Evidence.Add(ProblemParser.ParseProblemEvidenceComponent(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element location
                    else if (ParserUtils.IsAtFhirElement(reader, "location"))
                    {
                        result.Location = new List <Hl7.Fhir.Model.Problem.ProblemLocationComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "location"))
                        {
                            result.Location.Add(ProblemParser.ParseProblemLocationComponent(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element relatedItem
                    else if (ParserUtils.IsAtFhirElement(reader, "relatedItem"))
                    {
                        result.RelatedItem = new List <Hl7.Fhir.Model.Problem.ProblemRelatedItemComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "relatedItem"))
                        {
                            result.RelatedItem.Add(ProblemParser.ParseProblemRelatedItemComponent(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element notes
                    else if (ParserUtils.IsAtFhirElement(reader, "notes"))
                    {
                        result.Notes = FhirStringParser.ParseFhirString(reader, errors);
                    }

                    else
                    {
                        errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                        reader.SkipSubElementsFor(currentElementName);
                        result = null;
                    }
                }

                reader.LeaveElement();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }
Example #22
0
        /// <summary>
        /// Parse CarePlanActivityComponent
        /// </summary>
        public static Hl7.Fhir.Model.CarePlan.CarePlanActivityComponent ParseCarePlanActivityComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.CarePlan.CarePlanActivityComponent existingInstance = null)
        {
            Hl7.Fhir.Model.CarePlan.CarePlanActivityComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.CarePlan.CarePlanActivityComponent();
            string currentElementName = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element category
                else if (atName == "category")
                {
                    result.CategoryElement = CodeParser.ParseCode <Hl7.Fhir.Model.CarePlan.CarePlanActivityCategory>(reader, errors);
                }

                // Parse element code
                else if (atName == "code")
                {
                    result.Code = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element status
                else if (atName == "status")
                {
                    result.StatusElement = CodeParser.ParseCode <Hl7.Fhir.Model.CarePlan.CarePlanActivityStatus>(reader, errors);
                }

                // Parse element prohibited
                else if (atName == "prohibited")
                {
                    result.ProhibitedElement = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                }

                // Parse element timing
                else if (atName.StartsWith("timing"))
                {
                    result.Timing = FhirParser.ParseElement(reader, errors);
                }

                // Parse element location
                else if (atName == "location")
                {
                    result.Location = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element performer
                else if (atName == "performer")
                {
                    result.Performer = new List <Hl7.Fhir.Model.ResourceReference>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "performer"))
                    {
                        result.Performer.Add(ResourceReferenceParser.ParseResourceReference(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element product
                else if (atName == "product")
                {
                    result.Product = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element dailyAmount
                else if (atName == "dailyAmount")
                {
                    result.DailyAmount = QuantityParser.ParseQuantity(reader, errors);
                }

                // Parse element quantity
                else if (atName == "quantity")
                {
                    result.Quantity = QuantityParser.ParseQuantity(reader, errors);
                }

                // Parse element details
                else if (atName == "details")
                {
                    result.DetailsElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element actionTaken
                else if (atName == "actionTaken")
                {
                    result.ActionTaken = new List <Hl7.Fhir.Model.ResourceReference>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "actionTaken"))
                    {
                        result.ActionTaken.Add(ResourceReferenceParser.ParseResourceReference(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element notes
                else if (atName == "notes")
                {
                    result.NotesElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }