Skip to content

Commit

Permalink
QPPA-1606: Ingest 2018 IA measures (#126)
Browse files Browse the repository at this point in the history
This PR adds a script for ingesting the 2018 IA measures from the source CSV file. This adds the source CSV file, the script that parses that CSV, the staging IA measures, the changes to the build-measures script, and the changes to the final measures. 

Also added some simple tests for IA measures (seems like there weren't any in 2017) as well as tests for the ingestion script and updating the merge-measures tests to use IA measures.

Reviewers: @kalvinwang @kencheeto
  • Loading branch information
samskeller authored May 30, 2018
1 parent ec9a3d0 commit 2e7b083
Show file tree
Hide file tree
Showing 16 changed files with 4,631 additions and 26 deletions.
1,356 changes: 1,356 additions & 0 deletions measures/2018/measures-data.json

Large diffs are not rendered by default.

1,451 changes: 1,451 additions & 0 deletions measures/2018/measures-data.xml

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qpp-measures-data",
"version": "1.1.1",
"version": "1.1.2",
"description": "Quality Payment Program Measures Data Repository",
"repository": {
"type": "git",
Expand Down
79 changes: 79 additions & 0 deletions scripts/measures/2018/import-ia-measures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const parse = require('csv-parse/lib/sync');
const _ = require('lodash');
const fs = require('fs');
const path = require('path');

const Constants = require('../../../constants.js');
/**
* `import-ia-measures` reads an IA CSV file and creates valid measures,
* then writes the resulting json to a staging measures-data-ia.js file.
*/

const IA_CSV_COLUMN_NAMES = {
'Activity Name': 'title',
'Activity Description': 'description',
'Activity ID': 'measureId',
'metricType': 'metricType',
'firstPerformanceYear': 'firstPerformanceYear',
'lastPerformanceYear': 'lastPerformanceYear',
'weight': 'weight',
'subcategoryId': 'subcategoryId',
'cehrtEligible': 'cehrtEligible'
};

// Accounts for TRUE, True, true, X, x...
// and people sometimes insert extra spaces
function cleanInput(input) {
return input.trim().toLowerCase();
}

// map specific csv input values to their representation in the measures schema
function mapInput(rawInput) {
const input = cleanInput(rawInput);
if (input === '' || input === 'null') {
return null;
} else if (input === 'true') {
return true;
} else if (input === 'false') {
return false;
} else if (Constants.validPerformanceYears.includes(Number(input))) {
return Number(input);
} else {
return rawInput.trim();
}
}

/**
* [convertIaCsvsToMeasures description]
* @param {array of objects} each object in the array represents
* a new measure (row)
* @return {array} Returns an array of measures objects
*
* Note: We trim all data sourced from CSVs because people sometimes unintentionally
* include spaces or linebreaks
*/
function convertIaCsvsToMeasures(iaCSVRows) {
return iaCSVRows.map((row) => {
const measure = {};
_.each(IA_CSV_COLUMN_NAMES, (measureKeyName, columnName) => {
measure[measureKeyName] = mapInput(row[columnName]);
measure['category'] = 'ia';
});
return measure;
});
}

function importIaMeasures(iaMeasuresPath, outputPath) {
const csv = fs.readFileSync(path.join(__dirname, iaMeasuresPath), 'utf8');
const iaCSV = parse(csv, {columns: true});

const iaMeasures = convertIaCsvsToMeasures(iaCSV);
const iaMeasuresJSON = JSON.stringify(iaMeasures, null, 2);

fs.writeFileSync(path.join(__dirname, outputPath), iaMeasuresJSON);
}

const iaMeasuresPath = process.argv[2];
const outputPath = process.argv[3];

importIaMeasures(iaMeasuresPath, outputPath);
2 changes: 1 addition & 1 deletion scripts/measures/2018/merge-measures-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');

const outputPath = process.argv[4];
const outputPath = process.argv[process.argv.length - 1];

function mergeMeasures() {
const allJson = [];
Expand Down
8 changes: 7 additions & 1 deletion scripts/measures/build-measures
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ quality_strata='../../../util/measures/'$currentPerformanceYear'/quality-strata.
quality_measures='../../../staging/'$currentPerformanceYear'/measures-data-quality.json'
pi_json='../../../util/measures/'$currentPerformanceYear'/pi-measures.json'
pi_measures='../../../staging/'$currentPerformanceYear'/measures-data-pi.json'
ia_csv='../../../util/measures/'$currentPerformanceYear'/ia-measures.csv'
ia_measures='../../../staging/'$currentPerformanceYear'/measures-data-ia.json'
final_measures='../../../measures/'$currentPerformanceYear'/measures-data.json'

# 0a. Add quality measures to the staging measures-data-quality.json file:
Expand All @@ -26,13 +28,17 @@ node scripts/measures/$currentPerformanceYear/import-quality-measures.js \
cat util/measures/$currentPerformanceYear/pi-measures.json > \
staging/$currentPerformanceYear/measures-data-pi.json

# 0c. Add IA measures to the staging measures-data-ia.json file:
node scripts/measures/$currentPerformanceYear/import-ia-measures.js \
$ia_csv $ia_measures

# TODO: Enrich `measures-data.json` file, run:
# node scripts/measures/enrich-measures-data.js \
# $staging_measures_with_qcdrs $final_measures

# 1. Merge the array/jsonfile-per-measureType into a combined array of all measures
node scripts/measures/$currentPerformanceYear/merge-measures-data.js \
$quality_measures $pi_measures \
$quality_measures $pi_measures $ia_measures \
$final_measures

# 2. To regenerate the `measures-data.xml` file, run:
Expand Down
Loading

0 comments on commit 2e7b083

Please sign in to comment.