-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathindex.ts
212 lines (183 loc) · 7.47 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Libraries
import * as fse from 'fs-extra';
import * as path from 'path';
import * as YAML from 'yaml';
import { Constants } from './constants';
import { ProgramNames, ProgramNamesEnum } from './util/interfaces/program-names';
import { BenchmarksData } from './util/interfaces/benchmarks';
import { BenchmarksExclusionReasons } from './util/interfaces/benchmarks-exclusion-reasons';
import { CostNationalAverage } from './util/interfaces/cost-national-average';
import { Measure } from './util/interfaces/measure';
import { ClinicalCluster } from './scripts/clinical-clusters/clinical-cluster.types';
import { MVPData, MVPDataSlim } from './util/interfaces/mvp';
import { createMVPDataFile } from './util/mvp-data-utils';
const yearRegEx = /^[0-9]{4}/;
const benchmarkJsonFileRegEx = /^[0-9]{4}\.json$/;
__dirname = __dirname.replace('/dist', '');
__dirname = __dirname.replace('\\dist', '');
/**
* @return {Array<number>}
* An array of all the years that the library has data for
*/
export function getValidPerformanceYears(): number[] {
return Constants.validPerformanceYears;
}
/**
*
* @return {ProgramNames} - program names -
* An object keyed by program name containing the current program names
*/
export function getProgramNames(): ProgramNames {
const programNamesFilePath = path.join(__dirname, 'util/program-names', 'program-names.json');
try {
return JSON.parse(fse.readFileSync(programNamesFilePath, 'utf8'));
} catch (e) {
console.log('Error parsing the program-names.json file: ' + ' --> ' + e);
return <ProgramNames>{}
}
}
/**
*
* @return {typeof ProgramNamesEnum} - program names -
* An Enum containing all program names.
* This is an "all-encompassing" list containing past and present program-name values.
* IE, this enum is not performance-year conscious.
*/
export function getProgramNamesEnum(): typeof ProgramNamesEnum {
return ProgramNamesEnum;
}
/**
*
* @return {BenchmarksData} - benchmarks data -
* An object keyed by performance year with array values
* containing the benchmarks for that performance year
*/
export function getBenchmarksData(): BenchmarksData {
const benchmarksByYear: any = {};
getBenchmarksYears().forEach(function (year) {
benchmarksByYear[year] = JSON.parse(fse.readFileSync(path.join(__dirname, 'benchmarks', `${year}.json`), 'utf8'));
});
return benchmarksByYear;
}
/**
*
* @return {Array<number>}
* An array of years that the library has benchmarks for
*/
export function getBenchmarksYears(): number[] {
const benchmarksYears = new Set<number>();
fse.readdirSync(path.join(__dirname, 'benchmarks')).forEach(function (file) {
const match = file.match(yearRegEx);
if (benchmarkJsonFileRegEx.test(file) && match) {
benchmarksYears.add(+match[0]);
}
});
return Array.from(benchmarksYears);
}
/**
* @return {any} - Object representation of the Benchmarks Schema
*/
export function getBenchmarksSchema(performanceYear: number = Constants.currentPerformanceYear): any {
return YAML.parse(fse.readFileSync(path.join(__dirname, 'benchmarks', performanceYear.toString(), 'benchmarks-schema.yaml'), 'utf8'));
}
/**
* @param {number} performanceYear - The performance year to get the exclusion reasons for.
* @return {BenchmarksExclusionReasons[]} - The exclusion reasons for the given performance year.
**/
export function getBenchmarksExclusionReasons(performanceYear: number = Constants.currentPerformanceYear): BenchmarksExclusionReasons[] {
return JSON.parse(
fse.readFileSync(path.join(__dirname, 'benchmarks', performanceYear.toString(), 'benchmark-exclusion-reasons.json'), 'utf8'));
}
/**
* @param {number} performanceYear - The performance year to get the national averages for.
* @return {CostNationalAverage[]} - The national averages for the given performance year.
**/
export function getBenchmarksNationalAverages(performanceYear: number = Constants.currentPerformanceYear): CostNationalAverage[] {
return JSON.parse(
fse.readFileSync(path.join(__dirname, 'benchmarks', performanceYear.toString(), 'cost-national-averages.json'), 'utf8'));
}
/**
* @return {any} - Object representation of the National Averages Schema
*/
export function getBenchmarksNationalAveragesSchema(performanceYear: number = Constants.currentPerformanceYear): any {
return YAML.parse(fse.readFileSync(path.join(__dirname, 'benchmarks', performanceYear.toString(), 'cost-national-averages-schema.yaml'), 'utf8'));
}
/**
* @param {number} performanceYear - The performance year for which to load the measures data.
* @return {Measure[]} An array of measure objects conforming to the Measure type definition.
**/
export function getMeasuresData(performanceYear: number = 2017): Measure[] {
return JSON.parse(
fse.readFileSync(path.join(__dirname, 'measures', performanceYear.toString(), 'measures-data.json'), 'utf8'));
}
/**
* @return {any} - Object representation of the Measures Schema
*/
export function getMeasuresSchema(performanceYear: number = 2017): any {
return YAML.parse(fse.readFileSync(path.join(__dirname, 'measures', performanceYear.toString(), 'measures-schema.yaml'), 'utf8'));
}
/**
* @param {number} performanceYear - The performance year for which to load the clinical cluster data.
* * @return {ClinicalCluster[]} An array of cluster objects conforming to the ClinicalCluster definition.
**/
export function getClinicalClusterData(performanceYear: number = 2017): ClinicalCluster[] {
let clusterData: any[] = [];
try {
clusterData = JSON.parse(
fse.readFileSync(path.join(__dirname, 'clinical-clusters', performanceYear.toString(), 'clinical-clusters.json'), 'utf8'));
} catch (e) {
console.log('QPP measures data not found for year: ' + performanceYear + ' --> ' + e);
}
return clusterData;
}
/**
* @return {any} - Object representation of the Clinical Cluster Schema
*/
export function getClinicalClusterSchema(performanceYear: number = 2023): any {
return YAML.parse(fse.readFileSync(path.join(__dirname, 'clinical-clusters', performanceYear.toString(), 'clinical-clusters-schema.yaml'), 'utf8'));
}
/**
* @return {MVPData[]}
*/
export function getMVPData(performanceYear: number = 2023, mvpIds: string[] = []): MVPData[] {
const filePath = path.join(__dirname, 'mvp', performanceYear.toString(), 'mvp-enriched.json');
let mvpData: any;
if (fse.existsSync(filePath)) {
mvpData = JSON.parse(fse.readFileSync(filePath, 'utf8'));
} else {
mvpData = createMVPDataFile(performanceYear);
}
if (mvpIds.length) {
mvpData = mvpData.filter(mvpDataItem => mvpIds.includes(mvpDataItem.mvpId));
}
return mvpData;
}
/**
* @return {any} - Object representation of the MVP Schema
*/
export function getMVPSchema(performanceYear: number = 2023): any {
return YAML.parse(fse.readFileSync(path.join(__dirname, 'mvp', performanceYear.toString(), 'mvp-schema.yaml'), 'utf8'));
}
/**
* @return {MVPDataSlim[]}
*/
export function getMVPDataSlim(performanceYear: number = 2023): MVPDataSlim[] {
const filePath = path.join(__dirname, 'mvp', performanceYear.toString(), 'mvp.json');
let mvpData: any;
if (fse.existsSync(filePath)) {
mvpData = JSON.parse(fse.readFileSync(filePath, 'utf8'));
mvpData.forEach((mvp: any) => {
mvp.measureIds = [].concat(
mvp.qualityMeasureIds,
mvp.iaMeasureIds,
mvp.costMeasureIds,
mvp.foundationPiMeasureIds,
mvp.foundationQualityMeasureIds,
mvp.administrativeClaimsMeasureIds
);
});
} else {
console.log('mvp.json file does not exist');
}
return mvpData;
}