Exemple #1
0
        public virtual BigDecimal ValidateValue(string value, VersionNumber version, string type, bool hasNullFlavor, XmlElement
                                                element, string propertyPath, Hl7Errors errors)
        {
            int        maxIntDigits            = this.GetMaxIntDigits(version, type);
            int        maxFractionDigits       = this.GetMaxFractionDigits(version, type);
            bool       alreadyWarnedAboutValue = false;
            BigDecimal result = null;

            if (StringUtils.IsBlank(value))
            {
                if (!hasNullFlavor)
                {
                    CreateWarning("No value provided for physical quantity", element, propertyPath, errors);
                }
            }
            else
            {
                if (NumberUtil.IsNumber(value))
                {
                    string integerPart  = value.Contains(".") ? StringUtils.SubstringBefore(value, ".") : value;
                    string decimalPart  = value.Contains(".") ? StringUtils.SubstringAfter(value, ".") : string.Empty;
                    string errorMessage = "PhysicalQuantity for {0}/{1} can contain a maximum of {2} {3} places";
                    if (StringUtils.Length(decimalPart) > maxFractionDigits)
                    {
                        CreateWarning(System.String.Format(errorMessage, version.GetBaseVersion(), type, maxFractionDigits, "decimal"), element,
                                      propertyPath, errors);
                    }
                    if (StringUtils.Length(integerPart) > maxIntDigits)
                    {
                        CreateWarning(System.String.Format(errorMessage, version.GetBaseVersion(), type, maxIntDigits, "integer"), element, propertyPath
                                      , errors);
                    }
                    if (!StringUtils.IsNumeric(integerPart) || !StringUtils.IsNumeric(decimalPart))
                    {
                        alreadyWarnedAboutValue = true;
                        CreateWarning(System.String.Format("value \"{0}\" must contain digits only", value), element, propertyPath, errors);
                    }
                }
                try
                {
                    result = new BigDecimal(value);
                }
                catch (FormatException)
                {
                    if (!alreadyWarnedAboutValue)
                    {
                        CreateWarning(System.String.Format("value \"{0}\" is not a valid decimal value", value), element, propertyPath, errors);
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        private void ValidatePostalAddressUses(PostalAddress postalAddress, string type, VersionNumber version, XmlElement element
                                               , string propertyPath, Hl7Errors errors)
        {
            int  numUses  = postalAddress.Uses.Count;
            bool isSearch = StandardDataType.AD_SEARCH.Type.Equals(type);

            if (isSearch && numUses > 0)
            {
                // error if > 0 and SEARCH
                CreateError("PostalAddressUses are not allowed for AD.SEARCH", element, propertyPath, errors);
            }
            else
            {
                if (numUses > MAX_USES)
                {
                    // error if more than 3 uses
                    CreateError("A maximum of 3 PostalAddressUses are allowed (number found: " + numUses + ")", element, propertyPath, errors
                                );
                }
            }
            if (!isSearch)
            {
                foreach (Ca.Infoway.Messagebuilder.Domainvalue.PostalAddressUse postalAddressUse in postalAddress.Uses)
                {
                    if (!IsAllowableUse(type, postalAddressUse, version.GetBaseVersion()))
                    {
                        CreateError("PostalAddressUse is not valid: " + (postalAddressUse == null ? "null" : postalAddressUse.CodeValue), element
                                    , propertyPath, errors);
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>Checks that a provided version is a match for a known version.</summary>
 /// <remarks>
 /// Checks that a provided version is a match for a known version. Usually done for jurisdiction-specific datatype processing.
 /// This check does _not_ compare the contents of the datatype registry.
 /// </remarks>
 /// <param name="version1"></param>
 /// <param name="version2"></param>
 /// <returns>whether the versions match</returns>
 public static bool IsExactVersion(VersionNumber version1, VersionNumber version2)
 {
     if (version1 == null || version1.VersionLiteral == null || version2 == null || version2.VersionLiteral == null)
     {
         return(false);
     }
     return(version1.VersionLiteral.Equals(version2.VersionLiteral) && version1.GetBaseVersion() == version2.GetBaseVersion());
 }
Exemple #4
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);
 }
Exemple #5
0
        public virtual void ValidateTelecommunicationAddress(TelecommunicationAddress telecomAddress, string type, string specializationType
                                                             , VersionNumber version, XmlElement element, string propertyPath, Hl7Errors errors)
        {
            string actualType = DetermineActualType(telecomAddress, type, specializationType, version, element, propertyPath, errors,
                                                    true);

            ValidateTelecomAddressUses(telecomAddress, actualType, version, element, propertyPath, errors);
            ValidateTelecomAddressScheme(telecomAddress, actualType, version.GetBaseVersion(), element, propertyPath, errors);
            ValidateTelecomAddressValue(telecomAddress, actualType, version, element, propertyPath, errors);
        }
Exemple #6
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)));
        }
Exemple #7
0
        // CeRx does not specify PQ.LAB or PQ.DISTANCE
        public virtual int GetMaxFractionDigits(VersionNumber version, string typeAsString)
        {
            int maxFractionDigits = MAXIMUM_FRACTION_DIGITS;
            StandardDataType type = StandardDataType.GetByTypeName(typeAsString);

            if (StandardDataType.PQ_DRUG.Equals(type) || StandardDataType.PQ_LAB.Equals(type))
            {
                maxFractionDigits = MAXIMUM_FRACTION_DIGITS_DRUG_LAB;
            }
            Int32?exceptionValue = maximum_fraction_digits_exceptions.SafeGet(version.GetBaseVersion() + "_" + type);

            return((int)(exceptionValue == null ? maxFractionDigits : exceptionValue));
        }
Exemple #8
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
                                                         );
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #9
0
 private void AddSpecializationType(EncapsulatedData ed, IDictionary <string, string> attributes, string type, StandardDataType
                                    specializationType, VersionNumber version)
 {
     if (StandardDataType.ED_DOC_OR_REF.Type.Equals(type) && !Hl7BaseVersion.CERX.Equals(version.GetBaseVersion()))
     {
         if (specializationType == StandardDataType.ED_DOC || specializationType == StandardDataType.ED_DOC_REF)
         {
             AddSpecializationType(attributes, specializationType.Type);
         }
         else
         {
             // best guess: check content to decide on DOC or DOC_REF (CDA/R1 will get ST, though clients may not want it)
             AddSpecializationType(attributes, ed.HasContent() ? StandardDataType.ED_DOC.Type : StandardDataType.ED_DOC_REF.Type);
         }
     }
 }
Exemple #10
0
 private bool IsCeRxOrNewfoundland(VersionNumber version)
 {
     return(version.GetBaseVersion() == Hl7BaseVersion.CERX || "NEWFOUNDLAND".Equals(version.VersionLiteral));
 }
Exemple #11
0
        public virtual int GetMaxIntDigits(VersionNumber version, string type)
        {
            Int32?exceptionValue = maximum_integer_digits_exceptions.SafeGet(version.GetBaseVersion() + "_" + type);

            return((int)(exceptionValue == null ? MAXIMUM_INTEGER_DIGITS : exceptionValue));
        }
Exemple #12
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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #13
0
        public static string[] GetAllDateFormats(StandardDataType standardDataType, VersionNumber version)
        {
            if (standardDataType == null || version == null)
            {
                return(new string[0]);
            }
            IDictionary <StandardDataType, IList <string> > exceptionMap = TsDateFormats.versionFormatExceptions.SafeGet(version.GetBaseVersion
                                                                                                                             ());
            IList <string> formats = (exceptionMap == null ? null : exceptionMap.SafeGet(standardDataType));

            if (formats == null)
            {
                formats = TsDateFormats.formats.SafeGet(standardDataType);
            }
            return(CollUtils.IsEmpty(formats) ? new string[0] : formats.ToArray(new string[formats.Count]));
        }