Skip to content

Commit

Permalink
Merge pull request #877 from CMSgov/QPPA-9758-measures-repo
Browse files Browse the repository at this point in the history
QPPA-9758: create script to manage allowed program
  • Loading branch information
chetanmunegowda authored Dec 27, 2024
2 parents 20c8b13 + 45a49fc commit 515c2b3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ The strata are modified by updating the qcdr and quality strata CSVs in the year

The specification links are added by placing the CSV or JSON files into the year's util directory, then running `npm run init:measures $YEAR`.

### Managing Allowed Programs for Measures

The `manage:allowed-programs` script enables adding or removing a program from the `allowedPrograms` field of all measures in a specific category for a given performance year. This is especially useful for bulk updates, such as adding a new program or making uniform changes across multiple measures.

```bash
npm run manage:allowed-programs -- <performanceYear> <category> <program> <add|remove>
````
Example: To remove the program `pcf` from all `ia` category measures for the year `2024`:
```bash
npm run manage:allowed-programs -- 2024 ia pcf remove
````
### Importing Measures from a CSV File
To handle UTF-8 encoding, make sure that you save any new csv from excel as `CSV UTF-8 (Comma delimited) (.csv)`. This will keep Unknown Characters out of the data set.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"update:mvp": "scripts/mvp/update-mvp",
"parse:mvp": "scripts/mvp/parse-mvp-data",
"export:measures": "bash scripts/measures/export-measures",
"manage:allowed-programs": "node dist/scripts/measures/manage-allowed-programs.js",
"pretest": "npm run lint",
"lint": "eslint scripts index.spec.ts",
"lint:fix": "eslint scripts index.spec.ts --fix",
Expand Down
79 changes: 79 additions & 0 deletions scripts/measures/manage-allowed-programs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import fs from 'fs-extra';
import path from 'path';
import appRoot from 'app-root-path';

// Function to update allowedPrograms for a specific category
export function updateAllowedPrograms(
performanceYear: string,
category: string,
program: string,
action: 'add' | 'remove',
) {
const measuresPath = `measures/${performanceYear}/measures-data.json`;

try {
// Load the measures data
const measuresJson: any[] = JSON.parse(
fs.readFileSync(path.join(appRoot.toString(), measuresPath), 'utf8')
);

let updatedMeasures = 0;

// Update measures in the specified category
measuresJson.forEach((measure) => {
if (measure.category === category) {
const allowedPrograms: string[] = measure.allowedPrograms || [];

if (action === 'add') {
// Add program if it doesn't already exist
if (!allowedPrograms.includes(program)) {
allowedPrograms.push(program);
measure.allowedPrograms = allowedPrograms;
updatedMeasures++;
console.log(`Added program "${program}" to measure "${measure.measureId}".`);
}
} else if (action === 'remove') {
// Remove program if it exists
const index = allowedPrograms.indexOf(program);
if (index !== -1) {
allowedPrograms.splice(index, 1);
measure.allowedPrograms = allowedPrograms;
updatedMeasures++;
console.log(`Removed program "${program}" from measure "${measure.measureId}".`);
}
}
}
});

// Save the updated measures data back to the file
if (updatedMeasures > 0) {
fs.writeFileSync(
path.join(appRoot.toString(), measuresPath),
JSON.stringify(measuresJson, null, 2)
);
console.log(`${updatedMeasures} measures updated successfully.`);
} else {
console.log(`No measures required updates.`);
}
} catch (err) {
console.error(`Failed to update measures: ${(err as Error).message}`);
}
}

if (require.main === module) {
const args = process.argv.slice(2);

if (args.length !== 4) {
console.error('Usage: node updateAllowedPrograms.js <performanceYear> <category> <program> <add|remove>');
process.exit(1);
}

const [performanceYear, category, program, action] = args;

if (!['add', 'remove'].includes(action)) {
console.error('Invalid action. Use "add" or "remove".');
process.exit(1);
}

updateAllowedPrograms(performanceYear, category, program, action as 'add' | 'remove');
}
4 changes: 2 additions & 2 deletions updates/measures/2025/changes.meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"PI_PY25_CR_20241112.csv",
"Quality_QCDR_PY25_CR_20241205.csv",
"Cost_Measures_PY225_20241223.csv",
"Cost_Measures_PY225_CR_20241223.csv"
"Cost_Measures_PY225_CR_20241223.csv",
"Quality_PY2025_DWH_Repo Compare Updates_CR_12182024.csv"
]
]

0 comments on commit 515c2b3

Please sign in to comment.