Beispiel #1
0
 /// <summary>Checks if the supplied VersionNumber is based on a particular HL7v3 release.</summary>
 /// <remarks>
 /// Checks if the supplied VersionNumber is based on a particular HL7v3 release.
 /// This now takes in the specific datatype for which this check is being performed. If the datatype
 /// registry contains this datatype then its registered version is returned, otherwise the base version
 /// is returned.
 /// </remarks>
 /// <param name="version"></param>
 /// <param name="versionToCheck"></param>
 /// <returns>whether the version supplied is a match for the given HL7v3 release</returns>
 public static bool IsVersion(Typed datatype, VersionNumber version, Hl7BaseVersion versionToCheck)
 {
     if (versionToCheck == null || version == null)
     {
         return(false);
     }
     return(version.GetBaseVersion(datatype) == versionToCheck);
 }
Beispiel #2
0
        public virtual bool IsAllowableUse(string dataType, Ca.Infoway.Messagebuilder.Domainvalue.TelecommunicationAddressUse telecomAddressUse
                                           , VersionNumber version)
        {
            Hl7BaseVersion baseVersion = version.GetBaseVersion();

            return(!StandardDataType.TEL_URI.Type.Equals(dataType) && telecomAddressUse != null && telecomAddressUse.CodeValue != null &&
                   ALLOWABLE_TELECOM_USES.Contains(telecomAddressUse.CodeValue != null ? telecomAddressUse.CodeValue.ToUpper() : null) &&
                   !(StandardDataType.TEL_EMAIL.Type.Equals(dataType) && IsPgConfDir(telecomAddressUse)) && !(IsMr2007(baseVersion) && IsConf
                                                                                                                  (telecomAddressUse)) && !(IsCeRxOrNewfoundland(version) && IsConfOrDir(telecomAddressUse)));
        }
Beispiel #3
0
        private void Validate(FormatContext context, BareANY dataType, EncapsulatedData encapsulatedData)
        {
            string         type = context.Type;
            string         specializationType = dataType.DataType == null ? null : dataType.DataType.Type;
            Hl7BaseVersion baseVersion        = context.GetVersion().GetBaseVersion();
            Hl7Errors      errors             = context.GetModelToXmlResult();

            this.edValidationUtils.DoValidate(encapsulatedData, specializationType, baseVersion, type, context.GetPropertyPath(), errors
                                              );
        }
Beispiel #4
0
        public virtual bool IsAllowableUse(string dataType, Ca.Infoway.Messagebuilder.Domainvalue.Basic.EntityNameUse personNameUse
                                           , Hl7BaseVersion baseVersion)
        {
            ICollection <string> allowableUses = ALLOWABLE_NAME_USES_BY_VERSION.SafeGet(baseVersion);

            if (allowableUses == null)
            {
                allowableUses = ALLOWABLE_NAME_USES;
            }
            return(allowableUses.Contains(personNameUse.CodeValue));
        }
Beispiel #5
0
        private string GetUseAttribute(string dataType, PostalAddress value, Hl7BaseVersion baseVersion)
        {
            string uses = string.Empty;

            foreach (Ca.Infoway.Messagebuilder.Domainvalue.PostalAddressUse postalAddressUse in value.Uses)
            {
                // for R2, all PostalAddressUses are allowed according to the schema
                uses += uses.Length == 0 ? string.Empty : " ";
                uses += postalAddressUse.CodeValue;
            }
            return(uses);
        }
