diff --git a/services/ui-src/src/measures/2021/globalValidations/index.ts b/services/ui-src/src/measures/2021/globalValidations/index.ts index da16c2bb40..8600b83908 100644 --- a/services/ui-src/src/measures/2021/globalValidations/index.ts +++ b/services/ui-src/src/measures/2021/globalValidations/index.ts @@ -7,7 +7,7 @@ export * from "./validateAtLeastOneDeviationFieldFilled"; export * from "shared/globalValidations/validateAtLeastOneRateComplete"; export * from "shared/globalValidations/validateBothDatesInRange"; export * from "./validateDualPopInformation"; -export * from "./validateEqualCategoryDenominators"; +export * from "shared/globalValidations/validateEqualCategoryDenominators"; export * from "shared/globalValidations/validateEqualQualifierDenominators"; export * from "./validateRateNotZero"; export * from "./validateRateZero"; diff --git a/services/ui-src/src/measures/2021/globalValidations/validateEqualCategoryDenominators/index.test.ts b/services/ui-src/src/measures/2021/globalValidations/validateEqualCategoryDenominators/index.test.ts deleted file mode 100644 index 77711f948a..0000000000 --- a/services/ui-src/src/measures/2021/globalValidations/validateEqualCategoryDenominators/index.test.ts +++ /dev/null @@ -1,185 +0,0 @@ -import { LabelData } from "utils"; -import { - validateEqualCategoryDenominatorsOMS, - validateEqualCategoryDenominatorsPM, -} from "."; - -import { - generateOmsCategoryRateData, - locationDictionary, - doubleRate, - simpleRate, - partialRate, - generatePmQualifierRateData, -} from "utils/testUtils/validationHelpers"; - -jest.mock("utils/getLabelText", () => ({ - isLegacyLabel: () => true, -})); - -describe("Testing Equal Denominators For All Qualifiers Validation", () => { - const noCat: LabelData[] = []; - const categories: LabelData[] = [ - { id: "Test Cat 1", label: "Test Cat 1", text: "Test Cat 1" }, - { id: "Test Cat 2", label: "Test Cat 2", text: "Test Cat 2" }, - ]; - const qualifiers: LabelData[] = [ - { id: "Test Qual 1", label: "Test Qual 1", text: "Test Qual 1" }, - { id: "Test Qual 2", label: "Test Qual 2", text: "Test Qual 2" }, - ]; - const pmd = { categories, qualifiers }; - - const baseOMSInfo = { - categories, - qualifiers, - locationDictionary, - isOPM: false, - label: ["TestLabel"], - }; - - // PM - describe("PM/OPM Validation", () => { - it("should return NO errors", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData(pmd, [simpleRate, simpleRate]), - categories - ); - - expect(errors).toHaveLength(0); - }); - - it("should have error", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData(pmd, [simpleRate, doubleRate]), - categories - ); - - expect(errors).toHaveLength(1); - expect(errors[0].errorList).toHaveLength(2); - expect(errors[0].errorLocation).toBe("Performance Measure"); - expect(errors[0].errorMessage).toBe( - `The following categories must have the same denominator:` - ); - expect(errors[0].errorList).toContain(categories[0].label); - expect(errors[0].errorList).toContain(categories[1].label); - }); - - it("should have error, with qualifiers listed", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData({ qualifiers, categories: noCat }, [ - simpleRate, - doubleRate, - ]), - noCat, - qualifiers - ); - - expect(errors).toHaveLength(1); - expect(errors[0].errorList).toHaveLength(2); - expect(errors[0].errorLocation).toBe("Performance Measure"); - expect(errors[0].errorMessage).toBe( - `The following categories must have the same denominator:` - ); - expect(errors[0].errorList).toContain(qualifiers[0].label); - expect(errors[0].errorList).toContain(qualifiers[1].label); - }); - - it("should NOT have error from empty rate value", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData(pmd, [partialRate, partialRate]), - categories - ); - - expect(errors).toHaveLength(0); - }); - - it("Error message text should match provided errorMessage", () => { - const errorMessage = "Another one bites the dust."; - const errorArray = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData({ qualifiers, categories: noCat }, [ - simpleRate, - doubleRate, - ]), - noCat, - qualifiers, - errorMessage - ); - expect(errorArray.length).toBe(1); - expect(errorArray[0].errorMessage).toBe(errorMessage); - }); - }); - - // OMS - describe("OMS Validation", () => { - it("should return NO errors", () => { - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - simpleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS()({ - ...baseOMSInfo, - rateData: data, - }); - - expect(errors).toHaveLength(0); - }); - - it("should return no errors if OPM", () => { - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - simpleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS()({ - ...baseOMSInfo, - rateData: data, - isOPM: true, - }); - - expect(errors).toHaveLength(0); - }); - - it("should have errors, list qualifiers", () => { - const locationDictionaryJestFunc = jest.fn(); - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - doubleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS()({ - ...baseOMSInfo, - locationDictionary: locationDictionaryJestFunc, - rateData: data, - }); - - expect(errors).toHaveLength(1); - expect(errors[0].errorLocation).toContain( - "Optional Measure Stratification:" - ); - expect(errors[0].errorMessage).toBe( - `The following categories must have the same denominator:` - ); - expect(errors[0].errorList).toContain(categories[0].label); - expect(errors[0].errorList).toContain(categories[1].label); - expect(locationDictionaryJestFunc).toHaveBeenCalledWith(["TestLabel"]); - }); - }); - - it("Error message text should match provided errorMessage", () => { - const errorMessage = "Another one bites the dust."; - const locationDictionaryJestFunc = jest.fn(); - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - doubleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS(errorMessage)({ - ...baseOMSInfo, - locationDictionary: locationDictionaryJestFunc, - rateData: data, - }); - - expect(errors).toHaveLength(1); - expect(errors[0].errorLocation).toContain( - "Optional Measure Stratification:" - ); - expect(errors[0].errorMessage).toBe(errorMessage); - }); -}); diff --git a/services/ui-src/src/measures/2021/globalValidations/validateEqualCategoryDenominators/index.ts b/services/ui-src/src/measures/2021/globalValidations/validateEqualCategoryDenominators/index.ts deleted file mode 100644 index 9441c1d2c8..0000000000 --- a/services/ui-src/src/measures/2021/globalValidations/validateEqualCategoryDenominators/index.ts +++ /dev/null @@ -1,78 +0,0 @@ -import * as Types from "shared/types"; -import { - OmsValidationCallback, - UnifiedValidationFunction as UVF, -} from "../types"; -import { - convertOmsDataToRateArray, - getPerfMeasureRateArray, -} from "../dataDrivenTools"; -import { SINGLE_CATEGORY } from "dataConstants"; -import { LabelData } from "utils"; - -const _validation: UVF = ({ - rateData, - qualifiers, - categories, - location, - errorMessage, -}) => { - const errorArray: FormError[] = []; - const locationArray: string[] = []; - const denominatorArray: string[] = []; - - for (const [i, rateSet] of rateData.entries()) { - for (const [j, rate] of rateSet.entries()) { - if (rate && rate.denominator) { - denominatorArray.push(rate.denominator); - locationArray.push( - !!categories?.length && categories[0].label !== SINGLE_CATEGORY - ? categories![i].label - : qualifiers![j].label - ); - } - } - } - - if (!denominatorArray.every((v) => denominatorArray[0] === v)) { - errorArray.push({ - errorLocation: location, - errorMessage: - errorMessage ?? - `The following categories must have the same denominator:`, - errorList: locationArray.filter((v, i, a) => a.indexOf(v) === i), - }); - } - - return errorArray; -}; - -/** Checks all rates have the same denominator for both categories and qualifiers. NOTE: only use qualifiers if category is empty */ -export const validateEqualCategoryDenominatorsOMS = - (errorMessage?: string): OmsValidationCallback => - ({ rateData, categories, qualifiers, label, locationDictionary, isOPM }) => { - if (isOPM) return []; - return _validation({ - categories, - qualifiers, - rateData: convertOmsDataToRateArray(categories, qualifiers, rateData), - location: `Optional Measure Stratification: ${locationDictionary(label)}`, - errorMessage, - }); - }; - -/** Checks all rates have the same denominator for both categories and qualifiers. NOTE: only pass qualifiers if category is empty */ -export const validateEqualCategoryDenominatorsPM = ( - data: Types.PerformanceMeasure, - categories: LabelData[], - qualifiers?: LabelData[], - errorMessage?: string -) => { - return _validation({ - categories, - qualifiers, - location: "Performance Measure", - rateData: getPerfMeasureRateArray(data, { categories, qualifiers }), - errorMessage, - }); -}; diff --git a/services/ui-src/src/measures/2022/shared/globalValidations/index.ts b/services/ui-src/src/measures/2022/shared/globalValidations/index.ts index da16c2bb40..8600b83908 100644 --- a/services/ui-src/src/measures/2022/shared/globalValidations/index.ts +++ b/services/ui-src/src/measures/2022/shared/globalValidations/index.ts @@ -7,7 +7,7 @@ export * from "./validateAtLeastOneDeviationFieldFilled"; export * from "shared/globalValidations/validateAtLeastOneRateComplete"; export * from "shared/globalValidations/validateBothDatesInRange"; export * from "./validateDualPopInformation"; -export * from "./validateEqualCategoryDenominators"; +export * from "shared/globalValidations/validateEqualCategoryDenominators"; export * from "shared/globalValidations/validateEqualQualifierDenominators"; export * from "./validateRateNotZero"; export * from "./validateRateZero"; diff --git a/services/ui-src/src/measures/2022/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts b/services/ui-src/src/measures/2022/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts deleted file mode 100644 index 77711f948a..0000000000 --- a/services/ui-src/src/measures/2022/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts +++ /dev/null @@ -1,185 +0,0 @@ -import { LabelData } from "utils"; -import { - validateEqualCategoryDenominatorsOMS, - validateEqualCategoryDenominatorsPM, -} from "."; - -import { - generateOmsCategoryRateData, - locationDictionary, - doubleRate, - simpleRate, - partialRate, - generatePmQualifierRateData, -} from "utils/testUtils/validationHelpers"; - -jest.mock("utils/getLabelText", () => ({ - isLegacyLabel: () => true, -})); - -describe("Testing Equal Denominators For All Qualifiers Validation", () => { - const noCat: LabelData[] = []; - const categories: LabelData[] = [ - { id: "Test Cat 1", label: "Test Cat 1", text: "Test Cat 1" }, - { id: "Test Cat 2", label: "Test Cat 2", text: "Test Cat 2" }, - ]; - const qualifiers: LabelData[] = [ - { id: "Test Qual 1", label: "Test Qual 1", text: "Test Qual 1" }, - { id: "Test Qual 2", label: "Test Qual 2", text: "Test Qual 2" }, - ]; - const pmd = { categories, qualifiers }; - - const baseOMSInfo = { - categories, - qualifiers, - locationDictionary, - isOPM: false, - label: ["TestLabel"], - }; - - // PM - describe("PM/OPM Validation", () => { - it("should return NO errors", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData(pmd, [simpleRate, simpleRate]), - categories - ); - - expect(errors).toHaveLength(0); - }); - - it("should have error", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData(pmd, [simpleRate, doubleRate]), - categories - ); - - expect(errors).toHaveLength(1); - expect(errors[0].errorList).toHaveLength(2); - expect(errors[0].errorLocation).toBe("Performance Measure"); - expect(errors[0].errorMessage).toBe( - `The following categories must have the same denominator:` - ); - expect(errors[0].errorList).toContain(categories[0].label); - expect(errors[0].errorList).toContain(categories[1].label); - }); - - it("should have error, with qualifiers listed", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData({ qualifiers, categories: noCat }, [ - simpleRate, - doubleRate, - ]), - noCat, - qualifiers - ); - - expect(errors).toHaveLength(1); - expect(errors[0].errorList).toHaveLength(2); - expect(errors[0].errorLocation).toBe("Performance Measure"); - expect(errors[0].errorMessage).toBe( - `The following categories must have the same denominator:` - ); - expect(errors[0].errorList).toContain(qualifiers[0].label); - expect(errors[0].errorList).toContain(qualifiers[1].label); - }); - - it("should NOT have error from empty rate value", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData(pmd, [partialRate, partialRate]), - categories - ); - - expect(errors).toHaveLength(0); - }); - - it("Error message text should match provided errorMessage", () => { - const errorMessage = "Another one bites the dust."; - const errorArray = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData({ qualifiers, categories: noCat }, [ - simpleRate, - doubleRate, - ]), - noCat, - qualifiers, - errorMessage - ); - expect(errorArray.length).toBe(1); - expect(errorArray[0].errorMessage).toBe(errorMessage); - }); - }); - - // OMS - describe("OMS Validation", () => { - it("should return NO errors", () => { - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - simpleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS()({ - ...baseOMSInfo, - rateData: data, - }); - - expect(errors).toHaveLength(0); - }); - - it("should return no errors if OPM", () => { - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - simpleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS()({ - ...baseOMSInfo, - rateData: data, - isOPM: true, - }); - - expect(errors).toHaveLength(0); - }); - - it("should have errors, list qualifiers", () => { - const locationDictionaryJestFunc = jest.fn(); - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - doubleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS()({ - ...baseOMSInfo, - locationDictionary: locationDictionaryJestFunc, - rateData: data, - }); - - expect(errors).toHaveLength(1); - expect(errors[0].errorLocation).toContain( - "Optional Measure Stratification:" - ); - expect(errors[0].errorMessage).toBe( - `The following categories must have the same denominator:` - ); - expect(errors[0].errorList).toContain(categories[0].label); - expect(errors[0].errorList).toContain(categories[1].label); - expect(locationDictionaryJestFunc).toHaveBeenCalledWith(["TestLabel"]); - }); - }); - - it("Error message text should match provided errorMessage", () => { - const errorMessage = "Another one bites the dust."; - const locationDictionaryJestFunc = jest.fn(); - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - doubleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS(errorMessage)({ - ...baseOMSInfo, - locationDictionary: locationDictionaryJestFunc, - rateData: data, - }); - - expect(errors).toHaveLength(1); - expect(errors[0].errorLocation).toContain( - "Optional Measure Stratification:" - ); - expect(errors[0].errorMessage).toBe(errorMessage); - }); -}); diff --git a/services/ui-src/src/measures/2022/shared/globalValidations/validateEqualCategoryDenominators/index.ts b/services/ui-src/src/measures/2022/shared/globalValidations/validateEqualCategoryDenominators/index.ts deleted file mode 100644 index 9441c1d2c8..0000000000 --- a/services/ui-src/src/measures/2022/shared/globalValidations/validateEqualCategoryDenominators/index.ts +++ /dev/null @@ -1,78 +0,0 @@ -import * as Types from "shared/types"; -import { - OmsValidationCallback, - UnifiedValidationFunction as UVF, -} from "../types"; -import { - convertOmsDataToRateArray, - getPerfMeasureRateArray, -} from "../dataDrivenTools"; -import { SINGLE_CATEGORY } from "dataConstants"; -import { LabelData } from "utils"; - -const _validation: UVF = ({ - rateData, - qualifiers, - categories, - location, - errorMessage, -}) => { - const errorArray: FormError[] = []; - const locationArray: string[] = []; - const denominatorArray: string[] = []; - - for (const [i, rateSet] of rateData.entries()) { - for (const [j, rate] of rateSet.entries()) { - if (rate && rate.denominator) { - denominatorArray.push(rate.denominator); - locationArray.push( - !!categories?.length && categories[0].label !== SINGLE_CATEGORY - ? categories![i].label - : qualifiers![j].label - ); - } - } - } - - if (!denominatorArray.every((v) => denominatorArray[0] === v)) { - errorArray.push({ - errorLocation: location, - errorMessage: - errorMessage ?? - `The following categories must have the same denominator:`, - errorList: locationArray.filter((v, i, a) => a.indexOf(v) === i), - }); - } - - return errorArray; -}; - -/** Checks all rates have the same denominator for both categories and qualifiers. NOTE: only use qualifiers if category is empty */ -export const validateEqualCategoryDenominatorsOMS = - (errorMessage?: string): OmsValidationCallback => - ({ rateData, categories, qualifiers, label, locationDictionary, isOPM }) => { - if (isOPM) return []; - return _validation({ - categories, - qualifiers, - rateData: convertOmsDataToRateArray(categories, qualifiers, rateData), - location: `Optional Measure Stratification: ${locationDictionary(label)}`, - errorMessage, - }); - }; - -/** Checks all rates have the same denominator for both categories and qualifiers. NOTE: only pass qualifiers if category is empty */ -export const validateEqualCategoryDenominatorsPM = ( - data: Types.PerformanceMeasure, - categories: LabelData[], - qualifiers?: LabelData[], - errorMessage?: string -) => { - return _validation({ - categories, - qualifiers, - location: "Performance Measure", - rateData: getPerfMeasureRateArray(data, { categories, qualifiers }), - errorMessage, - }); -}; diff --git a/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx b/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx index ce6b071d9f..3069f378d3 100644 --- a/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx +++ b/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx @@ -3,7 +3,7 @@ import * as validateAtLeastOneDeviationFieldFilled from "measures/2022/shared/gl import * as validateAtLeastOneRateComplete from "shared/globalValidations/validateAtLeastOneRateComplete"; import * as validateBothDatesInRange from "shared/globalValidations/validateBothDatesInRange"; import * as validateDualPopInformation from "measures/2022/shared/globalValidations/validateDualPopInformation"; -import * as validateEqualCategoryDenominators from "measures/2022/shared/globalValidations/validateEqualCategoryDenominators"; +import * as validateEqualCategoryDenominators from "shared/globalValidations/validateEqualCategoryDenominators"; import * as validateEqualQualifierDenominators from "shared/globalValidations/validateEqualQualifierDenominators"; import * as validateRateNotZero from "measures/2022/shared/globalValidations/validateRateNotZero"; import * as validateRateZero from "measures/2022/shared/globalValidations/validateRateZero"; diff --git a/services/ui-src/src/measures/2023/shared/globalValidations/index.ts b/services/ui-src/src/measures/2023/shared/globalValidations/index.ts index 1f94abfdbe..5c8eba40dd 100644 --- a/services/ui-src/src/measures/2023/shared/globalValidations/index.ts +++ b/services/ui-src/src/measures/2023/shared/globalValidations/index.ts @@ -11,7 +11,7 @@ export * from "shared/globalValidations/validateAtLeastOneRateComplete"; export * from "shared/globalValidations/validateBothDatesInRange"; export * from "shared/globalValidations/validateDateRangeRadioButtonCompletion"; export * from "./validateDualPopInformation"; -export * from "./validateEqualCategoryDenominators"; +export * from "shared/globalValidations/validateEqualCategoryDenominators"; export * from "shared/globalValidations/validateEqualQualifierDenominators"; export * from "shared/globalValidations/validateFfsRadioButtonCompletion"; export * from "./validateRateNotZero"; diff --git a/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx b/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx index 15017a7f65..b28e7c2294 100644 --- a/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx +++ b/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx @@ -6,7 +6,7 @@ import * as validateAtLeastOneDeviationFieldFilled from "measures/2023/shared/gl import * as validateAtLeastOneRateComplete from "shared/globalValidations/validateAtLeastOneRateComplete"; import * as validateBothDatesInRange from "shared/globalValidations/validateBothDatesInRange"; import * as validateDualPopInformation from "measures/2023/shared/globalValidations/validateDualPopInformation"; -import * as validateEqualCategoryDenominators from "measures/2023/shared/globalValidations/validateEqualCategoryDenominators"; +import * as validateEqualCategoryDenominators from "shared/globalValidations/validateEqualCategoryDenominators"; import * as validateEqualQualifierDenominators from "shared/globalValidations/validateEqualQualifierDenominators"; import * as validateFfsRadioButtonCompletion from "shared/globalValidations/validateFfsRadioButtonCompletion"; import * as validateRateNotZero from "measures/2023/shared/globalValidations/validateRateNotZero"; diff --git a/services/ui-src/src/measures/2024/shared/globalValidations/index.ts b/services/ui-src/src/measures/2024/shared/globalValidations/index.ts index 36cc92039c..0a19895558 100644 --- a/services/ui-src/src/measures/2024/shared/globalValidations/index.ts +++ b/services/ui-src/src/measures/2024/shared/globalValidations/index.ts @@ -12,7 +12,7 @@ export * from "shared/globalValidations/validateAtLeastOneRateComplete"; export * from "shared/globalValidations/validateBothDatesInRange"; export * from "shared/globalValidations/validateDateRangeRadioButtonCompletion"; export * from "./validateDualPopInformation"; -export * from "./validateEqualCategoryDenominators"; +export * from "shared/globalValidations/validateEqualCategoryDenominators"; export * from "shared/globalValidations/validateEqualQualifierDenominators"; export * from "shared/globalValidations/validateFfsRadioButtonCompletion"; export * from "./validateRateNotZero"; diff --git a/services/ui-src/src/measures/2024/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts b/services/ui-src/src/measures/2024/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts deleted file mode 100644 index 870c5cbf59..0000000000 --- a/services/ui-src/src/measures/2024/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts +++ /dev/null @@ -1,184 +0,0 @@ -import { LabelData } from "utils"; -import { - validateEqualCategoryDenominatorsOMS, - validateEqualCategoryDenominatorsPM, -} from "."; - -import { - generateOmsCategoryRateData, - locationDictionary, - doubleRate, - simpleRate, - partialRate, - generatePmQualifierRateData, -} from "utils/testUtils/validationHelpers"; - -describe("Testing Equal Denominators For All Qualifiers Validation", () => { - const noCat: LabelData[] = []; - const categories = [ - { label: "TestCat1", text: "TestCat1", id: "TestCat1" }, - { label: "TestCat2", text: "TestCat2", id: "TestCat2" }, - ]; - const qualifiers = [ - { label: "TestQual1", text: "TestQual1", id: "TestQual1" }, - { label: "TestQual2", text: "TestQual2", id: "TestQual2" }, - ]; - const pmd = { categories, qualifiers }; - - const baseOMSInfo = { - categories, - qualifiers, - locationDictionary, - isOPM: false, - label: ["TestLabel"], - }; - - // PM - describe("PM/OPM Validation", () => { - it("should return NO errors", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData(pmd, [simpleRate, simpleRate]), - categories, - qualifiers - ); - - expect(errors).toHaveLength(0); - }); - - it("should have error", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData(pmd, [simpleRate, doubleRate]), - categories, - qualifiers - ); - - expect(errors).toHaveLength(1); - expect(errors[0].errorList).toHaveLength(2); - expect(errors[0].errorLocation).toBe("Performance Measure"); - expect(errors[0].errorMessage).toBe( - `The following categories must have the same denominator:` - ); - expect(errors[0].errorList).toContain(categories[0].label); - expect(errors[0].errorList).toContain(categories[1].label); - }); - - it("should have error, with qualifiers listed", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData({ qualifiers, categories: noCat }, [ - simpleRate, - doubleRate, - ]), - noCat, - qualifiers - ); - - expect(errors).toHaveLength(1); - expect(errors[0].errorList).toHaveLength(2); - expect(errors[0].errorLocation).toBe("Performance Measure"); - expect(errors[0].errorMessage).toBe( - `The following categories must have the same denominator:` - ); - expect(errors[0].errorList).toContain(qualifiers[0].label); - expect(errors[0].errorList).toContain(qualifiers[1].label); - }); - - it("should NOT have error from empty rate value", () => { - const errors = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData(pmd, [partialRate, partialRate]), - categories, - qualifiers - ); - - expect(errors).toHaveLength(0); - }); - - it("Error message text should match provided errorMessage", () => { - const errorMessage = "Another one bites the dust."; - const errorArray = validateEqualCategoryDenominatorsPM( - generatePmQualifierRateData({ qualifiers, categories: noCat }, [ - simpleRate, - doubleRate, - ]), - noCat, - qualifiers, - errorMessage - ); - expect(errorArray.length).toBe(1); - expect(errorArray[0].errorMessage).toBe(errorMessage); - }); - }); - - // OMS - describe("OMS Validation", () => { - it("should return NO errors", () => { - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - simpleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS()({ - ...baseOMSInfo, - rateData: data, - }); - - expect(errors).toHaveLength(0); - }); - - it("should return no errors if OPM", () => { - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - simpleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS()({ - ...baseOMSInfo, - rateData: data, - isOPM: true, - }); - - expect(errors).toHaveLength(0); - }); - - it("should have errors, list qualifiers", () => { - const locationDictionaryJestFunc = jest.fn(); - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - doubleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS()({ - ...baseOMSInfo, - locationDictionary: locationDictionaryJestFunc, - rateData: data, - }); - - expect(errors).toHaveLength(1); - expect(errors[0].errorLocation).toContain( - "Optional Measure Stratification:" - ); - expect(errors[0].errorMessage).toBe( - `The following categories must have the same denominator:` - ); - expect(errors[0].errorList).toContain(categories[0].label); - expect(errors[0].errorList).toContain(categories[1].label); - expect(locationDictionaryJestFunc).toHaveBeenCalledWith(["TestLabel"]); - }); - }); - - it("Error message text should match provided errorMessage", () => { - const errorMessage = "Another one bites the dust."; - const locationDictionaryJestFunc = jest.fn(); - const data = generateOmsCategoryRateData(categories, qualifiers, [ - simpleRate, - doubleRate, - ]); - const errors = validateEqualCategoryDenominatorsOMS(errorMessage)({ - ...baseOMSInfo, - locationDictionary: locationDictionaryJestFunc, - rateData: data, - }); - - expect(errors).toHaveLength(1); - expect(errors[0].errorLocation).toContain( - "Optional Measure Stratification:" - ); - expect(errors[0].errorMessage).toBe(errorMessage); - }); -}); diff --git a/services/ui-src/src/measures/2024/shared/globalValidations/validateEqualCategoryDenominators/index.ts b/services/ui-src/src/measures/2024/shared/globalValidations/validateEqualCategoryDenominators/index.ts deleted file mode 100644 index 33aa86814d..0000000000 --- a/services/ui-src/src/measures/2024/shared/globalValidations/validateEqualCategoryDenominators/index.ts +++ /dev/null @@ -1,80 +0,0 @@ -import * as Types from "shared/types"; -import { - OmsValidationCallback, - UnifiedValidationFunction as UVF, -} from "../types"; -import { - convertOmsDataToRateArray, - getPerfMeasureRateArray, -} from "../dataDrivenTools"; -import { SINGLE_CATEGORY } from "dataConstants"; -import { LabelData } from "utils"; - -const _validation: UVF = ({ - rateData, - qualifiers, - categories, - location, - errorMessage, -}) => { - const errorArray: FormError[] = []; - const locationArray: string[] = []; - const denominatorArray: string[] = []; - - for (const [i, rateSet] of rateData.entries()) { - for (const [j, rate] of rateSet.entries()) { - if (rate && rate.denominator) { - denominatorArray.push(rate.denominator); - locationArray.push( - !!categories?.length && - categories[0].label !== SINGLE_CATEGORY && - categories.some((item) => item.label) - ? categories![i].label - : qualifiers![j].label - ); - } - } - } - - if (!denominatorArray.every((v) => denominatorArray[0] === v)) { - errorArray.push({ - errorLocation: location, - errorMessage: - errorMessage ?? - `The following categories must have the same denominator:`, - errorList: locationArray.filter((v, i, a) => a.indexOf(v) === i), - }); - } - - return errorArray; -}; - -/** Checks all rates have the same denominator for both categories and qualifiers. NOTE: only use qualifiers if category is empty */ -export const validateEqualCategoryDenominatorsOMS = - (errorMessage?: string): OmsValidationCallback => - ({ rateData, categories, qualifiers, label, locationDictionary, isOPM }) => { - if (isOPM) return []; - return _validation({ - categories, - qualifiers, - rateData: convertOmsDataToRateArray(categories, qualifiers, rateData), - location: `Optional Measure Stratification: ${locationDictionary(label)}`, - errorMessage, - }); - }; - -/** Checks all rates have the same denominator for both categories and qualifiers. NOTE: only pass qualifiers if category is empty */ -export const validateEqualCategoryDenominatorsPM = ( - data: Types.PerformanceMeasure, - categories: LabelData[], - qualifiers?: LabelData[], - errorMessage?: string -) => { - return _validation({ - categories, - qualifiers, - location: "Performance Measure", - rateData: getPerfMeasureRateArray(data, { categories, qualifiers }), - errorMessage, - }); -}; diff --git a/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx b/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx index 1fee268f9c..0c798bdbaf 100644 --- a/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx +++ b/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx @@ -6,7 +6,7 @@ import * as validateAtLeastOneDeviationFieldFilled from "measures/2024/shared/gl import * as validateAtLeastOneRateComplete from "shared/globalValidations/validateAtLeastOneRateComplete"; import * as validateBothDatesInRange from "shared/globalValidations/validateBothDatesInRange"; import * as validateDualPopInformation from "measures/2024/shared/globalValidations/validateDualPopInformation"; -import * as validateEqualCategoryDenominators from "measures/2024/shared/globalValidations/validateEqualCategoryDenominators"; +import * as validateEqualCategoryDenominators from "shared/globalValidations/validateEqualCategoryDenominators"; import * as validateEqualQualifierDenominators from "shared/globalValidations/validateEqualQualifierDenominators"; import * as validateFfsRadioButtonCompletion from "shared/globalValidations/validateFfsRadioButtonCompletion"; import * as validateRateNotZero from "measures/2024/shared/globalValidations/validateRateNotZero"; diff --git a/services/ui-src/src/measures/2023/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts b/services/ui-src/src/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts similarity index 100% rename from services/ui-src/src/measures/2023/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts rename to services/ui-src/src/shared/globalValidations/validateEqualCategoryDenominators/index.test.ts diff --git a/services/ui-src/src/measures/2023/shared/globalValidations/validateEqualCategoryDenominators/index.ts b/services/ui-src/src/shared/globalValidations/validateEqualCategoryDenominators/index.ts similarity index 98% rename from services/ui-src/src/measures/2023/shared/globalValidations/validateEqualCategoryDenominators/index.ts rename to services/ui-src/src/shared/globalValidations/validateEqualCategoryDenominators/index.ts index 33aa86814d..1e3d8b51b9 100644 --- a/services/ui-src/src/measures/2023/shared/globalValidations/validateEqualCategoryDenominators/index.ts +++ b/services/ui-src/src/shared/globalValidations/validateEqualCategoryDenominators/index.ts @@ -2,7 +2,7 @@ import * as Types from "shared/types"; import { OmsValidationCallback, UnifiedValidationFunction as UVF, -} from "../types"; +} from "shared/types/TypeValidations"; import { convertOmsDataToRateArray, getPerfMeasureRateArray,