public FormatContextImpl(string newType, bool isSpecializationType, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel newConformanceLevel , Cardinality newCardinality, string elementName, FormatContext context) : this(context.GetModelToXmlResult(), context.GetPropertyPath (), elementName, newType, context.GetDomainType(), newConformanceLevel, newCardinality, isSpecializationType, context.GetVersion (), context.GetDateTimeZone(), context.GetDateTimeTimeZone(), context.GetCodingStrength(), null, context.IsCda()) { }
public override string Format(FormatContext formatContext, BareANY hl7Value, int indentLevel) { if (hl7Value == null) { return(string.Empty); } string specializationType = hl7Value.DataType.Type; StandardDataType specializationTypeAsEnum = StandardDataType.GetByTypeName(specializationType); if (specializationTypeAsEnum != null && StandardDataType.ANY.Equals(specializationTypeAsEnum.RootDataType)) { // specializationType has been determined to be an ANY variant; this (most likely) means specializationType has not been specified, so don't do any special processing return(base.Format(formatContext, hl7Value, indentLevel)); } else { string mappedSpecializationType = this.polymorphismHandler.MapCdaR1Type(hl7Value.DataType, formatContext.IsCda()); PropertyFormatter formatter = FormatterRegistry.GetInstance().Get(mappedSpecializationType); string parentType = formatContext.Type; if (formatter == null || !AnyHelper.IsValidTypeForAny(parentType, specializationType)) { string errorText = "Cannot support properties of type " + specializationType + " for " + parentType + ". Please specify a specializationType applicable for " + parentType + " in the appropriate message bean."; throw new ModelToXmlTransformationException(errorText); } else { // pass processing off to the formatter applicable for the given specializationType StandardDataType type = hl7Value.DataType; return(formatter.Format(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(formatContext.GetModelToXmlResult (), formatContext.GetPropertyPath(), formatContext.GetElementName(), mappedSpecializationType, type.Coded ? "Code" : formatContext .GetDomainType(), formatContext.GetConformanceLevel(), formatContext.GetCardinality(), true, formatContext.GetVersion(), formatContext.GetDateTimeZone(), formatContext.GetDateTimeTimeZone(), null, formatContext.GetConstraints(), formatContext .IsCda()), hl7Value, indentLevel)); } } }
public override string Format(FormatContext context, BareANY hl7Value, int indentLevel) { bool isAny = false; CD cd = null; if (hl7Value is CD) { cd = (CD)hl7Value; } else { isAny = true; // bypass some validations cd = ConvertAnyToCd(hl7Value); } StringBuilder result = new StringBuilder(); if (cd != null) { HandleConstraints(cd.Value, context.GetConstraints(), context.GetPropertyPath(), context.GetModelToXmlResult()); // don't bother validating if we don't have anything to validate if (cd.HasNullFlavor() || HasValue(cd, context)) { Hl7Errors errors = context.GetModelToXmlResult(); VersionNumber version = context.GetVersion(); string type = context.Type; bool isCne = context.GetCodingStrength() == CodingStrength.CNE; bool isCwe = context.GetCodingStrength() == CodingStrength.CWE; // we can't lookup a code supplied in an ANY datatype as we don't know the domain // a "reverse" lookup of domain type by code/codesystem could be possible, but difficult to implement to be 100% correct (MB does not track code systems) if (!isAny) { if (cd.Value != null && cd.Value.CodeValue != null) { ValidateCodeExists(cd.Value, context.GetDomainType(), version, context.IsCda(), context.GetPropertyPath(), errors); } } string codeAsString = (cd.Value != null ? cd.Value.CodeValue : null); CD_VALIDATION_UTILS.ValidateCodedType(cd, codeAsString, isCwe, isCne, false, context.IsFixed(), type, version, null, context .GetPropertyPath(), errors); } IDictionary <string, string> attributes = new Dictionary <string, string>(); Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel(); Cardinality cardinality = context.GetCardinality(); if (cd.HasNullFlavor()) { if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality)) { LogMandatoryError(context); } else { attributes.PutAll(CreateNullFlavorAttributes(hl7Value.NullFlavor)); } } else { if (!HasValue(cd, context)) { if (conformanceLevel == null || IsMandatoryOrPopulated(context)) { if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality)) { LogMandatoryError(context); } else { attributes.PutAll(AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES); } } } } // Codes can have other attributes in map even if has NullFlavor attributes.PutAll(GetAttributeNameValuePairs(context, cd.Value, hl7Value)); bool hasChildContent = HasChildContent(cd, context); if (hasChildContent || (!attributes.IsEmpty() || ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))) { result.Append(CreateElement(context, attributes, indentLevel, !hasChildContent, !hasChildContent)); if (hasChildContent) { CreateChildContent(cd, result); result.Append("</").Append(context.GetElementName()).Append(">"); result.Append(SystemUtils.LINE_SEPARATOR); } } } return(result.ToString()); }
// only checking II constraints for now protected virtual FormatContext CreateSubContext(FormatContext context) { return(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(context.GetModelToXmlResult(), context.GetPropertyPath (), context.GetElementName(), GetSubType(context), context.GetDomainType(), context.GetConformanceLevel(), context.GetCardinality (), context.IsSpecializationType(), context.GetVersion(), context.GetDateTimeZone(), context.GetDateTimeTimeZone(), null , null, context.IsCda())); }