-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadMeasures.ts
75 lines (68 loc) · 2.29 KB
/
loadMeasures.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
import { logger } from '../common/logger';
import * as fs from 'fs';
export function loadMeasureBundle(
directoryPath: string,
filenames: string[]
): { fileName: string; json: string }[] {
const jsons: { fileName: string; json: string }[] = [];
logger.info('Loading input FHIR measure library from : ' + directoryPath);
let fileCnt = 0;
if (filenames.length > 0) {
filenames.forEach(oneFile => {
if (oneFile.includes('.json')) {
logger.info('Loading file: ' + oneFile);
const json = fs.readFileSync(directoryPath + oneFile, { encoding: 'utf8', flag: 'r' });
if (JSON.parse(json).resourceType === 'Bundle') {
fileCnt++;
jsons.push({ fileName: oneFile, json: json });
}
}
});
} else {
const files = fs.readdirSync(directoryPath);
files.forEach(function (oneFile) {
if (oneFile.includes('.json')) {
const json = fs.readFileSync(directoryPath + oneFile, {
encoding: 'utf8',
flag: 'r'
});
if (JSON.parse(json).resourceType === 'Bundle') {
logger.info('Loading file: ' + oneFile);
fileCnt++;
jsons.push({ fileName: oneFile, json: json });
}
}
});
}
logger.info('Loaded ' + fileCnt + ' files');
return jsons;
}
export function loadMeasureLibraryFromDir(
directoryPath: string,
filenames: string[]
): { fileName: string; json: string }[] {
const jsons: { fileName: string; json: string }[] = [];
const files = fs.readdirSync(directoryPath);
let fileCnt = 0;
files.forEach(function (f) {
if (f.includes('.json')) {
if (filenames.includes(f) || filenames.length == 0) {
logger.info('Loading file: ' + f);
fileCnt++;
const json = fs.readFileSync(directoryPath + f, { encoding: 'utf8', flag: 'r' });
if (JSON.parse(json).resourceType === 'Library') {
jsons.push({ fileName: f, json: json });
}
if (JSON.parse(json).resourceType === 'Bundle') {
const entry = JSON.parse(json).entry;
entry.forEach((e: any) => {
if (e.resource.resourceType === 'Library')
jsons.push({ fileName: f, json: JSON.stringify(e.resource) });
});
}
}
}
});
logger.info('Loaded ' + fileCnt + ' files');
return jsons;
}