Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse VisitHospitalizationComponent
        /// </summary>
        public static Hl7.Fhir.Model.Visit.VisitHospitalizationComponent ParseVisitHospitalizationComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Visit.VisitHospitalizationComponent existingInstance = null)
        {
            Hl7.Fhir.Model.Visit.VisitHospitalizationComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Visit.VisitHospitalizationComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

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

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

                        reader.LeaveArray();
                    }

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

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

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

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

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

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

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

                        while (ParserUtils.IsAtArrayElement(reader, "accomodation"))
                        {
                            result.Accomodation.Add(VisitParser.ParseVisitHospitalizationAccomodationComponent(reader, errors));
                        }

                        reader.LeaveArray();
                    }

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

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

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

                        reader.LeaveArray();
                    }

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

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

                        reader.LeaveArray();
                    }

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

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

                    // Parse element reAdmission
                    else if (atName == "reAdmission")
                    {
                        result.ReAdmission = 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();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }