Exemple #1
0
        internal static object GetFixedValue(Relationship relationship, VersionNumber version, bool isR2, Hl7Errors errors, string
                                             propertyPath)
        {
            string fixedValue = relationship.FixedValue;

            if (StringUtils.Equals("BL", relationship.Type))
            {
                return(true.ToString().EqualsIgnoreCase(fixedValue));
            }
            else
            {
                if (StringUtils.Equals("INT.POS", relationship.Type))
                {
                    return(System.Convert.ToInt32(fixedValue));
                }
                else
                {
                    if (StringUtils.Equals("ST", relationship.Type))
                    {
                        return(fixedValue);
                    }
                    else
                    {
                        if (relationship.CodedType)
                        {
                            Type codeType = DomainTypeHelper.GetReturnType(relationship, version, CodeTypeRegistry.GetInstance());
                            if (codeType == null)
                            {
                                codeType = typeof(Code);
                            }
                            Code code = CodeResolverRegistry.Lookup(codeType, fixedValue);
                            if (code == null)
                            {
                                string message = System.String.Format("Fixed code lookup could not find match for {0}.{1}", relationship.DomainType, fixedValue
                                                                      );
                                errors.AddHl7Error(new Hl7Error(Hl7ErrorCode.VALUE_NOT_IN_CODE_SYSTEM, ErrorLevel.WARNING, message, propertyPath));
                            }
                            //Fixup for .NET
                            if (isR2)
                            {
                                return(code == null ? null : new CodedTypeR2 <Code>(code));
                            }
                            else
                            {
                                return(code);
                            }
                        }
                        else
                        {
                            throw new MarshallingException("Cannot handle a fixed relationship of type: " + relationship.Type);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void ValidateCodeExists(Code value, string domainType, VersionNumber version, bool isCda, string propertyPath, Hl7Errors
                                        errors)
        {
            Type returnType = null;

            if (StringUtils.IsNotBlank(domainType))
            {
                returnType = (Type)DomainTypeHelper.GetReturnType(domainType, version, CodeTypeRegistry.GetInstance());
            }
            if (returnType == null)
            {
                // for CDA usage, domainType not always supplied
                if (!isCda)
                {
                    errors.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Could not locate a registered domain type to match \"" + domainType
                                                    + "\"", propertyPath));
                }
            }
            else
            {
                if (GetCode(returnType, value.CodeValue, value.CodeSystem) == null)
                {
                    errors.AddHl7Error(CreateCodeValueNotFoundError(value, returnType, propertyPath));
                }
            }
        }
Exemple #3
0
        private object ResolveCodeValue(Relationship relationship, string attributeValue, VersionNumber version, bool isR2)
        {
            Type   returnType = (Type)DomainTypeHelper.GetReturnType(relationship, version, CodeTypeRegistry.GetInstance());
            Code   codeLookup = CodeResolverRegistry.Lookup(returnType, attributeValue);
            object result     = codeLookup;

            if (isR2)
            {
                result = CodedTypeR2Helper.ConvertCodedTypeR2(new CodedTypeR2 <Code>(codeLookup), returnType);
            }
            return(result);
        }
Exemple #4
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        private void WriteAttribute(BeanWrapper bean, Hl7Source source, IList <XmlNode> nodes, Relationship relationship, string traversalName
                                    )
        {
            if (relationship.Structural)
            {
                source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "Data found for relationship as an element but should have been an attribute. "
                                                            + (nodes.IsEmpty() ? ("(" + relationship.Name + ")") : XmlDescriber.DescribePath(nodes[0])), CollUtils.IsEmpty(nodes) ?
                                                            null : (XmlElement)nodes[0]));
            }
            string        type   = DetermineType(nodes, relationship, source, source.GetResult());
            ElementParser parser = (source.IsR2() ? ParserR2Registry.GetInstance().Get(type) : ParserRegistry.GetInstance().Get(type)
                                    );

            if (parser != null)
            {
                try
                {
                    ConstrainedDatatype constraints = source.GetService().GetConstraints(source.GetVersion(), relationship.ConstrainedType);
                    ParseContextImpl    context     = new ParseContextImpl(relationship, constraints, source.GetVersion(), source.GetDateTimeZone(),
                                                                           source.GetDateTimeTimeZone(), CodeTypeRegistry.GetInstance(), source.IsCda());
                    BareANY @object = parser.Parse(context, nodes, source.GetResult());
                    ChangeDatatypeIfNecessary(type, relationship, @object);
                    if (relationship.HasFixedValue())
                    {
                        ValidateNonstructuralFixedValue(relationship, @object, source, nodes);
                    }
                    else
                    {
                        // fixed means nothing to write to bean
                        bean.Write(relationship, @object);
                    }
                }
                catch (InvalidCastException e)
                {
                    source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "Can't parse relationship name=" + relationship.
                                                                Name + ", traversalName=" + traversalName + " [" + e.Message + "]", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[
                                                                    0]));
                }
            }
            else
            {
                source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "No parser for type \"" + type + "\". " + (nodes
                                                                                                                                    .IsEmpty() ? ("(" + relationship.Name + ")") : XmlDescriber.DescribePath(nodes[0])), CollUtils.IsEmpty(nodes) ? null : (
                                                                XmlElement)nodes[0]));
            }
        }
Exemple #5
0
 public Type GetTypeAsClass(String version)
 {
     return(DomainTypeHelper.GetReturnType(this.type, version, CodeTypeRegistry.GetInstance()));
 }