Beispiel #6
0
        private void ValidateTelecomAddressValue(TelecommunicationAddress telecomAddress, string type, VersionNumber version, XmlElement
                                                 element, string propertyPath, Hl7Errors errors)
        {
            Hl7BaseVersion baseVersion             = version.GetBaseVersion();
            string         address                 = telecomAddress.Address;
            int            schemePlusAddressLength = telecomAddress.ToString().Length;

            if (StringUtils.IsBlank(address))
            {
                CreateError("TelecomAddress must have a value for the actual address", element, propertyPath, errors);
            }
            else
            {
                if (StandardDataType.TEL_EMAIL.Type.Equals(type) && schemePlusAddressLength > MAX_VALUE_LENGTH_EMAIL)
                {
                    CreateMaxLengthError(schemePlusAddressLength, MAX_VALUE_LENGTH_EMAIL, type, baseVersion, element, propertyPath, errors);
                }
                else
                {
                    if (StandardDataType.TEL_URI.Type.Equals(type) && schemePlusAddressLength > MAX_VALUE_LENGTH_URI)
                    {
                        CreateMaxLengthError(schemePlusAddressLength, MAX_VALUE_LENGTH_URI, type, baseVersion, element, propertyPath, errors);
                    }
                    else
                    {
                        if (StandardDataType.TEL_PHONE.Type.Equals(type))
                        {
                            if (IsMr2007(baseVersion) || IsCeRxOrNewfoundland(version))
                            {
                                if (schemePlusAddressLength > MAX_VALUE_LENGTH_PHONE_MR2007_CERX)
                                {
                                    CreateMaxLengthError(schemePlusAddressLength, MAX_VALUE_LENGTH_PHONE_MR2007_CERX, type, baseVersion, element, propertyPath
                                                         , errors);
                                }
                            }
                            else
                            {
                                if (schemePlusAddressLength > MAX_VALUE_LENGTH_PHONE_MR2009)
                                {
                                    CreateMaxLengthError(schemePlusAddressLength, MAX_VALUE_LENGTH_PHONE_MR2009, type, baseVersion, element, propertyPath, errors
                                                         );
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        private void ValidatePersonNameUses(PersonName personName, string type, Hl7BaseVersion baseVersion, XmlElement element, Hl7Errors
                                            errors, string propertyPath)
        {
            bool isSearch = StandardDataType.PN_SEARCH.Type.Equals(type);
            int  numUses  = personName.Uses.Count;

            // confirmed with CHI that multiple uses are allowed (specs don't indicate either way)
            if (numUses == 0 && !isSearch)
            {
                CreateError("PersonName 'use' property is mandatory.", element, propertyPath, errors);
            }
            foreach (Ca.Infoway.Messagebuilder.Domainvalue.Basic.EntityNameUse personNameUse in personName.Uses)
            {
                if (!IsAllowableUse(type, personNameUse, baseVersion))
                {
                    CreateError("PersonNameUse is not valid: " + (personNameUse == null ? "null" : personNameUse.CodeValue), element, propertyPath
                                , errors);
                }
            }
        }
Beispiel #8
0
        protected sealed override string FormatNonNullValue(FormatContext context, PostalAddress postalAddress, int indentLevel)
        {
            Hl7BaseVersion baseVersion = context.GetVersion().GetBaseVersion();
            string         dataType    = context.Type;

            AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.ValidatePostalAddress(postalAddress, dataType, context.GetVersion(), null
                                                                                  , context.GetPropertyPath(), context.GetModelToXmlResult());
            PostalAddress basicAddress = new PostalAddress();
            StringBuilder builder      = new StringBuilder();

            // remove any non-basic address parts
            foreach (PostalAddressPart part in EmptyIterable <object> .NullSafeIterable(postalAddress.Parts))
            {
                if (part.Type == PostalAddressPartType.CITY || part.Type == PostalAddressPartType.STATE || part.Type == PostalAddressPartType
                    .COUNTRY || part.Type == PostalAddressPartType.POSTAL_CODE || part.Type == PostalAddressPartType.DELIMITER)
                {
                    Flush(builder, basicAddress);
                    basicAddress.AddPostalAddressPart(part);
                }
                else
                {
                    if (StringUtils.IsNotBlank(part.Value))
                    {
                        if (builder.Length > 0)
                        {
                            builder.Append(" ");
                        }
                        builder.Append(part.Value);
                    }
                }
            }
            Flush(builder, basicAddress);
            foreach (Ca.Infoway.Messagebuilder.Domainvalue.PostalAddressUse use in postalAddress.Uses)
            {
                if (AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.IsAllowableUse(dataType, use, baseVersion))
                {
                    basicAddress.AddUse(use);
                }
            }
            return(base.FormatNonNullValue(context, basicAddress, indentLevel));
        }
Beispiel #9
0
 private bool IsMr2007(Hl7BaseVersion baseVersion)
 {
     return(baseVersion == Hl7BaseVersion.MR2007);
 }
Beispiel #10
0
 public virtual void ValidatePersonName(PersonName personName, string type, Hl7BaseVersion baseVersion, XmlElement element
                                        , string propertyPath, Hl7Errors errors)
 {
     ValidatePersonNameUses(personName, type, baseVersion, element, errors, propertyPath);
     ValidatePersonNameParts(personName, type, baseVersion, element, propertyPath, errors);
 }
Beispiel #11
0
        private void ValidateTelecomAddressScheme(TelecommunicationAddress telecomAddress, string type, Hl7BaseVersion baseVersion
                                                  , XmlElement element, string propertyPath, Hl7Errors errors)
        {
            Ca.Infoway.Messagebuilder.Domainvalue.URLScheme urlScheme = telecomAddress.UrlScheme;
            string urlSchemeValue = (urlScheme == null ? null : urlScheme.CodeValue.ToLower());

            if (urlScheme == null)
            {
                CreateError("TelecomAddress must have a valid URL scheme (e.g. 'http://')", element, propertyPath, errors);
            }
            else
            {
                if (StandardDataType.TEL.Type.Equals(type))
                {
                    // any known scheme should be ok here
                    ICollection <ICollection <string> > values = ALLOWABLE_SCHEMES_BY_TYPE.Values;
                    foreach (ICollection <string> set in values)
                    {
                        if (set.Contains(urlSchemeValue))
                        {
                            return;
                        }
                    }
                    // we're good here
                    CreateError("TelecomAddressScheme " + urlScheme.CodeValue + " is not valid for " + type, element, propertyPath, errors);
                }
                else
                {
                    ICollection <string> allowableSchemes = ALLOWABLE_SCHEMES_BY_TYPE.SafeGet(type);
                    if (allowableSchemes == null || !allowableSchemes.Contains(urlSchemeValue))
                    {
                        CreateError("TelecomAddressScheme " + urlScheme.CodeValue + " is not valid for " + type, element, propertyPath, errors);
                    }
                }
            }
        }
Beispiel #12
0
 private void CreateMaxLengthError(int addressLength, int maxLength, string type, Hl7BaseVersion baseVersion, XmlElement element
                                   , string propertyPath, Hl7Errors errors)
 {
     CreateError(type + " value (scheme + address) limited to a length of " + maxLength + " for " + baseVersion + " (length was "
                 + addressLength + ")", element, propertyPath, errors);
 }
Beispiel #13
0
        private void ValidatePersonNameParts(PersonName personName, string type, Hl7BaseVersion baseVersion, XmlElement element,
                                             string propertyPath, Hl7Errors errors)
        {
            bool isBasic         = StandardDataType.PN_BASIC.Type.Equals(type);
            bool isSimple        = StandardDataType.PN_SIMPLE.Type.Equals(type);
            bool isFull          = StandardDataType.PN_FULL.Type.Equals(type);
            bool isSearch        = StandardDataType.PN_SEARCH.Type.Equals(type);
            int  countBlankParts = 0;
            bool isCeRx          = IsCeRx(baseVersion);
            int  numParts        = personName.Parts.Count;

            if (numParts > MAX_PARTS)
            {
                CreateError("A maximum of " + MAX_PARTS + " name parts are allowed. Found: " + numParts, element, propertyPath, errors);
            }
            foreach (EntityNamePart personNamePart in personName.Parts)
            {
                int partLength = StringUtils.Length(personNamePart.Value);
                if ((isCeRx && partLength > MAX_PART_LENGTH_CERX) || partLength > MAX_PART_LENGTH)
                {
                    CreateError("Name part types have a maximum allowed length of " + (isCeRx ? MAX_PART_LENGTH_CERX : MAX_PART_LENGTH) + " (length found: "
                                + partLength + ")", element, propertyPath, errors);
                }
                // error if part type not allowed
                NamePartType partType = personNamePart.Type;
                if (partType == null)
                {
                    countBlankParts++;
                    // no part type : only allowed for SIMPLE or, if CeRx, BASIC (max 1 in both cases)
                    if (!isSimple && !(isBasic && isCeRx))
                    {
                        CreateError("Names without a part type are not allowed", element, propertyPath, errors);
                    }
                }
                else
                {
                    if (!ALLOWABLE_NAME_PARTS.Contains(partType.Value))
                    {
                        CreateError("Part type " + partType.Value + " is not allowed for " + type, element, propertyPath, errors);
                    }
                }
                EntityNamePartQualifier qualifier = personNamePart.Qualifier;
                if (qualifier != null)
                {
                    if (isCeRx || (!IsMr2007(baseVersion) && isBasic))
                    {
                        if (!"IN".Equals(qualifier.CodeValue))
                        {
                            CreateError("Qualifier '" + qualifier.CodeValue + "' not valid. Only 'IN' is allowed.", element, propertyPath, errors);
                        }
                    }
                    else
                    {
                        if (!ALLOWABLE_NAME_PART_QUALIFIERS.Contains(qualifier.CodeValue))
                        {
                            CreateError("Qualifier '" + qualifier.CodeValue + "' not valid.", element, propertyPath, errors);
                        }
                    }
                }
            }
            if (isSimple && (countBlankParts > 1 || numParts > 1 || (numParts > 0 && countBlankParts == 0)))
            {
                CreateError("For PN.SIMPLE, only one simple name (a name without a part type) is allowed, and no other name parts are allowed."
                            , element, propertyPath, errors);
            }
            if ((isBasic && isCeRx) && ((countBlankParts > 1) || (countBlankParts == 1 && numParts > 1)))
            {
                CreateError("For CeRx PN.BASIC a name can be provided without a part type, but only a single simple name (i.e. a name without a part type) is allowed in this case. Multiple name parts can be provided, but then all name parts must have part types."
                            , element, propertyPath, errors);
            }
            // confirmed with CHI that simple and basic types do not have to provide any name parts
            if (numParts == 0 && (isFull || isSearch))
            {
                CreateError("At least one name part must be specified.", element, propertyPath, errors);
            }
        }
Beispiel #14
0
 // error if CONF/DIR and CeRx
 private bool IsCeRx(Hl7BaseVersion baseVersion)
 {
     return(baseVersion == Hl7BaseVersion.CERX);
 }
Beispiel #15
0
        public virtual void ValidateCodedType(CD codeWrapper, string codeAsString, bool isCwe, bool isCne, bool isTranslation, bool
                                              isFixed, string type, VersionNumber version, XmlElement element, string propertyPath, Hl7Errors errors)
        {
            Hl7BaseVersion baseVersion = version == null ? Hl7BaseVersion.MR2009 : version.GetBaseVersion();
            // validations use codeAsString instead of codeWrapper.getValue().getCodeValue() in case the code specified wasn't found by a lookup
            //    - this ensures we validate exactly what was passed in, and redundant errors aren't recorded (in most cases, at least)
            Code       code            = codeWrapper.Value;
            string     codeSystem      = (code == null ? null : code.CodeSystem);
            IList <CD> translations    = codeWrapper.Translations;
            bool       hasCode         = (codeAsString != null);
            bool       hasNonBlankCode = (StringUtils.IsNotBlank(codeAsString));
            bool       hasNullFlavor   = codeWrapper.NullFlavor != null;

            if (StandardDataType.CS.Type.Equals(type))
            {
                ValidateCs(codeWrapper, codeAsString, translations, baseVersion, element, propertyPath, errors);
            }
            else
            {
                // CD/CE/CV
                ValidateCodeLength(codeAsString, baseVersion, element, propertyPath, errors, isTranslation);
                ValidateValueLength("codeSystem", code == null ? null : codeSystem, MAX_CODE_SYSTEM_LENGTH, element, propertyPath, errors
                                    , isTranslation);
                ValidateValueLength("originalText", codeWrapper.OriginalText, MAX_ORIGINAL_TEXT_LENGTH, element, propertyPath, errors, isTranslation
                                    );
                if (hasNullFlavor && hasCode)
                {
                    CreateError("Code cannot be provided along with a nullFlavor.", element, propertyPath, errors, isTranslation);
                }
                if (!isTranslation)
                {
                    // displayName is only allowed for CD.LAB, and for CV (but only if BC); in both of these cases, this is disallowed if nullFlavor
                    if (IsCdLab(type) || (IsBC(version) && IsCv(type)))
                    {
                        if (hasNullFlavor)
                        {
                            ValidateUnallowedValue(StandardDataType.GetByTypeName(type), "displayName", codeWrapper.DisplayName, element, propertyPath
                                                   , errors, isTranslation, "when a nullFlavor");
                        }
                    }
                    else
                    {
                        ValidateUnallowedValue(StandardDataType.GetByTypeName(type), "displayName", codeWrapper.DisplayName, element, propertyPath
                                               , errors, isTranslation, null);
                    }
                }
                if (!isTranslation)
                {
                    ValidateTranslations(translations, type, isCwe, isCne, hasNullFlavor, version, element, propertyPath, errors);
                }
                // codes can be one of CWE or CNE (unsure if they can be *neither*)
                // RM19852 - special validation exception for codes that are fixed
                if (isFixed)
                {
                    // only validate that a code has been provided
                    if (!hasNonBlankCode)
                    {
                        CreateError("Code property must be provided.", element, propertyPath, errors, isTranslation);
                    }
                }
                else
                {
                    if (isCwe && !hasNullFlavor)
                    {
                        // cwe = 1 of code/originalText must be non-null; code present = codeSystem mandatory
                        if (!hasNonBlankCode && StringUtils.IsBlank(codeWrapper.OriginalText))
                        {
                            CreateError("For codes with codingStrength of CWE, one of code or originalText must be provided.", element, propertyPath,
                                        errors, isTranslation);
                        }
                        if (hasCode && StringUtils.IsBlank(codeSystem))
                        {
                            CreateError("For codes with codingStrength of CWE, the codeSystem property must be provided when the code property is included."
                                        , element, propertyPath, errors, isTranslation);
                        }
                    }
                    else
                    {
                        if (isCne)
                        {
                            // cne = code and codeSystem mandatory if non-null; if NF=OTH then originalText mandatory and no other properties allowed
                            if (hasNullFlavor)
                            {
                                if (Ca.Infoway.Messagebuilder.Domainvalue.Nullflavor.NullFlavor.OTHER.CodeValue.Equals(codeWrapper.NullFlavor.CodeValue))
                                {
                                    if (StringUtils.IsBlank(codeWrapper.OriginalText))
                                    {
                                        CreateError("For codes with codingStrength of CNE, originalText is mandatory when NullFlavor is 'OTH'.", element, propertyPath
                                                    , errors, isTranslation);
                                    }
                                    if (HasAnyPropertiesProvided(codeWrapper, codeAsString))
                                    {
                                        CreateError("For codes with codingStrength of CNE, originalText is the only property allowed when NullFlavor is 'OTH'.",
                                                    element, propertyPath, errors, isTranslation);
                                    }
                                }
                            }
                            else
                            {
                                if (!hasNonBlankCode || StringUtils.IsBlank(codeSystem))
                                {
                                    CreateError("For codes with codingStrength of CNE, code and codeSystem properties must be provided.", element, propertyPath
                                                , errors, isTranslation);
                                }
                            }
                        }
                        else
                        {
                            // not entirely clear on what should be validated here; code is mandatory, but is code system as well?
                            if (!hasNullFlavor || isTranslation)
                            {
                                if (!hasNonBlankCode || StringUtils.IsBlank(codeSystem))
                                {
                                    CreateError("Code and codeSystem properties must be provided.", element, propertyPath, errors, isTranslation);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #16
0
        private IDictionary <string, string> GetUseAttributeMap(string dataType, PostalAddress value, Hl7BaseVersion baseVersion)
        {
            string uses = string.Empty;

            foreach (Ca.Infoway.Messagebuilder.Domainvalue.PostalAddressUse postalAddressUse in value.Uses)
            {
                if (AD_VALIDATION_UTILS.IsAllowableUse(dataType, postalAddressUse, baseVersion))
                {
                    uses += uses.Length == 0 ? string.Empty : " ";
                    uses += postalAddressUse.CodeValue;
                }
            }
            IDictionary <string, string> result = new Dictionary <string, string>();

            if (uses.Length > 0)
            {
                result["use"] = uses.Trim();
            }
            return(result);
        }
Beispiel #17
0
 /// <summary>Register a specific datatype against a particular HL7v3 release (for validation and processing).</summary>
 /// <remarks>Register a specific datatype against a particular HL7v3 release (for validation and processing).</remarks>
 /// <param name="datatype"></param>
 /// <param name="hl7BaseVersion"></param>
 public virtual void RegisterHl7ReleaseByDatatype(string datatype, Hl7BaseVersion hl7BaseVersion)
 {
     this.hl7ReleaseByDatatypeMap[datatype] = hl7BaseVersion;
 }
Beispiel #18
0
        private void ValidateCs(CD codeWrapper, string codeAsString, IList <CD> translations, Hl7BaseVersion baseVersion, XmlElement
                                element, string propertyPath, Hl7Errors errors)
        {
            bool hasCode         = (codeAsString != null);
            bool hasNonBlankCode = (StringUtils.IsNotBlank(codeAsString));
            bool hasNullFlavor   = codeWrapper.NullFlavor != null;

            // code mandatory, max length 200 (mr2009)/20 (mr2007 and cerx)
            if (!hasNullFlavor && !hasNonBlankCode)
            {
                CreateError("Code is mandatory for CS types.", element, propertyPath, errors, false);
            }
            else
            {
                if (hasNullFlavor && hasCode)
                {
                    CreateError("Code cannot be provided along with a nullFlavor.", element, propertyPath, errors, false);
                }
            }
            ValidateCodeLength(codeAsString, baseVersion, element, propertyPath, errors, false);
            // skip validating codeSystem (codes can be created with a codeSystem even if one wasn't provided, unfortunately)
            // validateUnallowedValue("codeSystem", code == null ? null : code.getCodeSystem(), element, errors);
            ValidateUnallowedValue(StandardDataType.CS, "originalText", codeWrapper.OriginalText, element, propertyPath, errors, false
                                   , null);
            ValidateUnallowedValue(StandardDataType.CS, "displayName", codeWrapper.DisplayName, element, propertyPath, errors, false,
                                   null);
            ValidateUnallowedValue(StandardDataType.CS, "translation", translations.IsEmpty() ? null : string.Empty, element, propertyPath
                                   , errors, false, null);
        }
Beispiel #19
0
 public virtual void DoValidate(string specializationType, Compression compression, bool hasCompression, x_DocumentMediaType
                                mediaType, string language, string representation, bool hasReference, bool hasContent, int contentSize, Hl7BaseVersion
                                baseVersion, string type, XmlElement element, string propertyPath, Hl7Errors errors)
 {
     // specializationType - must be provided for ED.DOCORREF *except* for CeRx; must be ED.DOC or ED.DOCREF
     if (StandardDataType.ED_DOC_OR_REF.Type.Equals(type) && !Hl7BaseVersion.CERX.Equals(baseVersion))
     {
         if (StringUtils.IsBlank(specializationType) || StandardDataType.ED.Type.Equals(specializationType))
         {
             // must specify
             type = (!hasContent ? StandardDataType.ED_DOC_REF.Type : StandardDataType.ED_DOC.Type);
             CreateError("Must specify specializationType for ED.DOC_OR_REF types. Value will be treated as " + type + ".", element, propertyPath
                         , errors);
         }
         else
         {
             if (!(StandardDataType.ED_DOC.Type.Equals(specializationType) || StandardDataType.ED_DOC_REF.Type.Equals(specializationType
                                                                                                                      )))
             {
                 // must be doc or docref; default to something suitable
                 type = (!hasContent ? StandardDataType.ED_DOC_REF.Type : StandardDataType.ED_DOC.Type);
                 CreateError("Invalid specializationType: " + specializationType + ". The specializationType must be ED.DOC or ED.DOCREF for ED.DOC_OR_REF types. Value will be treated as "
                             + type + ".", element, propertyPath, errors);
             }
             else
             {
                 type = specializationType;
             }
         }
     }
     // compression - required, must be DF or GZ
     //             - only GZ for CeRx (ED.DOCORREF), and only allowed if content present
     //             - not permitted for ED.REF
     if (hasCompression)
     {
         if (StandardDataType.ED_REF.Type.Equals(type))
         {
             // not allowed
             CreateError("Compression not allowed for ED.REF types.", element, propertyPath, errors);
         }
         else
         {
             if (Hl7BaseVersion.CERX.Equals(baseVersion) && (compression == null || !Compression.GZIP.CompressionType.Equals(compression
                                                                                                                             .CompressionType)))
             {
                 // only GZ allowed in this case
                 CreateError("Only GZ compression allowed for CeRx ED.DOCORREF type.", element, propertyPath, errors);
             }
             else
             {
                 if (compression == null || (!Compression.GZIP.CompressionType.Equals(compression.CompressionType) && !Compression.DEFLATE
                                             .CompressionType.Equals(compression.CompressionType)))
                 {
                     // only DF or GZ
                     CreateError("Compression must be DF or GZ.", element, propertyPath, errors);
                 }
             }
         }
     }
     // mediatype - mandatory; value from x_DocumentMediaType
     //           - ED.DOC/ED.DOCREF/MR2007, ED.DOCORREF/ED.REF/CeRx: restricted to "text/plain", "text/html", "text/xml", "application/pdf"
     if (mediaType == null)
     {
         // must be provided, and must be acceptable value
         CreateError("MediaType must be provided and must be a value from x_DocumentMediaType.", element, propertyPath, errors);
     }
     // language - required, 2-2
     //          - "eng" or "fre" (CeRx)
     if (StringUtils.IsNotBlank(language))
     {
         if (Hl7BaseVersion.CERX.Equals(baseVersion))
         {
             if (!CERX_ENGLISH.EqualsIgnoreCase(language) && !CERX_FRENCH.EqualsIgnoreCase(language))
             {
                 // incorrect language for CeRx
                 CreateError("The language attribute must be one of 'eng' or 'fre'.", element, propertyPath, errors);
             }
         }
         else
         {
             if (language.Length != 5 || (language[2] != '-'))
             {
                 // needs to be a language code (yes, the above check isn't perfect, but it should be fine for most cases)
                 CreateError("The language attribute must be a 2-letter language code, followed by a hyphen, followed by a 2-letter country code."
                             , element, propertyPath, errors);
             }
         }
     }
     // representation - TXT or B64; vague on if this is mandatory or not; not permitted for CeRx
     if (StringUtils.IsNotBlank(representation))
     {
         if (!REPRESENTATION_TXT.EqualsIgnoreCase(representation) && !REPRESENTATION_B64.EqualsIgnoreCase(representation))
         {
             // error
             CreateError("The representation attribute must be one of 'TXT' or 'B64'.", element, propertyPath, errors);
         }
     }
     // reference - required; must be TEL.URI (mandatory for ED.DOCREF)
     //           - CeRx: only allowed (and mandatory?) if content not present; must be FTP, HTTP, HTTPS  (ED.REF, ED.DOCORREF)
     if (!hasReference)
     {
         if (StandardDataType.ED_DOC_REF.Type.Equals(type) || StandardDataType.ED_REF.Type.Equals(type))
         {
             // mandatory case
             CreateError("Reference is mandatory.", element, propertyPath, errors);
         }
     }
     if (element != null && element.HasAttribute(ELEMENT_REFERENCE))
     {
         CreateError("Reference is not allowed as an attribute; it should be in a <reference> element having a value attribute containing the actual reference."
                     , element, propertyPath, errors);
     }
     // content - max 1 MB after compression and base64 encoding; compressed or pdf must be b64-encoded; any checks done on this??
     //         - mandatory for ED.DOC, ED.DOCORREF/CeRx (if no ref provided)
     //         - not permitted for ED.DOCREF/ED.REF
     if (hasContent && contentSize > 0)
     {
         if (StandardDataType.ED_DOC_REF.Type.Equals(type) || StandardDataType.ED_REF.Type.Equals(type))
         {
             // not permitted
             CreateError("Content is not permitted for " + type + ".", element, propertyPath, errors);
         }
         if (contentSize > ONE_MEGABYTE_SIZE)
         {
             // too large
             CreateError("Content must be less than 1 MB.", element, propertyPath, errors);
         }
     }
     else
     {
         if (StandardDataType.ED_DOC.Type.Equals(type))
         {
             // must be provided
             CreateError("Content must be provided for " + type + ".", element, propertyPath, errors);
         }
     }
     if (Hl7BaseVersion.CERX.Equals(baseVersion) && StandardDataType.ED_DOC_OR_REF.Type.Equals(type))
     {
         if (hasReference && hasContent)
         {
             // can't provide both
             CreateError("Cannot provide both content and reference.", element, propertyPath, errors);
         }
         else
         {
             if (!hasReference && !hasContent)
             {
                 // must provide one
                 CreateError("Must provide one and only one of content or reference.", element, propertyPath, errors);
             }
         }
     }
 }
Beispiel #20
0
        // for newer format of "reference" usage
        public virtual void DoValidate(EncapsulatedData ed, string specializationType, Hl7BaseVersion baseVersion, string type, string
                                       propertyPath, Hl7Errors errors)
        {
            Compression compression    = ed.Compression;
            bool        hasCompression = (compression != null);
            int         contentSize    = (ed.HasContent() ? 1 : 0);
            string      representation = (ed.Representation == null ? null : ed.Representation.Name);
            bool        hasReference   = (ed.ReferenceObj != null);

            DoValidate(specializationType, compression, hasCompression, ed.MediaType, ed.Language, representation, hasReference, ed.HasContent
                           (), contentSize, baseVersion, type, null, propertyPath, errors);
        }
Beispiel #21
0
 private MockVersionNumber(string literal, Hl7BaseVersion baseVersion)
 {
     this.literal     = literal;
     this.baseVersion = baseVersion;
 }
Beispiel #22
0
 public virtual bool IsAllowableUse(string dataType, Ca.Infoway.Messagebuilder.Domainvalue.PostalAddressUse use, Hl7BaseVersion
                                    baseVersion)
 {
     return(!StandardDataType.AD_SEARCH.Type.Equals(dataType) && use != null && use.CodeValue != null && ALLOWABLE_ADDRESS_USES
            .Contains(use.CodeValue) && !(IsCeRx(baseVersion) && IsConfOrDir(use)));
 }
Beispiel #23
0
 private SpecificationVersion(string name, string description, Hl7BaseVersion baseVersion) : base(name)
 {
     this.description = description;
     this.baseVersion = baseVersion;
 }
Beispiel #24
0
 private void ValidateCodeLength(string codeAsString, Hl7BaseVersion baseVersion, XmlElement element, string propertyPath,
                                 Hl7Errors errors, bool isTranslation)
 {
     ValidateValueLength("code", codeAsString, IsCeRx(baseVersion) || IsMr2007(baseVersion) ? MAX_CODE_LENGTH_CERX_MR2007 : MAX_CODE_LENGTH
                         , element, propertyPath, errors, isTranslation);
 }