Пример #1
0
        public void ShallRenturnHomeContactPoint()
        {
            var xml =
                @"<telecom value=""tel:+1(555)555-2003"" use=""HP""/>";

            var element = XElement.Parse(xml);
            var result  = new ContactPointParser().FromXml(element);

            result.Should().NotBeNull();
            result.Use.Should().Be(ContactPoint.ContactPointUse.Home);
            result.Value.Should().Be("+1(555)555-2003");
        }
Пример #2
0
        public void NullXmlShallRenturnNull()
        {
            var result = new ContactPointParser().FromXml(null);

            result.Should().BeNull();
        }
Пример #3
0
        public override Organization FromXml(XElement element)
        {
            if (element == null)
            {
                return(null);
            }

            var org = new Organization
            {
                Id   = Guid.NewGuid().ToString(),
                Meta = new Meta
                {
                    Profile = new List <string>
                    {
                        "http://hl7.org/fhir/us/core/StructureDefinition/us-core-organization"
                    }
                },
                Active = true
            };

            foreach (var child in element.Elements())
            {
                if (child.Name.LocalName == "id")
                {
                    var id = new IdentifierParser().FromXml(child, Errors);

                    if (id != null)
                    {
                        org.Identifier.Add(id);
                    }
                }
                else if (child.Name.LocalName == "name")
                {
                    org.Name = child.Value;
                }
                else if (child.Name.LocalName == "telecom")
                {
                    var telecom = new ContactPointParser().FromXml(child, Errors);

                    if (telecom != null)
                    {
                        org.Telecom.Add(telecom);
                    }
                }
                else if (child.Name.LocalName == "addr")
                {
                    var addr = new AddressParser().FromXml(child, Errors);

                    if (addr != null)
                    {
                        org.Address.Add(addr);
                    }
                }
            }

            if (!org.Identifier.Any())
            {
                Errors.Add(ParserError.CreateParseError(element, "does NOT have id element", ParseErrorLevel.Error));
            }

            if (string.IsNullOrEmpty(org.Name))
            {
                Errors.Add(ParserError.CreateParseError(element, "does NOT have name element", ParseErrorLevel.Error));
            }

            if (!org.Telecom.Any())
            {
                Errors.Add(
                    ParserError.CreateParseError(element, "does NOT have telecom element", ParseErrorLevel.Error));
            }

            if (!org.Address.Any())
            {
                Errors.Add(ParserError.CreateParseError(element, "does NOT have addr element", ParseErrorLevel.Error));
            }

            var existingOrg = Bundle?.FirstOrDefault <Organization>(p => p.Identifier.IsExactly(org.Identifier));

            if (existingOrg == null)
            {
                Bundle?.AddResourceEntry(org);
            }
            else
            {
                org = existingOrg;
            }

            return(org);
        }