Exemplo n.º 1
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);
        }
        public static void SerializeTest(Hl7.Fhir.Model.Test value, IFhirWriter writer)
        {
            writer.WriteStartRootObject("Test");
            writer.WriteStartComplexContent();

            // Serialize element extension
            if (value.Extension != null && value.Extension.Count > 0)
            {
                writer.WriteStartArrayElement("extension");
                foreach (var item in value.Extension)
                {
                    writer.WriteStartArrayMember("extension");
                    ExtensionSerializer.SerializeExtension(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element language
            if (value.Language != null)
            {
                writer.WriteStartElement("language");
                CodeSerializer.SerializeCode(value.Language, writer);
                writer.WriteEndElement();
            }

            // Serialize element text
            if (value.Text != null)
            {
                writer.WriteStartElement("text");
                NarrativeSerializer.SerializeNarrative(value.Text, writer);
                writer.WriteEndElement();
            }

            // Serialize element contained
            if (value.Contained != null && value.Contained.Count > 0)
            {
                writer.WriteStartArrayElement("contained");
                foreach (var item in value.Contained)
                {
                    writer.WriteStartArrayMember("contained");
                    FhirSerializer.SerializeResource(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element _id
            if (value.LocalId != null)
            {
                writer.WriteStartElement("_id");
                IdSerializer.SerializeId(value.LocalId, writer);
                writer.WriteEndElement();
            }

            // Serialize element stringErr
            if (value.StringErr != null && value.StringErr.Count > 0)
            {
                writer.WriteStartArrayElement("stringErr");
                foreach (var item in value.StringErr)
                {
                    writer.WriteStartArrayMember("stringErr");
                    FhirStringSerializer.SerializeFhirString(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element stringCorr
            if (value.StringCorr != null && value.StringCorr.Count > 0)
            {
                writer.WriteStartArrayElement("stringCorr");
                foreach (var item in value.StringCorr)
                {
                    writer.WriteStartArrayMember("stringCorr");
                    FhirStringSerializer.SerializeFhirString(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element booleanErr
            if (value.BooleanErr != null && value.BooleanErr.Count > 0)
            {
                writer.WriteStartArrayElement("booleanErr");
                foreach (var item in value.BooleanErr)
                {
                    writer.WriteStartArrayMember("booleanErr");
                    FhirBooleanSerializer.SerializeFhirBoolean(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element booleanCorr
            if (value.BooleanCorr != null && value.BooleanCorr.Count > 0)
            {
                writer.WriteStartArrayElement("booleanCorr");
                foreach (var item in value.BooleanCorr)
                {
                    writer.WriteStartArrayMember("booleanCorr");
                    FhirBooleanSerializer.SerializeFhirBoolean(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element integerErr
            if (value.IntegerErr != null && value.IntegerErr.Count > 0)
            {
                writer.WriteStartArrayElement("integerErr");
                foreach (var item in value.IntegerErr)
                {
                    writer.WriteStartArrayMember("integerErr");
                    IntegerSerializer.SerializeInteger(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element integerCorr
            if (value.IntegerCorr != null && value.IntegerCorr.Count > 0)
            {
                writer.WriteStartArrayElement("integerCorr");
                foreach (var item in value.IntegerCorr)
                {
                    writer.WriteStartArrayMember("integerCorr");
                    IntegerSerializer.SerializeInteger(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element decimalErr
            if (value.DecimalErr != null && value.DecimalErr.Count > 0)
            {
                writer.WriteStartArrayElement("decimalErr");
                foreach (var item in value.DecimalErr)
                {
                    writer.WriteStartArrayMember("decimalErr");
                    FhirDecimalSerializer.SerializeFhirDecimal(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element decimalCorr
            if (value.DecimalCorr != null && value.DecimalCorr.Count > 0)
            {
                writer.WriteStartArrayElement("decimalCorr");
                foreach (var item in value.DecimalCorr)
                {
                    writer.WriteStartArrayMember("decimalCorr");
                    FhirDecimalSerializer.SerializeFhirDecimal(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element b64Err
            if (value.B64Err != null && value.B64Err.Count > 0)
            {
                writer.WriteStartArrayElement("b64Err");
                foreach (var item in value.B64Err)
                {
                    writer.WriteStartArrayMember("b64Err");
                    Base64BinarySerializer.SerializeBase64Binary(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element b64Corr
            if (value.B64Corr != null && value.B64Corr.Count > 0)
            {
                writer.WriteStartArrayElement("b64Corr");
                foreach (var item in value.B64Corr)
                {
                    writer.WriteStartArrayMember("b64Corr");
                    Base64BinarySerializer.SerializeBase64Binary(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element instantErr
            if (value.InstantErr != null && value.InstantErr.Count > 0)
            {
                writer.WriteStartArrayElement("instantErr");
                foreach (var item in value.InstantErr)
                {
                    writer.WriteStartArrayMember("instantErr");
                    InstantSerializer.SerializeInstant(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element instantCorr
            if (value.InstantCorr != null && value.InstantCorr.Count > 0)
            {
                writer.WriteStartArrayElement("instantCorr");
                foreach (var item in value.InstantCorr)
                {
                    writer.WriteStartArrayMember("instantCorr");
                    InstantSerializer.SerializeInstant(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element uriErr
            if (value.UriErr != null && value.UriErr.Count > 0)
            {
                writer.WriteStartArrayElement("uriErr");
                foreach (var item in value.UriErr)
                {
                    writer.WriteStartArrayMember("uriErr");
                    FhirUriSerializer.SerializeFhirUri(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element uriCorr
            if (value.UriCorr != null && value.UriCorr.Count > 0)
            {
                writer.WriteStartArrayElement("uriCorr");
                foreach (var item in value.UriCorr)
                {
                    writer.WriteStartArrayMember("uriCorr");
                    FhirUriSerializer.SerializeFhirUri(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element idrefSingle
            if (value.IdrefSingle != null)
            {
                writer.WriteStartElement("idrefSingle");
                IdRefSerializer.SerializeIdRef(value.IdrefSingle, writer);
                writer.WriteEndElement();
            }


            writer.WriteEndComplexContent();
            writer.WriteEndRootObject();
        }