Beispiel #1
0
        internal void Replace(IfcNamedUnit unit)
        {
            IfcNamedUnit existing = mUnits.OfType <IfcNamedUnit>().Where(x => x.UnitType == unit.UnitType).FirstOrDefault();

            if (existing != null)
            {
                mUnits.Remove(existing);
            }
            Units.Add(unit);
        }
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            EN instance = o as EN;

            // Do a base format
            base.Graph(s, o as ANY, result);

            // Null flavor
            if (instance.NullFlavor != null)
            {
                return;
            }

            // use
            if (instance.Use != null)
            {
                s.WriteAttributeString("use", Util.ToWireFormat(instance.Use));
            }

            // parts
            if (instance.Part != null)
            {
                foreach (ENXP part in instance.Part)
                {
                    EntityNamePartType?pt = part.Type;
                    SET <CS <EntityNamePartQualifier> > qualifiers = new SET <CS <EntityNamePartQualifier> >();
                    if (part.Qualifier != null)
                    {
                        foreach (var qlf in part.Qualifier)
                        {
                            qualifiers.Add(qlf.Clone() as CS <EntityNamePartQualifier>);
                        }
                    }

                    // Title part type?
                    if (pt == EntityNamePartType.Title)
                    {
                        part.Qualifier.Add(new CS <EntityNamePartQualifier>()
                        {
                            Code = CodeValue <EntityNamePartQualifier> .Parse("TITLE")
                        }
                                           );
                        pt = null;
                    }

                    // Possible to match qualifier to a part tpye if none specified!
                    if (!qualifiers.IsEmpty)
                    {
                        CS <EntityNamePartQualifier> pfx = qualifiers.Find(a => a.Code.Equals(EntityNamePartQualifier.Prefix)),
                                                     sfx = qualifiers.Find(a => a.Code.Equals(EntityNamePartQualifier.Suffix));
                        if (pfx != null)
                        {
                            pt = EntityNamePartType.Prefix;
                            qualifiers.Remove(pfx);
                        }
                        else if (sfx != null)
                        {
                            pt = EntityNamePartType.Suffix;
                            qualifiers.Remove(sfx);
                        }
                    }

                    // Part type is not set so do it inline
                    if (pt == null)
                    {
                        if (!qualifiers.IsEmpty)
                        {
                            result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "Part has qualifier but is not being rendered as a type element, qualifier will be dropped", s.ToString(), null));
                        }
                        s.WriteString(part.Value);
                    }
                    else if (mapping.ContainsKey(pt))
                    {
                        var prt = part.Clone() as ENXP;
                        prt.Type      = pt;
                        prt.Qualifier = qualifiers;
                        s.WriteStartElement(mapping[pt], "urn:hl7-org:v3");
                        ENXPFormatter enFormatter = new ENXPFormatter();
                        enFormatter.Graph(s, prt, result);
                        s.WriteEndElement();
                    }
                    else
                    {
                        throw new MessageValidationException(string.Format("Can't represent entity name part '{0}' in datatypes R1 at '{1}'", pt, (s as XmlStateWriter).CurrentPath));
                    }
                }
            }

            // Bug: 2102 - Graph the validTime element. Since the HXIT
            // class in R2 already has validTimeLow and validTimeHigh
            // what we'll do is map these attributes to the validTime element
            if (instance.ValidTimeLow != null || instance.ValidTimeHigh != null)
            {
                IVL <TS> validTime = new IVL <TS>(instance.ValidTimeLow, instance.ValidTimeHigh);
                s.WriteStartElement("validTime", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, validTime);
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement(); // valid time
            }
        }