diff --git a/services/ui-src/src/measures/2021/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx b/services/ui-src/src/measures/2021/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx deleted file mode 100644 index 57c1d281f8..0000000000 --- a/services/ui-src/src/measures/2021/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx +++ /dev/null @@ -1,113 +0,0 @@ -import { LabelData, cleanString } from "utils"; - -export const ComplexValueSameCrossCategoryOMS = ( - rateData: any, - categories: LabelData[], - qualifiers: LabelData[], - errorLocation: string -) => { - // Using a subset of rateData as iterator to be sure that Total - // is always at the end of the category array. - const qualifierObj = { ...rateData }; - delete qualifierObj["Total"]; - const totalData = rateData["Total"]; // quick reference variable - - const qualifierLabels: any = {}; - for (const q of qualifiers) { - const qCleaned = q.id; - qualifierLabels[qCleaned] = q; - } - const cleanedCategories = categories.map((cat) => cat.id); - - // build performanceMeasureArray - let performanceMeasureArray = []; - for (const cat of cleanedCategories) { - let row = []; - for (const q in qualifierObj) { - const qual = qualifierObj[q]?.[cat]?.[0]; - if (qual) { - qual.label = qualifierLabels[q]; - row.push(qual); - } - } - // only need to add total data if other data exists - if (row.length > 0) { - const catTotal = { ...totalData[cat][0] }; - catTotal.label = "Total"; - row.push(catTotal); - performanceMeasureArray.push(row); - } - } - - // if (performanceMeasureArray) - let errorArray: any[] = ComplexValueSameCrossCategory({ - rateData: performanceMeasureArray, - OPM: undefined, - errorLocation, - }); - return errorArray; -}; - -interface Props { - rateData: any; - OPM: any; - fieldIndex?: number; - fieldLabel?: string; - errorLocation?: string; -} - -/* - * Validate that the value of a given field with a given qualifier is consistent - * across all measurement categories. - * - * Ex - "Number of Enrollee Months" in Inpatient ages 0-17 === Medicine ages 0-17 - */ -export const ComplexValueSameCrossCategory = ({ - rateData, - OPM, - fieldIndex = 0, - fieldLabel = "Number of Enrollee Months", - errorLocation = "Performance Measure/Other Performance Measure", -}: Props) => { - let errorArray: any[] = []; - if (!OPM) { - const tempValues: { - [cleanedQualifier: string]: { - value: string; - label: string; - error?: boolean; - }; - } = {}; - for (const category of rateData) { - for (const qualifier of category.slice(0, -1)) { - const cleanQual = cleanString(qualifier.label); - if (tempValues[cleanQual]?.value) { - if ( - qualifier.fields[fieldIndex]?.value && - tempValues[cleanQual].value !== qualifier.fields[fieldIndex]?.value - ) { - // Set an error if the qualifier does not match tempValues - tempValues[cleanQual].error = true; - } - } else { - // Set tempValues[cleanQual] to be used in future checks against other qualifiers - tempValues[cleanQual] = { - value: qualifier.fields[fieldIndex]?.value, - label: qualifier.label, - }; - } - } - } - - // Using tempValues as a reference prevents multiple error messages per qualifier - for (const tempValue in tempValues) { - if (tempValues[tempValue]?.error) { - errorArray.push({ - errorLocation, - errorMessage: `Value of "${fieldLabel}" in ${tempValues[tempValue].label} must be the same across all measurement categories.`, - }); - } - } - } - return errorArray; -}; diff --git a/services/ui-src/src/measures/2021/globalValidations/index.ts b/services/ui-src/src/measures/2021/globalValidations/index.ts index da16c2bb40..29aad7ee4a 100644 --- a/services/ui-src/src/measures/2021/globalValidations/index.ts +++ b/services/ui-src/src/measures/2021/globalValidations/index.ts @@ -40,4 +40,4 @@ export { ComplexValidateDualPopInformation } from "./ComplexValidations/ComplexV export { ComplexValueSameCrossCategory, ComplexValueSameCrossCategoryOMS, -} from "./ComplexValidations/ComplexValueSameCrossCategory"; +} from "shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; diff --git a/services/ui-src/src/measures/2022/IUHH/validation.ts b/services/ui-src/src/measures/2022/IUHH/validation.ts index 59fb95b490..a1a9813e99 100644 --- a/services/ui-src/src/measures/2022/IUHH/validation.ts +++ b/services/ui-src/src/measures/2022/IUHH/validation.ts @@ -110,7 +110,7 @@ const OMSValidations: GV.Types.OmsValidationCallback = ({ rates ?? [], ndrForumlas, `Optional Measure Stratification: ${locationDictionary(label)}`, - OPM.map((item: any) => item.description) + OPM?.map((item: any) => item.description) ), ...GV.ComplexValidateNDRTotalsOMS( rateData?.["iuhh-rate"]?.rates ?? {}, diff --git a/services/ui-src/src/measures/2022/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx b/services/ui-src/src/measures/2022/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx deleted file mode 100644 index 57c1d281f8..0000000000 --- a/services/ui-src/src/measures/2022/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx +++ /dev/null @@ -1,113 +0,0 @@ -import { LabelData, cleanString } from "utils"; - -export const ComplexValueSameCrossCategoryOMS = ( - rateData: any, - categories: LabelData[], - qualifiers: LabelData[], - errorLocation: string -) => { - // Using a subset of rateData as iterator to be sure that Total - // is always at the end of the category array. - const qualifierObj = { ...rateData }; - delete qualifierObj["Total"]; - const totalData = rateData["Total"]; // quick reference variable - - const qualifierLabels: any = {}; - for (const q of qualifiers) { - const qCleaned = q.id; - qualifierLabels[qCleaned] = q; - } - const cleanedCategories = categories.map((cat) => cat.id); - - // build performanceMeasureArray - let performanceMeasureArray = []; - for (const cat of cleanedCategories) { - let row = []; - for (const q in qualifierObj) { - const qual = qualifierObj[q]?.[cat]?.[0]; - if (qual) { - qual.label = qualifierLabels[q]; - row.push(qual); - } - } - // only need to add total data if other data exists - if (row.length > 0) { - const catTotal = { ...totalData[cat][0] }; - catTotal.label = "Total"; - row.push(catTotal); - performanceMeasureArray.push(row); - } - } - - // if (performanceMeasureArray) - let errorArray: any[] = ComplexValueSameCrossCategory({ - rateData: performanceMeasureArray, - OPM: undefined, - errorLocation, - }); - return errorArray; -}; - -interface Props { - rateData: any; - OPM: any; - fieldIndex?: number; - fieldLabel?: string; - errorLocation?: string; -} - -/* - * Validate that the value of a given field with a given qualifier is consistent - * across all measurement categories. - * - * Ex - "Number of Enrollee Months" in Inpatient ages 0-17 === Medicine ages 0-17 - */ -export const ComplexValueSameCrossCategory = ({ - rateData, - OPM, - fieldIndex = 0, - fieldLabel = "Number of Enrollee Months", - errorLocation = "Performance Measure/Other Performance Measure", -}: Props) => { - let errorArray: any[] = []; - if (!OPM) { - const tempValues: { - [cleanedQualifier: string]: { - value: string; - label: string; - error?: boolean; - }; - } = {}; - for (const category of rateData) { - for (const qualifier of category.slice(0, -1)) { - const cleanQual = cleanString(qualifier.label); - if (tempValues[cleanQual]?.value) { - if ( - qualifier.fields[fieldIndex]?.value && - tempValues[cleanQual].value !== qualifier.fields[fieldIndex]?.value - ) { - // Set an error if the qualifier does not match tempValues - tempValues[cleanQual].error = true; - } - } else { - // Set tempValues[cleanQual] to be used in future checks against other qualifiers - tempValues[cleanQual] = { - value: qualifier.fields[fieldIndex]?.value, - label: qualifier.label, - }; - } - } - } - - // Using tempValues as a reference prevents multiple error messages per qualifier - for (const tempValue in tempValues) { - if (tempValues[tempValue]?.error) { - errorArray.push({ - errorLocation, - errorMessage: `Value of "${fieldLabel}" in ${tempValues[tempValue].label} must be the same across all measurement categories.`, - }); - } - } - } - return errorArray; -}; 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..29aad7ee4a 100644 --- a/services/ui-src/src/measures/2022/shared/globalValidations/index.ts +++ b/services/ui-src/src/measures/2022/shared/globalValidations/index.ts @@ -40,4 +40,4 @@ export { ComplexValidateDualPopInformation } from "./ComplexValidations/ComplexV export { ComplexValueSameCrossCategory, ComplexValueSameCrossCategoryOMS, -} from "./ComplexValidations/ComplexValueSameCrossCategory"; +} from "shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; 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..b2eedc8286 100644 --- a/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx +++ b/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx @@ -22,7 +22,7 @@ import * as ComplexNoNonZeroNumOrDenom from "measures/2022/shared/globalValidati import * as ComplexValidateAtLeastOneNDRInDeviationOfMeasureSpec from "measures/2022/shared/globalValidations/ComplexValidations/ComplexValidateAtLeastOneNDRInDeviationOfMeasureSpec"; //pragma: allowlist secret import * as ComplexValidateNDRTotals from "measures/2022/shared/globalValidations/ComplexValidations/ComplexValidateNDRTotals"; import * as ComplexValidateDualPopInformation from "measures/2022/shared/globalValidations/ComplexValidations/ComplexValidateDualPopInformation"; -import * as ComplexValueSameCrossCategory from "measures/2022/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; +import * as ComplexValueSameCrossCategory from "shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; import { DefaultFormDataLegacy as DefaultFormData } from "shared/types/FormData"; /** 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 3381a22ba8..a795014072 100644 --- a/services/ui-src/src/measures/2023/shared/globalValidations/index.ts +++ b/services/ui-src/src/measures/2023/shared/globalValidations/index.ts @@ -46,4 +46,4 @@ export { ComplexValidateDualPopInformation } from "./ComplexValidations/ComplexV export { ComplexValueSameCrossCategory, ComplexValueSameCrossCategoryOMS, -} from "./ComplexValidations/ComplexValueSameCrossCategory"; +} from "shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; 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 b96fbd0309..be498ef89f 100644 --- a/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx +++ b/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx @@ -24,7 +24,7 @@ import * as ComplexAtLeastOneRateComplete from "shared/globalValidations/Complex import * as ComplexNoNonZeroNumOrDenom from "measures/2023/shared/globalValidations/ComplexValidations/ComplexNoNonZeroNumOrDenom"; import * as ComplexValidateNDRTotals from "measures/2023/shared/globalValidations/ComplexValidations/ComplexValidateNDRTotals"; import * as ComplexValidateDualPopInformation from "measures/2023/shared/globalValidations/ComplexValidations/ComplexValidateDualPopInformation"; -import * as ComplexValueSameCrossCategory from "measures/2023/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; +import * as ComplexValueSameCrossCategory from "shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; import { DefaultFormData } from "shared/types/FormData"; /** diff --git a/services/ui-src/src/measures/2024/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx b/services/ui-src/src/measures/2024/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx deleted file mode 100644 index a7c536c968..0000000000 --- a/services/ui-src/src/measures/2024/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx +++ /dev/null @@ -1,110 +0,0 @@ -import { LabelData } from "utils"; - -export const ComplexValueSameCrossCategoryOMS = ( - rateData: any, - categories: LabelData[], - qualifiers: LabelData[], - errorLocation: string -) => { - // Using a subset of rateData as iterator to be sure that Total - // is always at the end of the category array. - const qualifierObj = { ...rateData }; - delete qualifierObj["Total"]; - const totalData = rateData["Total"]; // quick reference variable - - const qualifierLabels: any = {}; - for (const q of qualifiers) { - qualifierLabels[q.id] = q.label; - } - - // build performanceMeasureArray - let performanceMeasureArray = []; - for (const cat of categories) { - let row = []; - for (const q in qualifierObj) { - const qual = qualifierObj[q]?.[cat.id]?.[0]; - if (qual) { - qual.label = qualifierLabels[q]; - row.push(qual); - } - } - // only need to add total data if other data exists - if (row.length > 0) { - const catTotal = { ...totalData[cat.id][0] }; - catTotal.label = "Total"; - row.push(catTotal); - performanceMeasureArray.push(row); - } - } - - let errorArray: any[] = ComplexValueSameCrossCategory({ - rateData: performanceMeasureArray, - OPM: undefined, - errorLocation, - }); - return errorArray; -}; - -interface Props { - rateData: any; - OPM: any; - fieldIndex?: number; - fieldLabel?: string; - errorLocation?: string; -} - -/* - * Validate that the value of a given field with a given qualifier is consistent - * across all measurement categories. - * - * Ex - "Number of Enrollee Months" in Inpatient ages 0-17 === Medicine ages 0-17 - */ -export const ComplexValueSameCrossCategory = ({ - rateData, - OPM, - fieldIndex = 0, - fieldLabel = "Number of Enrollee Months", - errorLocation = "Performance Measure/Other Performance Measure", -}: Props) => { - let errorArray: any[] = []; - if (!OPM) { - const tempValues: { - [cleanedQualifier: string]: { - value: string; - label: string; - error?: boolean; - }; - } = {}; - for (const category of rateData) { - for (const qualifier of category.slice(0, -1)) { - const cleanQual = qualifier.uid.split(".")[1]; - if (tempValues[cleanQual]?.value) { - if ( - qualifier.fields[fieldIndex]?.value && - tempValues[cleanQual].value !== qualifier.fields[fieldIndex]?.value - ) { - // Set an error if the qualifier does not match tempValues - tempValues[cleanQual].error = true; - } - } else { - // Set tempValues[cleanQual] to be used in future checks against other qualifiers - tempValues[cleanQual] = { - value: qualifier.fields[fieldIndex]?.value, - label: qualifier.label, - }; - } - } - } - - // Using tempValues as a reference prevents multiple error messages per qualifier - for (const tempValue in tempValues) { - if (tempValues[tempValue]?.error) { - errorArray.push({ - errorLocation, - errorMessage: `Value of "${fieldLabel}" in ${tempValues[tempValue].label} must be the same across all measurement categories.`, - }); - } - } - } - return errorArray; -}; 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 9ebc576fec..9d57385b86 100644 --- a/services/ui-src/src/measures/2024/shared/globalValidations/index.ts +++ b/services/ui-src/src/measures/2024/shared/globalValidations/index.ts @@ -48,4 +48,4 @@ export { ComplexValidateDualPopInformation } from "./ComplexValidations/ComplexV export { ComplexValueSameCrossCategory, ComplexValueSameCrossCategoryOMS, -} from "./ComplexValidations/ComplexValueSameCrossCategory"; +} from "shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; 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 eb4ebce901..70ee4f6e8d 100644 --- a/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx +++ b/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx @@ -24,7 +24,7 @@ import * as ComplexAtLeastOneRateComplete from "shared/globalValidations/Complex import * as ComplexNoNonZeroNumOrDenom from "measures/2024/shared/globalValidations/ComplexValidations/ComplexNoNonZeroNumOrDenom"; import * as ComplexValidateNDRTotals from "measures/2024/shared/globalValidations/ComplexValidations/ComplexValidateNDRTotals"; import * as ComplexValidateDualPopInformation from "measures/2024/shared/globalValidations/ComplexValidations/ComplexValidateDualPopInformation"; -import * as ComplexValueSameCrossCategory from "measures/2024/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; +import * as ComplexValueSameCrossCategory from "shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory"; import { DefaultFormData } from "shared/types/FormData"; /** diff --git a/services/ui-src/src/measures/2023/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx b/services/ui-src/src/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx similarity index 95% rename from services/ui-src/src/measures/2023/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx rename to services/ui-src/src/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx index a7c536c968..c209a12b8f 100644 --- a/services/ui-src/src/measures/2023/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx +++ b/services/ui-src/src/shared/globalValidations/ComplexValidations/ComplexValueSameCrossCategory/index.tsx @@ -1,4 +1,4 @@ -import { LabelData } from "utils"; +import { isLegacyLabel, LabelData } from "utils"; export const ComplexValueSameCrossCategoryOMS = ( rateData: any, @@ -77,7 +77,9 @@ export const ComplexValueSameCrossCategory = ({ } = {}; for (const category of rateData) { for (const qualifier of category.slice(0, -1)) { - const cleanQual = qualifier.uid.split(".")[1]; + const cleanQual = isLegacyLabel() + ? qualifier.id + : qualifier.uid.split(".")[1]; if (tempValues[cleanQual]?.value) { if ( qualifier.fields[fieldIndex]?.value &&