Beispiel #1
0
        private CD ConvertAnyToCd(BareANY hl7Value)
        {
            ANYMetaData anyCd = (ANYMetaData)hl7Value;
            CD          cd    = new CDImpl();

            if (anyCd != null)
            {
                if (GenericClassUtil.IsInstanceOfANY(hl7Value))
                {
                    object value = GenericClassUtil.GetValueFromANY(hl7Value);
                    if (value is Code)
                    {
                        cd.Value = (Code)value;
                    }
                }
                cd.DataType     = hl7Value.DataType;
                cd.NullFlavor   = hl7Value.NullFlavor;
                cd.DisplayName  = anyCd.DisplayName;
                cd.OriginalText = anyCd.OriginalText;
                cd.Translations.AddAll(anyCd.Translations);
            }
            return(cd);
        }
Beispiel #2
0
 private void ValidateNonstructuralFixedValue(Relationship relationship, BareANY value, Hl7Source source, IList <XmlNode> nodes
                                              )
 {
     if (relationship.HasFixedValue())
     {
         bool valueProvided = (value != null && value.BareValue != null);
         bool valid         = valueProvided || (!ConformanceLevelUtil.IsMandatory(relationship) && !ConformanceLevelUtil.IsPopulated(relationship
                                                                                                                                     ));
         // optional and required fixed values do not have to provide a value, but if they do they must conform to specified value
         if (valueProvided)
         {
             if ("BL".Equals(relationship.Type) && value is BL)
             {
                 string valueAsString = ((BL)value).Value.ToString();
                 valid = relationship.FixedValue.EqualsIgnoreCase(valueAsString);
             }
             else
             {
                 if ("ST".Equals(relationship.Type) && value is ST)
                 {
                     string valueAsString = ((ST)value).Value.ToString();
                     valid = relationship.FixedValue.EqualsIgnoreCase(valueAsString);
                 }
                 else
                 {
                     if ("INT.POS".Equals(relationship.Type) && value is INT)
                     {
                         string valueAsString = ((INT)value).Value.ToString();
                         valid = relationship.FixedValue.EqualsIgnoreCase(valueAsString);
                     }
                     else
                     {
                         if (relationship.CodedType)
                         {
                             if (source.IsR2())
                             {
                                 if (GenericClassUtil.IsInstanceOfANY(value))
                                 {
                                     object value2 = GenericClassUtil.GetValueFromANY(value);
                                     Code   code   = value2 == null ? null : CodedTypeR2Helper.GetCode(value2);
                                     valid = (code != null && code.CodeValue != null && StringUtils.Equals(relationship.FixedValue, code.CodeValue));
                                 }
                             }
                             else
                             {
                                 if (value is CD)
                                 {
                                     Code code = ((CD)value).Value;
                                     valid = (code.CodeValue != null && StringUtils.Equals(relationship.FixedValue, code.CodeValue));
                                 }
                             }
                         }
                         else
                         {
                             source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.SYNTAX_ERROR, "Non-structural fixed-value attribute '" + relationship
                                                                         .Name + "' was of unexpected type '" + relationship.Type + "'", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[0]));
                         }
                     }
                 }
             }
         }
         if (!valid)
         {
             source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.MANDATORY_FIELD_NOT_PROVIDED, "Fixed-value attribute '" + relationship
                                                         .Name + "' must have value '" + relationship.FixedValue + "'", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[0]));
         }
     }
 }
Beispiel #3
0
 public virtual void TestIsInstanceOfANYDifferentObject()
 {
     Assert.IsFalse(GenericClassUtil.IsInstanceOfANY("abcd"));
 }
Beispiel #4
0
 public virtual void TestIsInstanceofANYTrue()
 {
     Assert.IsTrue(GenericClassUtil.IsInstanceOfANY(new CD_R2Impl <Code>()));
 }
Beispiel #5
0
 public virtual void TestIsInstanceOfANYNull()
 {
     Assert.IsFalse(GenericClassUtil.IsInstanceOfANY(null));
 }