protected virtual string FormatAllElements(FormatContext originalContext, FormatContext subContext, ICollection <BareANY> collection, int indentLevel) { StringBuilder builder = new StringBuilder(); ValidateCardinality(originalContext, collection); PropertyFormatter formatter = this.formatterRegistry.Get(subContext.Type); if (collection.IsEmpty()) { builder.Append(formatter.Format(subContext, null, indentLevel)); } else { foreach (BareANY hl7Value in EmptyIterable <object> .NullSafeIterable <BareANY>(collection)) { string type = DetermineActualType(subContext.Type, hl7Value, originalContext.GetModelToXmlResult(), originalContext.GetPropertyPath (), originalContext.IsCda()); if (!StringUtils.Equals(type, subContext.Type)) { subContext = new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(type, true, subContext); formatter = this.formatterRegistry.Get(type); } builder.Append(formatter.Format(subContext, hl7Value, indentLevel)); } } return(builder.ToString()); }
protected override void AddOtherAttributesIfNecessary(PlatformDate v, IDictionary <string, string> attributes, FormatContext context, BareANY bareAny) { base.AddOtherAttributesIfNecessary(v, attributes, context, bareAny); if (context.IsCda()) { SetOperator @operator = ((ANYMetaData)bareAny).Operator; if (@operator != null) { attributes["operator"] = @operator.CodeValue; } } }
private void ValidateRootAndExtensionAsOidOrUuid(string root, string extension, StandardDataType type, VersionNumber version , FormatContext context) { // if root has not been provided don't bother further validating root or extension if (StringUtils.IsNotBlank(root)) { if (!iiValidationUtils.IsUuid(root)) { ValidateRootAsOid(root, version, type, context); if (!context.IsCda()) { ValidateExtensionForOid(extension, type.Name, context); } } else { ValidateRootAsUuid(root, version, type, context); ValidateUnallowedAttribute("extension", extension, type.Name, context); } } }
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 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()); }
private string HandleSpecializationType(BareANY bareAny, FormatContext context, IDictionary <string, string> result) { string typeFromContext = context.Type; string typeFromField = bareAny.DataType == null ? null : bareAny.DataType.Type; if (iiValidationUtils.IsSpecializationTypeRequired(context.GetVersion(), typeFromContext, context.IsCda())) { bool validSpecializationType = IsSpecializationTypeProvided(typeFromContext, typeFromField); if (iiValidationUtils.IsII(typeFromContext)) { validSpecializationType &= IiValidationUtils.concreteIiTypes.Contains(typeFromField); } else { if (iiValidationUtils.IsIiBusAndVer(typeFromContext)) { validSpecializationType &= iiValidationUtils.IsIiBusOrIiVer(typeFromField); } } // only override type if new type is valid if (validSpecializationType) { typeFromContext = typeFromField; AddSpecializationTypeAttributesBasedOnVersion(result, typeFromContext, context.GetVersion()); } else { if (iiValidationUtils.IsIiBusAndVer(typeFromContext)) { AddSpecializationTypeAttributesBasedOnVersion(result, IiValidationUtils.II_BUS, context.GetVersion()); typeFromContext = IiValidationUtils.II_BUS; RecordError(iiValidationUtils.GetInvalidSpecializationTypeForBusAndVerErrorMessage(typeFromField, typeFromContext), context ); } else { RecordError(iiValidationUtils.GetInvalidOrMissingSpecializationTypeErrorMessage(typeFromField), context); } } } else { if (IsSpecializationTypeProvided(typeFromContext, typeFromField)) { RecordError(iiValidationUtils.GetShouldNotProvideSpecializationTypeErrorMessage(typeFromContext), context); } } return(typeFromContext); }
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)); } } }
// 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())); }