/// <summary> /// Determines whether [is alpha numeric codes exists] [the specified contract code]. /// </summary> /// <param name="contractCode">The contract code.</param> /// <param name="condition">The condition.</param> /// <param name="conditionOperation">The condition operation.</param> /// <param name="isHcpcsCode">if set to <c>true</c> [is HCPCS code].</param> /// <returns></returns> private bool IsAlphaNumericCodesExists(ConditionRange contractCode, ICondition condition, Enums.ConditionOperation conditionOperation, bool isHcpcsCode = false) { IEnumerable <string> claimCodes = condition.LeftOperands; //Default flag to false bool isValid = false; var enumerable = claimCodes == null ? new List <string>() : claimCodes.ToList(); var emptyCodes = enumerable.ToList().Any(string.IsNullOrEmpty); if (emptyCodes && conditionOperation == Enums.ConditionOperation.NotEqualTo) { isValid = true; } else if (!(emptyCodes && conditionOperation == Enums.ConditionOperation.EqualTo)) { foreach (string claimCode in enumerable.Select(code => code.ToLower())) { isValid = IsClaimCodeExist(conditionOperation, claimCode, contractCode, isHcpcsCode); //Break loop is condition is not valid if (Utilities.IsConditionNotValid(isValid, conditionOperation)) { break; } } } return(isValid); }
/// <summary> /// Determines whether [is condition not valid] [the specified is valid]. /// </summary> /// <param name="isValid">if set to <c>true</c> [is valid].</param> /// <param name="conditionOperation">The condition operation.</param> /// <returns></returns> public static bool IsConditionNotValid(bool isValid, Enums.ConditionOperation conditionOperation) { return(conditionOperation == Enums.ConditionOperation.Contains ? (!isValid && conditionOperation != Enums.ConditionOperation.Contains) : ((!isValid && conditionOperation == Enums.ConditionOperation.NotEqualTo) || (isValid && conditionOperation != Enums.ConditionOperation.NotEqualTo && conditionOperation != Enums.ConditionOperation.Contains))); }
/// <summary> /// Determines whether [is code exist] [the specified condition operation]. /// </summary> /// <param name="conditionOperation">The condition operation.</param> /// <param name="claimCode">The claim code.</param> /// <param name="conditionRange">The condition range.</param> /// <returns></returns> private bool IsCodeExist(Enums.ConditionOperation conditionOperation, string claimCode, ConditionRange conditionRange) { bool isValid = false; double numericCode; double numericStartValue; if (Double.TryParse(claimCode, out numericCode) && Double.TryParse(conditionRange.StartValue, out numericStartValue)) { double numericEndValue; switch (conditionOperation) { case Enums.ConditionOperation.EqualTo: isValid = conditionRange.EndValue != null ? Double.TryParse(conditionRange.EndValue, out numericEndValue) && (numericCode >= numericStartValue) && (numericCode <= numericEndValue) : numericCode.Equals(numericStartValue); break; case Enums.ConditionOperation.GreaterThan: isValid = numericCode > numericStartValue; break; case Enums.ConditionOperation.LessThan: isValid = numericCode < numericStartValue; break; case Enums.ConditionOperation.NotEqualTo: isValid = conditionRange.EndValue != null ? Double.TryParse(conditionRange.EndValue, out numericEndValue) && !((numericCode >= numericStartValue) && (numericCode <= numericEndValue)) : !numericCode.Equals(numericStartValue); break; } } else if (conditionRange.StartValue.Contains('*') && claimCode != null && conditionRange.EndValue == null) { switch (conditionOperation) { case Enums.ConditionOperation.EqualTo: isValid = new RegexHelper(conditionRange.StartValue.Trim().Replace(@"\", "#")).IsMatch(claimCode.Trim().Replace( @"\", "#")); break; case Enums.ConditionOperation.NotEqualTo: isValid = !new RegexHelper(conditionRange.StartValue.Trim().Replace(@"\", "#")).IsMatch( claimCode.Trim().Replace(@"\", "#")); break; } } return(isValid); }
/// <summary> /// Determines whether [is valid length] [the specified contract codes]. /// </summary> /// <param name="contractCodes">The contract codes.</param> /// <param name="claimCodes">The claim codes.</param> /// <param name="conditionOperation">The condition operation.</param> /// <returns></returns> public static bool IsValidLength(ConditionRange contractCodes, IEnumerable <string> claimCodes, Enums.ConditionOperation conditionOperation) { if (claimCodes != null) { //Match claim code's length with maximum of all contract codes return((from item in claimCodes let length = GetMaxLength(contractCodes) where conditionOperation == Enums.ConditionOperation.GreaterThan && item.Length >= length || conditionOperation == Enums.ConditionOperation.LessThan && item.Length <= length select item).Any()); } return(false); }
/// <summary> /// Determines whether [is numeric code exist] [the specified condition]. /// </summary> /// <param name="condition">The condition.</param> /// <returns></returns> private bool IsNumericCodeExist(ICondition condition) { bool isValid = false; var enumerable = condition.LeftOperands as IList <string> ?? condition.LeftOperands.ToList(); var emptyCodes = enumerable.ToList().Any(string.IsNullOrEmpty); Enums.ConditionOperation conditionOperation = (Enums.ConditionOperation)condition.ConditionOperator; if (emptyCodes && conditionOperation == Enums.ConditionOperation.NotEqualTo) { isValid = true; } else if (!(emptyCodes && conditionOperation == Enums.ConditionOperation.EqualTo)) { //Getting Start and End values (Rage) from string List <ConditionRange> conditionRanges = Utilities.GetRanges(condition.RightOperand); //Update Total Charge Data conditionRanges = UpdateTotalChargeData(conditionRanges, condition); //For each claim codes match with contract conditions. foreach (string claimCode in condition.LeftOperands) { foreach (ConditionRange conditionRange in conditionRanges) { //check claim codes is between Start and End value range. isValid = IsCodeExist(conditionOperation, claimCode, conditionRange); //Break loop is condition is not valid if (Utilities.IsConditionNotValid(isValid, conditionOperation)) { break; } } //Break loop is condition is not valid if (Utilities.IsConditionNotValid(isValid, conditionOperation)) { break; } } } return(isValid); }
/// <summary> /// Determines whether [is alphanumeric codes] [the specified condition]. /// </summary> /// <param name="condition">The condition.</param> /// <returns></returns> private bool IsAlphanumericCodes(ICondition condition) { bool isValid = false; bool isHcpcsCode = false; //Update Code if Condition is set as Include Modifier if (condition.PropertyColumnName == Constants.PropertyHcpcsCodeWithModifier) { condition.LeftOperands = UpdateCodeWithIncludeModifier(condition.LeftOperands); condition.RightOperand = string.Join(Constants.Comma, UpdateCodeWithIncludeModifier(new List <string> { condition.RightOperand })); isHcpcsCode = true; } if (condition.PropertyColumnName == Constants.PropertyPriPayerName) { foreach (ConditionRange conditionRange in Utilities.GetRangesForPriPayerName(condition.RightOperand)) { Enums.ConditionOperation conditionOperation = (Enums.ConditionOperation)condition.ConditionOperator; //Check length is valid or not isValid = Utilities.IsValidLength(conditionRange, condition.LeftOperands, conditionOperation); if (!(!isValid && (conditionOperation == Enums.ConditionOperation.GreaterThan || conditionOperation == Enums.ConditionOperation.LessThan))) { //Pads left with spaces to make all items of same size ConditionRange padConditionRange = Utilities.PadConditionRange(conditionRange); Utilities.PadLeftToCode(condition.LeftOperands, padConditionRange); isValid = IsAlphaNumericCodesExists(padConditionRange, condition, conditionOperation); } //Break loop is condition is not valid if (Utilities.IsConditionNotValid(isValid, conditionOperation)) { break; } } } else { foreach (ConditionRange conditionRange in Utilities.GetRanges(condition.RightOperand)) { Enums.ConditionOperation conditionOperation = (Enums.ConditionOperation)condition.ConditionOperator; //Check length is valid or not isValid = Utilities.IsValidLength(conditionRange, condition.LeftOperands, conditionOperation); if (!(!isValid && (conditionOperation == Enums.ConditionOperation.GreaterThan || conditionOperation == Enums.ConditionOperation.LessThan))) { //Pads left with spaces to make all items of same size ConditionRange padConditionRange = Utilities.PadConditionRange(conditionRange); Utilities.PadLeftToCode(condition.LeftOperands, padConditionRange); isValid = IsAlphaNumericCodesExists(padConditionRange, condition, conditionOperation, isHcpcsCode); } //Break loop is condition is not valid if (Utilities.IsConditionNotValid(isValid, conditionOperation)) { break; } } } return(isValid); }
/// <summary> /// Determines whether [is claim code exist] [the specified condition operation]. /// </summary> /// <param name="conditionOperation">The condition operation.</param> /// <param name="claimCode">The claim code.</param> /// <param name="conditionRange">The condition range.</param> /// <param name="isHcpcsCode">if set to <c>true</c> [is HCPCS code].</param> /// <returns></returns> private bool IsClaimCodeExist(Enums.ConditionOperation conditionOperation, string claimCode, ConditionRange conditionRange, bool isHcpcsCode = false) { bool isValid = false; switch (conditionOperation) { case Enums.ConditionOperation.EqualTo: //If the claimcode is HCPCS, then claimcode will be considered as just first five characters of it. isValid = conditionRange.EndValue != null ? isHcpcsCode && claimCode.Trim() != string.Empty? (String.CompareOrdinal(claimCode.Trim().Length >= 5 ? claimCode.Trim().Substring(0, 5) : claimCode, conditionRange.StartValue.Trim().Length > 5 ? conditionRange.StartValue.Trim().Substring(0, 5) : conditionRange.StartValue.Trim()) >= 0 && String.CompareOrdinal(claimCode.Trim().Length >= 5 ? claimCode.Trim().Substring(0, 5) : claimCode, conditionRange.EndValue.Trim().Length > 5 ? conditionRange.EndValue.Trim().Substring(0, 5) : conditionRange.EndValue.Trim()) <= 0) : (String.CompareOrdinal(claimCode, conditionRange.StartValue) >= 0 && String.CompareOrdinal(claimCode, conditionRange.EndValue) <= 0) : (conditionRange.StartValue.Contains(Constants.WildCard) && claimCode != null ? new RegexHelper(conditionRange.StartValue.Trim().Length >= 5? conditionRange.StartValue.Trim().Substring(0, 5).Replace(@"\", Constants.RegexHash): conditionRange.StartValue.Trim().Replace(@"\", "#")).IsMatch( isHcpcsCode && claimCode.Trim().Length > 5 ? claimCode.Trim().Substring(0, 5).Replace(@"\", Constants.RegexHash) : claimCode.Trim().Replace(@"\", Constants.RegexHash)) : String.CompareOrdinal(claimCode, conditionRange.StartValue) == 0); if (!isValid && !string.IsNullOrWhiteSpace(claimCode) && isHcpcsCode && claimCode.Trim().Length > 5 && !conditionRange.StartValue.Contains(Constants.WildCard)) { string claimCodeHcpcs = claimCode.Trim().Substring(0, 5); isValid = conditionRange.EndValue != null ? String.CompareOrdinal(claimCodeHcpcs, conditionRange.StartValue) >= 0 && String.CompareOrdinal(claimCodeHcpcs, conditionRange.EndValue) <= 0 : (conditionRange.StartValue.Contains(Constants.WildCard) ? new RegexHelper(conditionRange.StartValue.Trim().Replace(@"\", Constants.RegexHash)).IsMatch( claimCodeHcpcs.Replace(@"\", Constants.RegexHash)) : String.CompareOrdinal(claimCodeHcpcs, conditionRange.StartValue.Trim()) == 0); } break; case Enums.ConditionOperation.GreaterThan: isValid = String.CompareOrdinal(claimCode, conditionRange.StartValue) > 0; break; case Enums.ConditionOperation.LessThan: isValid = conditionRange.EndValue != null ? String.CompareOrdinal(claimCode , conditionRange.EndValue) < 0 : String.CompareOrdinal(claimCode, conditionRange.StartValue) < 0; break; case Enums.ConditionOperation.NotEqualTo: claimCode = claimCode.Trim(); isValid = conditionRange.EndValue != null ? !(String.CompareOrdinal(claimCode, conditionRange.StartValue.Trim()) >= 0 && String.CompareOrdinal(claimCode, conditionRange.EndValue.Trim()) <= 0) : (conditionRange.StartValue.Contains(Constants.WildCard) ? !new RegexHelper(conditionRange.StartValue.Trim().Replace(@"\", Constants.RegexHash)).IsMatch( claimCode.Replace(@"\", Constants.RegexHash)) : String.CompareOrdinal(claimCode, conditionRange.StartValue.Trim()) != 0); if (isValid && !string.IsNullOrWhiteSpace(claimCode) && isHcpcsCode && claimCode.Length > 5) { string claimCodeHcpcs = claimCode.Substring(0, 5); isValid = conditionRange.EndValue != null ? !(String.CompareOrdinal(claimCodeHcpcs, conditionRange.StartValue) >= 0 && String.CompareOrdinal(claimCodeHcpcs, conditionRange.EndValue) <= 0) : (conditionRange.StartValue.Contains(Constants.WildCard) ? !new RegexHelper(conditionRange.StartValue.Trim().Replace(@"\", Constants.RegexHash)).IsMatch( claimCodeHcpcs.Replace(@"\", Constants.RegexHash)) : String.CompareOrdinal(claimCodeHcpcs, conditionRange.StartValue.Trim()) != 0); } break; case Enums.ConditionOperation.Contains: isValid = claimCode.Trim().Contains(conditionRange.StartValue.Trim()); break; } return(isValid); }
/// <summary> /// Determines whether [is date exist] [the specified condition]. /// </summary> /// <param name="condition">The condition.</param> /// <returns></returns> private bool IsDateExist(ICondition condition) { bool isValid = false; //Both Date Should come in LeftOperands for StatementCoversPeriodToDatesOfService. that's why we are checking Count = 2. bool isStatementCoversPeriod = condition.OperandIdentifier == (byte) Enums.OperandIdentifier.StatementCoversPeriodToDatesOfService && condition.LeftOperands.Count == 2; foreach (ConditionRange conditionRange in Utilities.GetRanges(condition.RightOperand)) { Enums.ConditionOperation conditionOperation = (Enums.ConditionOperation)condition.ConditionOperator; DateTime date; if (DateTime.TryParse(conditionRange.StartValue, out date)) { switch (conditionOperation) { case Enums.ConditionOperation.EqualTo: isValid = isStatementCoversPeriod ? condition.LeftOperands[0] != null && condition.LeftOperands[1] != null && (date.Date >= Convert.ToDateTime(condition.LeftOperands[0]) && date.Date <= Convert.ToDateTime(condition.LeftOperands[1])) : condition.LeftOperands[0] != null && date.Date == Convert.ToDateTime(condition.LeftOperands[0]); break; case Enums.ConditionOperation.GreaterThan: isValid = isStatementCoversPeriod ? condition.LeftOperands[1] != null && (Convert.ToDateTime(condition.LeftOperands[1]) > date.Date) : condition.LeftOperands[0] != null && Convert.ToDateTime(condition.LeftOperands[0]) > date.Date; break; case Enums.ConditionOperation.LessThan: isValid = condition.LeftOperands[0] != null && Convert.ToDateTime(condition.LeftOperands[0]) < date.Date; break; case Enums.ConditionOperation.NotEqualTo: isValid = isStatementCoversPeriod ? condition.LeftOperands[0] != null && condition.LeftOperands[1] != null && (!(date.Date >= Convert.ToDateTime(condition.LeftOperands[0]) && date.Date <= Convert.ToDateTime(condition.LeftOperands[1]))) : condition.LeftOperands[0] != null && date.Date != Convert.ToDateTime(condition.LeftOperands[0]); break; case Enums.ConditionOperation.GreaterThanEqualTo: isValid = condition.LeftOperands[0] != null && Convert.ToDateTime(condition.LeftOperands[0]) >= date.Date; break; case Enums.ConditionOperation.LessThanEqualTo: isValid = condition.LeftOperands[0] != null && Convert.ToDateTime(condition.LeftOperands[0]) <= date.Date; break; } } //Break loop is condition is not valid if (Utilities.IsConditionNotValid(isValid, conditionOperation)) { break; } } return(isValid); }