/// <summary>
        /// Parse Demographics
        /// </summary>
        public static Hl7.Fhir.Model.Demographics ParseDemographics(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Demographics existingInstance = null)
        {
            Hl7.Fhir.Model.Demographics result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Demographics();
            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 _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 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.BirthDate = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                    }

                    // Parse element deceased
                    else if (atName == "deceased")
                    {
                        result.Deceased = FhirBooleanParser.ParseFhirBoolean(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 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 maritalStatus
                    else if (atName == "maritalStatus")
                    {
                        result.MaritalStatus = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element language
                    else if (atName == "language")
                    {
                        result.Language = new List <Hl7.Fhir.Model.Demographics.DemographicsLanguageComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "language"))
                        {
                            result.Language.Add(DemographicsParser.ParseDemographicsLanguageComponent(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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse Provider
        /// </summary>
        public static Provider ParseProvider(IFhirReader reader, ErrorList errors, Provider existingInstance = null)
        {
            Provider result = existingInstance != null ? existingInstance : new Provider();

            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 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 <Resource>();
                        reader.EnterArray();

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

                        reader.LeaveArray();
                    }

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

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

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

                        reader.LeaveArray();
                    }

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

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

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

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

                        reader.LeaveArray();
                    }

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

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

                        reader.LeaveArray();
                    }

                    // Parse element period
                    else if (ParserUtils.IsAtFhirElement(reader, "period"))
                    {
                        result.Period = PeriodParser.ParsePeriod(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);
        }