/// <summary>
        /// Parse Document
        /// </summary>
        public static Hl7.Fhir.Model.Document ParseDocument(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Document existingInstance = null)
        {
            Hl7.Fhir.Model.Document result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Document();
            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 = IdentifierParser.ParseIdentifier(reader, errors);
                }

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

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

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

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

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

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

                // Parse element confidentiality
                else if (atName == "confidentiality")
                {
                    result.Confidentiality = CodingParser.ParseCoding(reader, errors);
                }

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

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

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

                    reader.LeaveArray();
                }

                // Parse element attester
                else if (atName == "attester")
                {
                    result.Attester = new List <Hl7.Fhir.Model.Document.DocumentAttesterComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "attester"))
                    {
                        result.Attester.Add(DocumentParser.ParseDocumentAttesterComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

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

                // Parse element event
                else if (atName == "event")
                {
                    result.Event = DocumentParser.ParseDocumentEventComponent(reader, errors);
                }

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

                // Parse element replaces
                else if (atName == "replaces")
                {
                    result.ReplacesElement = IdParser.ParseId(reader, errors);
                }

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

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

                    reader.LeaveArray();
                }

                // Parse element stylesheet
                else if (atName == "stylesheet")
                {
                    result.Stylesheet = AttachmentParser.ParseAttachment(reader, errors);
                }

                // Parse element representation
                else if (atName == "representation")
                {
                    result.Representation = AttachmentParser.ParseAttachment(reader, errors);
                }

                // Parse element section
                else if (atName == "section")
                {
                    result.Section = new List <Hl7.Fhir.Model.Document.SectionComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "section"))
                    {
                        result.Section.Add(DocumentParser.ParseSectionComponent(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);
        }
Esempio n. 2
0
        /// <summary>
        /// Parse RelatedPerson
        /// </summary>
        public static Hl7.Fhir.Model.RelatedPerson ParseRelatedPerson(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.RelatedPerson existingInstance = null)
        {
            Hl7.Fhir.Model.RelatedPerson result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.RelatedPerson();
            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 patient
                else if (atName == "patient")
                {
                    result.Patient = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

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

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

                // 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 address
                else if (atName == "address")
                {
                    result.Address = AddressParser.ParseAddress(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();
                }

                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 MedicationDispense
        /// </summary>
        public static Hl7.Fhir.Model.MedicationDispense ParseMedicationDispense(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.MedicationDispense existingInstance = null)
        {
            Hl7.Fhir.Model.MedicationDispense result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.MedicationDispense();
            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 = IdentifierParser.ParseIdentifier(reader, errors);
                }

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

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

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

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

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

                    reader.LeaveArray();
                }

                // Parse element dispense
                else if (atName == "dispense")
                {
                    result.Dispense = new List <Hl7.Fhir.Model.MedicationDispense.MedicationDispenseDispenseComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "dispense"))
                    {
                        result.Dispense.Add(MedicationDispenseParser.ParseMedicationDispenseDispenseComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element substitution
                else if (atName == "substitution")
                {
                    result.Substitution = MedicationDispenseParser.ParseMedicationDispenseSubstitutionComponent(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);
        }
Esempio n. 4
0
        /// <summary>
        /// Parse Coverage
        /// </summary>
        public static Hl7.Fhir.Model.Coverage ParseCoverage(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Coverage existingInstance = null)
        {
            Hl7.Fhir.Model.Coverage result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Coverage();
            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 issuer
                else if (atName == "issuer")
                {
                    result.Issuer = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element period
                else if (atName == "period")
                {
                    result.Period = PeriodParser.ParsePeriod(reader, errors);
                }

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

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

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

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

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

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

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

                // Parse element subscriber
                else if (atName == "subscriber")
                {
                    result.Subscriber = CoverageParser.ParseCoverageSubscriberComponent(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 DiagnosticReport
        /// </summary>
        public static Hl7.Fhir.Model.DiagnosticReport ParseDiagnosticReport(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.DiagnosticReport existingInstance = null)
        {
            Hl7.Fhir.Model.DiagnosticReport result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.DiagnosticReport();
            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 status
                else if (atName == "status")
                {
                    result.StatusElement = CodeParser.ParseCode <Hl7.Fhir.Model.ObservationStatus>(reader, errors);
                }

                // Parse element issued
                else if (atName == "issued")
                {
                    result.IssuedElement = FhirDateTimeParser.ParseFhirDateTime(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 reportId
                else if (atName == "reportId")
                {
                    result.ReportId = IdentifierParser.ParseIdentifier(reader, errors);
                }

                // Parse element requestDetail
                else if (atName == "requestDetail")
                {
                    result.RequestDetail = new List <Hl7.Fhir.Model.DiagnosticReport.DiagnosticReportRequestDetailComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "requestDetail"))
                    {
                        result.RequestDetail.Add(DiagnosticReportParser.ParseDiagnosticReportRequestDetailComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

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

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

                // Parse element results
                else if (atName == "results")
                {
                    result.Results = DiagnosticReportParser.ParseResultGroupComponent(reader, errors);
                }

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

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

                    reader.LeaveArray();
                }

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

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

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

                    reader.LeaveArray();
                }

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

                    while (ParserUtils.IsAtArrayElement(reader, "representation"))
                    {
                        result.Representation.Add(AttachmentParser.ParseAttachment(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);
        }
Esempio n. 6
0
        /// <summary>
        /// Parse ImagingStudy
        /// </summary>
        public static Hl7.Fhir.Model.ImagingStudy ParseImagingStudy(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.ImagingStudy existingInstance = null)
        {
            Hl7.Fhir.Model.ImagingStudy result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.ImagingStudy();
            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 dateTime
                else if (atName == "dateTime")
                {
                    result.DateTimeElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                }

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

                // Parse element uid
                else if (atName == "uid")
                {
                    result.UidElement = OidParser.ParseOid(reader, errors);
                }

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

                // 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 modality
                else if (atName == "modality")
                {
                    result.Modality_Element = new List <Code <Hl7.Fhir.Model.ImagingStudy.ImagingModality> >();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "modality"))
                    {
                        result.Modality_Element.Add(CodeParser.ParseCode <Hl7.Fhir.Model.ImagingStudy.ImagingModality>(reader, errors));
                    }

                    reader.LeaveArray();
                }

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

                // Parse element availability
                else if (atName == "availability")
                {
                    result.AvailabilityElement = CodeParser.ParseCode <Hl7.Fhir.Model.ImagingStudy.InstanceAvailability>(reader, errors);
                }

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

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

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

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

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

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

                    reader.LeaveArray();
                }

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

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

                // Parse element series
                else if (atName == "series")
                {
                    result.Series = new List <Hl7.Fhir.Model.ImagingStudy.ImagingStudySeriesComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "series"))
                    {
                        result.Series.Add(ImagingStudyParser.ParseImagingStudySeriesComponent(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 Protocol
        /// </summary>
        public static Hl7.Fhir.Model.Protocol ParseProtocol(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Protocol existingInstance = null)
        {
            Hl7.Fhir.Model.Protocol result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Protocol();
            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 title
                    else if (ParserUtils.IsAtFhirElement(reader, "title"))
                    {
                        result.Title = FhirStringParser.ParseFhirString(reader, errors);
                    }

                    // Parse element type
                    else if (ParserUtils.IsAtFhirElement(reader, "type"))
                    {
                        result.Type = CodeParser.ParseCode <Hl7.Fhir.Model.Protocol.ProtocolType>(reader, errors);
                    }

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

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

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

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

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

                    // Parse element step
                    else if (ParserUtils.IsAtFhirElement(reader, "step"))
                    {
                        result.Step = new List <Hl7.Fhir.Model.Protocol.ProtocolStepComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "step"))
                        {
                            result.Step.Add(ProtocolParser.ParseProtocolStepComponent(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);
        }
Esempio n. 8
0
        /// <summary>
        /// Parse Procedure
        /// </summary>
        public static Hl7.Fhir.Model.Procedure ParseProcedure(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Procedure existingInstance = null)
        {
            Hl7.Fhir.Model.Procedure result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Procedure();
            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 type
                else if (atName == "type")
                {
                    result.Type = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

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

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

                    reader.LeaveArray();
                }

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

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

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

                    reader.LeaveArray();
                }

                // Parse element date
                else if (atName == "date")
                {
                    result.Date = PeriodParser.ParsePeriod(reader, errors);
                }

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

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

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

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

                    reader.LeaveArray();
                }

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

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

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

                    while (ParserUtils.IsAtArrayElement(reader, "relatedItem"))
                    {
                        result.RelatedItem.Add(ProcedureParser.ParseProcedureRelatedItemComponent(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);
        }
Esempio n. 9
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 Substance
        /// </summary>
        public static Hl7.Fhir.Model.Substance ParseSubstance(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Substance existingInstance = null)
        {
            Hl7.Fhir.Model.Substance result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Substance();
            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 = IdentifierParser.ParseIdentifier(reader, errors);
                }

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

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

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

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

                // Parse element effectiveTime
                else if (atName == "effectiveTime")
                {
                    result.EffectiveTime = PeriodParser.ParsePeriod(reader, errors);
                }

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

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

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

                    reader.LeaveArray();
                }

                // Parse element quantityMode
                else if (atName == "quantityMode")
                {
                    result.QuantityMode = CodeableConceptParser.ParseCodeableConcept(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);
        }
Esempio n. 11
0
        /// <summary>
        /// Parse Group
        /// </summary>
        public static Hl7.Fhir.Model.Group ParseGroup(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Group existingInstance = null)
        {
            Hl7.Fhir.Model.Group result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Group();
            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 = IdentifierParser.ParseIdentifier(reader, errors);
                }

                // Parse element type
                else if (atName == "type")
                {
                    result.TypeElement = CodeParser.ParseCode <Hl7.Fhir.Model.Group.GroupType>(reader, errors);
                }

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

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

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

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

                // Parse element characteristic
                else if (atName == "characteristic")
                {
                    result.Characteristic = new List <Hl7.Fhir.Model.Group.GroupCharacteristicComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "characteristic"))
                    {
                        result.Characteristic.Add(GroupParser.ParseGroupCharacteristicComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

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

                    while (ParserUtils.IsAtArrayElement(reader, "member"))
                    {
                        result.Member.Add(ResourceReferenceParser.ParseResourceReference(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 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);
        }
        /// <summary>
        /// Parse OperationOutcome
        /// </summary>
        public static Hl7.Fhir.Model.OperationOutcome ParseOperationOutcome(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.OperationOutcome existingInstance = null)
        {
            Hl7.Fhir.Model.OperationOutcome result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.OperationOutcome();
            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 issue
                else if (atName == "issue")
                {
                    result.Issue = new List <Hl7.Fhir.Model.OperationOutcome.OperationOutcomeIssueComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "issue"))
                    {
                        result.Issue.Add(OperationOutcomeParser.ParseOperationOutcomeIssueComponent(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 Prescription
        /// </summary>
        public static Prescription ParsePrescription(IFhirReader reader, ErrorList errors, Prescription existingInstance = null)
        {
            Prescription result = existingInstance != null ? existingInstance : new Prescription();

            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 status
                    else if (ParserUtils.IsAtFhirElement(reader, "status"))
                    {
                        result.Status = CodeParser.ParseCode <Prescription.PrescriptionStatus>(reader, errors);
                    }

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

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

                    // Parse element prescribed
                    else if (ParserUtils.IsAtFhirElement(reader, "prescribed"))
                    {
                        result.Prescribed = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                    }

                    // Parse element dispense
                    else if (ParserUtils.IsAtFhirElement(reader, "dispense"))
                    {
                        result.Dispense = PrescriptionParser.ParsePrescriptionDispenseComponent(reader, errors);
                    }

                    // Parse element medicine
                    else if (ParserUtils.IsAtFhirElement(reader, "medicine"))
                    {
                        result.Medicine = PrescriptionParser.ParsePrescriptionMedicineComponent(reader, errors);
                    }

                    // Parse element administrationRequest
                    else if (ParserUtils.IsAtFhirElement(reader, "administrationRequest"))
                    {
                        result.AdministrationRequest = PrescriptionParser.ParsePrescriptionAdministrationRequestComponent(reader, errors);
                    }

                    // Parse element reason
                    else if (ParserUtils.IsAtFhirElement(reader, "reason"))
                    {
                        result.Reason = CodeableConceptParser.ParseCodeableConcept(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 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);
        }
Esempio n. 16
0
        /// <summary>
        /// Parse Product
        /// </summary>
        public static Product ParseProduct(IFhirReader reader, ErrorList errors, Product existingInstance = null)
        {
            Product result = existingInstance != null ? existingInstance : new Product();

            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());
                    }

                    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 Message
        /// </summary>
        public static Hl7.Fhir.Model.Message ParseMessage(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Message existingInstance = null)
        {
            Hl7.Fhir.Model.Message result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Message();
            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.IdentifierElement = IdParser.ParseId(reader, errors);
                }

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

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

                // Parse element response
                else if (atName == "response")
                {
                    result.Response = MessageParser.ParseMessageResponseComponent(reader, errors);
                }

                // Parse element source
                else if (atName == "source")
                {
                    result.Source = MessageParser.ParseMessageSourceComponent(reader, errors);
                }

                // Parse element destination
                else if (atName == "destination")
                {
                    result.Destination = MessageParser.ParseMessageDestinationComponent(reader, errors);
                }

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

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

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

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

                // Parse element effective
                else if (atName == "effective")
                {
                    result.Effective = PeriodParser.ParsePeriod(reader, errors);
                }

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

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

                    while (ParserUtils.IsAtArrayElement(reader, "data"))
                    {
                        result.Data.Add(ResourceReferenceParser.ParseResourceReference(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);
        }
Esempio n. 18
0
        /// <summary>
        /// Parse XdsFolder
        /// </summary>
        public static XdsFolder ParseXdsFolder(IFhirReader reader, ErrorList errors, XdsFolder existingInstance = null)
        {
            XdsFolder result = existingInstance != null ? existingInstance : new XdsFolder();

            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 code
                    else if (ParserUtils.IsAtFhirElement(reader, "code"))
                    {
                        result.Code = new List <Coding>();
                        reader.EnterArray();

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

                        reader.LeaveArray();
                    }

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

                    // Parse element patientId
                    else if (ParserUtils.IsAtFhirElement(reader, "patientId"))
                    {
                        result.PatientId = IdentifierParser.ParseIdentifier(reader, errors);
                    }

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

                    // Parse element comments
                    else if (ParserUtils.IsAtFhirElement(reader, "comments"))
                    {
                        result.Comments = 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 Conformance
        /// </summary>
        public static Hl7.Fhir.Model.Conformance ParseConformance(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Conformance existingInstance = null)
        {
            Hl7.Fhir.Model.Conformance result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Conformance();
            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.IdentifierElement = FhirStringParser.ParseFhirString(reader, errors);
                }

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

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

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

                // 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 description
                else if (atName == "description")
                {
                    result.DescriptionElement = FhirStringParser.ParseFhirString(reader, errors);
                }

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

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

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

                // Parse element software
                else if (atName == "software")
                {
                    result.Software = ConformanceParser.ParseConformanceSoftwareComponent(reader, errors);
                }

                // Parse element implementation
                else if (atName == "implementation")
                {
                    result.Implementation = ConformanceParser.ParseConformanceImplementationComponent(reader, errors);
                }

                // Parse element fhirVersion
                else if (atName == "fhirVersion")
                {
                    result.FhirVersionElement = IdParser.ParseId(reader, errors);
                }

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

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

                    while (ParserUtils.IsAtArrayElement(reader, "format"))
                    {
                        result.FormatElement.Add(CodeParser.ParseCode(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element rest
                else if (atName == "rest")
                {
                    result.Rest = new List <Hl7.Fhir.Model.Conformance.ConformanceRestComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "rest"))
                    {
                        result.Rest.Add(ConformanceParser.ParseConformanceRestComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element messaging
                else if (atName == "messaging")
                {
                    result.Messaging = new List <Hl7.Fhir.Model.Conformance.ConformanceMessagingComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "messaging"))
                    {
                        result.Messaging.Add(ConformanceParser.ParseConformanceMessagingComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element document
                else if (atName == "document")
                {
                    result.Document = new List <Hl7.Fhir.Model.Conformance.ConformanceDocumentComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "document"))
                    {
                        result.Document.Add(ConformanceParser.ParseConformanceDocumentComponent(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 XdsEntry
        /// </summary>
        public static XdsEntry ParseXdsEntry(IFhirReader reader, ErrorList errors, XdsEntry existingInstance = null)
        {
            XdsEntry result = existingInstance != null ? existingInstance : new XdsEntry();

            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 url
                    else if (ParserUtils.IsAtFhirElement(reader, "url"))
                    {
                        result.Url = FhirUriParser.ParseFhirUri(reader, errors);
                    }

                    // Parse element repositoryId
                    else if (ParserUtils.IsAtFhirElement(reader, "repositoryId"))
                    {
                        result.RepositoryId = FhirUriParser.ParseFhirUri(reader, errors);
                    }

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

                    // Parse element format
                    else if (ParserUtils.IsAtFhirElement(reader, "format"))
                    {
                        result.Format = CodingParser.ParseCoding(reader, errors);
                    }

                    // Parse element class
                    else if (ParserUtils.IsAtFhirElement(reader, "class"))
                    {
                        result.Class = CodingParser.ParseCoding(reader, errors);
                    }

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

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

                    // Parse element documentId
                    else if (ParserUtils.IsAtFhirElement(reader, "documentId"))
                    {
                        result.DocumentId = FhirUriParser.ParseFhirUri(reader, errors);
                    }

                    // Parse element availability
                    else if (ParserUtils.IsAtFhirElement(reader, "availability"))
                    {
                        result.Availability = CodeParser.ParseCode <XdsEntry.XdsEntryAvailability>(reader, errors);
                    }

                    // Parse element confidentialityCode
                    else if (ParserUtils.IsAtFhirElement(reader, "confidentialityCode"))
                    {
                        result.ConfidentialityCode = CodingParser.ParseCoding(reader, errors);
                    }

                    // Parse element created
                    else if (ParserUtils.IsAtFhirElement(reader, "created"))
                    {
                        result.Created = InstantParser.ParseInstant(reader, errors);
                    }

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

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

                        reader.LeaveArray();
                    }

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

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

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

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

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

                        reader.LeaveArray();
                    }

                    // Parse element patientId
                    else if (ParserUtils.IsAtFhirElement(reader, "patientId"))
                    {
                        result.PatientId = IdentifierParser.ParseIdentifier(reader, errors);
                    }

                    // Parse element sourcePatientId
                    else if (ParserUtils.IsAtFhirElement(reader, "sourcePatientId"))
                    {
                        result.SourcePatientId = IdentifierParser.ParseIdentifier(reader, errors);
                    }

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

                    // Parse element author
                    else if (ParserUtils.IsAtFhirElement(reader, "author"))
                    {
                        result.Author = new List <XdsEntry.XdsEntryAuthorComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "author"))
                        {
                            result.Author.Add(XdsEntryParser.ParseXdsEntryAuthorComponent(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element authenticator
                    else if (ParserUtils.IsAtFhirElement(reader, "authenticator"))
                    {
                        result.Authenticator = XdsEntryParser.ParseXdsEntryAuthenticatorComponent(reader, errors);
                    }

                    // Parse element facilityType
                    else if (ParserUtils.IsAtFhirElement(reader, "facilityType"))
                    {
                        result.FacilityType = CodingParser.ParseCoding(reader, errors);
                    }

                    // Parse element practiceSetting
                    else if (ParserUtils.IsAtFhirElement(reader, "practiceSetting"))
                    {
                        result.PracticeSetting = CodingParser.ParseCoding(reader, errors);
                    }

                    // Parse element homeCommunity
                    else if (ParserUtils.IsAtFhirElement(reader, "homeCommunity"))
                    {
                        result.HomeCommunity = FhirUriParser.ParseFhirUri(reader, errors);
                    }

                    // Parse element service
                    else if (ParserUtils.IsAtFhirElement(reader, "service"))
                    {
                        result.Service = XdsEntryParser.ParseXdsEntryServiceComponent(reader, errors);
                    }

                    // Parse element comments
                    else if (ParserUtils.IsAtFhirElement(reader, "comments"))
                    {
                        result.Comments = 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 DeviceLog
        /// </summary>
        public static Hl7.Fhir.Model.DeviceLog ParseDeviceLog(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.DeviceLog existingInstance = null)
        {
            Hl7.Fhir.Model.DeviceLog result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.DeviceLog();
            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 instant
                else if (atName == "instant")
                {
                    result.InstantElement = InstantParser.ParseInstant(reader, errors);
                }

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

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

                // Parse element item
                else if (atName == "item")
                {
                    result.Item = new List <Hl7.Fhir.Model.DeviceLog.DeviceLogItemComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "item"))
                    {
                        result.Item.Add(DeviceLogParser.ParseDeviceLogItemComponent(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);
        }
Esempio n. 22
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 Practitioner
        /// </summary>
        public static Hl7.Fhir.Model.Practitioner ParsePractitioner(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Practitioner existingInstance = null)
        {
            Hl7.Fhir.Model.Practitioner result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Practitioner();
            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 = HumanNameParser.ParseHumanName(reader, errors);
                }

                // 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 address
                else if (atName == "address")
                {
                    result.Address = AddressParser.ParseAddress(reader, errors);
                }

                // 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 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 organization
                else if (atName == "organization")
                {
                    result.Organization = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

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

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

                    reader.LeaveArray();
                }

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

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

                    reader.LeaveArray();
                }

                // Parse element period
                else if (atName == "period")
                {
                    result.Period = PeriodParser.ParsePeriod(reader, errors);
                }

                // Parse element qualification
                else if (atName == "qualification")
                {
                    result.Qualification = new List <Hl7.Fhir.Model.Practitioner.PractitionerQualificationComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "qualification"))
                    {
                        result.Qualification.Add(PractitionerParser.ParsePractitionerQualificationComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // 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();
                }

                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);
        }
Esempio n. 24
0
        /// <summary>
        /// Parse Immunization
        /// </summary>
        public static Hl7.Fhir.Model.Immunization ParseImmunization(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Immunization existingInstance = null)
        {
            Hl7.Fhir.Model.Immunization result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Immunization();
            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 date
                else if (atName == "date")
                {
                    result.DateElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                }

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

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

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

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

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

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

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

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

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

                // Parse element expirationDate
                else if (atName == "expirationDate")
                {
                    result.ExpirationDateElement = DateParser.ParseDate(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 doseQuantity
                else if (atName == "doseQuantity")
                {
                    result.DoseQuantity = QuantityParser.ParseQuantity(reader, errors);
                }

                // Parse element explanation
                else if (atName == "explanation")
                {
                    result.Explanation = ImmunizationParser.ParseImmunizationExplanationComponent(reader, errors);
                }

                // Parse element reaction
                else if (atName == "reaction")
                {
                    result.Reaction = new List <Hl7.Fhir.Model.Immunization.ImmunizationReactionComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "reaction"))
                    {
                        result.Reaction.Add(ImmunizationParser.ParseImmunizationReactionComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element vaccinationProtocol
                else if (atName == "vaccinationProtocol")
                {
                    result.VaccinationProtocol = ImmunizationParser.ParseImmunizationVaccinationProtocolComponent(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 Organization
        /// </summary>
        public static Hl7.Fhir.Model.Organization ParseOrganization(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Organization existingInstance = null)
        {
            Hl7.Fhir.Model.Organization result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Organization();
            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.NameElement = FhirStringParser.ParseFhirString(reader, errors);
                }

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

                // 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 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 partOf
                else if (atName == "partOf")
                {
                    result.PartOf = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

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

                    while (ParserUtils.IsAtArrayElement(reader, "contact"))
                    {
                        result.Contact.Add(OrganizationParser.ParseOrganizationContactComponent(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);
        }
        /// <summary>
        /// Parse FamilyHistory
        /// </summary>
        public static Hl7.Fhir.Model.FamilyHistory ParseFamilyHistory(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.FamilyHistory existingInstance = null)
        {
            Hl7.Fhir.Model.FamilyHistory result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.FamilyHistory();
            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 note
                else if (atName == "note")
                {
                    result.NoteElement = FhirStringParser.ParseFhirString(reader, errors);
                }

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

                    while (ParserUtils.IsAtArrayElement(reader, "relation"))
                    {
                        result.Relation.Add(FamilyHistoryParser.ParseFamilyHistoryRelationComponent(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);
        }
Esempio n. 27
0
        /// <summary>
        /// Parse Device
        /// </summary>
        public static Hl7.Fhir.Model.Device ParseDevice(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Device existingInstance = null)
        {
            Hl7.Fhir.Model.Device result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Device();
            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 type
                else if (atName == "type")
                {
                    result.Type = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

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

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

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

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

                // Parse element identity
                else if (atName == "identity")
                {
                    result.Identity = DeviceParser.ParseDeviceIdentityComponent(reader, errors);
                }

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

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

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

                    reader.LeaveArray();
                }

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

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

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

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

                    reader.LeaveArray();
                }

                // Parse element url
                else if (atName == "url")
                {
                    result.UrlElement = FhirUriParser.ParseFhirUri(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);
        }
Esempio n. 28
0
        /// <summary>
        /// Parse XdsEntry2
        /// </summary>
        public static XdsEntry2 ParseXdsEntry2(IFhirReader reader, ErrorList errors, XdsEntry2 existingInstance = null)
        {
            XdsEntry2 result = existingInstance != null ? existingInstance : new XdsEntry2();

            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 id
                    else if (ParserUtils.IsAtFhirElement(reader, "id"))
                    {
                        result.Id = IdentifierParser.ParseIdentifier(reader, errors);
                    }

                    // Parse element information
                    else if (ParserUtils.IsAtFhirElement(reader, "information"))
                    {
                        result.Information = DocumentInformationParser.ParseDocumentInformation(reader, errors);
                    }

                    // Parse element format
                    else if (ParserUtils.IsAtFhirElement(reader, "format"))
                    {
                        result.Format = CodingParser.ParseCoding(reader, errors);
                    }

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

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

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

                        reader.LeaveArray();
                    }

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

                    // Parse element content
                    else if (ParserUtils.IsAtFhirElement(reader, "content"))
                    {
                        result.Content = AttachmentParser.ParseAttachment(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);
        }
Esempio n. 29
0
        /// <summary>
        /// Parse Test
        /// </summary>
        public static Hl7.Fhir.Model.Test ParseTest(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Test existingInstance = null)
        {
            Hl7.Fhir.Model.Test result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Test();
            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 stringErr
                    else if (ParserUtils.IsAtFhirElement(reader, "stringErr"))
                    {
                        result.StringErr = new List <Hl7.Fhir.Model.FhirString>();
                        reader.EnterArray();

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

                        reader.LeaveArray();
                    }

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

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

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "booleanErr"))
                        {
                            result.BooleanErr.Add(FhirBooleanParser.ParseFhirBoolean(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "booleanCorr"))
                        {
                            result.BooleanCorr.Add(FhirBooleanParser.ParseFhirBoolean(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "integerErr"))
                        {
                            result.IntegerErr.Add(IntegerParser.ParseInteger(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "integerCorr"))
                        {
                            result.IntegerCorr.Add(IntegerParser.ParseInteger(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "decimalErr"))
                        {
                            result.DecimalErr.Add(FhirDecimalParser.ParseFhirDecimal(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "decimalCorr"))
                        {
                            result.DecimalCorr.Add(FhirDecimalParser.ParseFhirDecimal(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "b64Err"))
                        {
                            result.B64Err.Add(Base64BinaryParser.ParseBase64Binary(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "b64Corr"))
                        {
                            result.B64Corr.Add(Base64BinaryParser.ParseBase64Binary(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "instantErr"))
                        {
                            result.InstantErr.Add(InstantParser.ParseInstant(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "instantCorr"))
                        {
                            result.InstantCorr.Add(InstantParser.ParseInstant(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "uriErr"))
                        {
                            result.UriErr.Add(FhirUriParser.ParseFhirUri(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

                        while (ParserUtils.IsAtArrayElement(reader, "uriCorr"))
                        {
                            result.UriCorr.Add(FhirUriParser.ParseFhirUri(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element idrefSingle
                    else if (ParserUtils.IsAtFhirElement(reader, "idrefSingle"))
                    {
                        result.IdrefSingle = IdRefParser.ParseIdRef(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 ValueSet
        /// </summary>
        public static Hl7.Fhir.Model.ValueSet ParseValueSet(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.ValueSet existingInstance = null)
        {
            Hl7.Fhir.Model.ValueSet result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.ValueSet();
            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.IdentifierElement = FhirStringParser.ParseFhirString(reader, errors);
                }

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

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

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

                // 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 description
                else if (atName == "description")
                {
                    result.DescriptionElement = FhirStringParser.ParseFhirString(reader, errors);
                }

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

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

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

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

                // Parse element define
                else if (atName == "define")
                {
                    result.Define = ValueSetParser.ParseValueSetDefineComponent(reader, errors);
                }

                // Parse element compose
                else if (atName == "compose")
                {
                    result.Compose = ValueSetParser.ParseValueSetComposeComponent(reader, errors);
                }

                // Parse element expansion
                else if (atName == "expansion")
                {
                    result.Expansion = ValueSetParser.ParseValueSetExpansionComponent(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);
        }