-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump_mocks.js
More file actions
63 lines (59 loc) · 1.62 KB
/
dump_mocks.js
File metadata and controls
63 lines (59 loc) · 1.62 KB
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
const fs = require("fs");
const path = require("path");
const endpoints = [
"/api/catalog",
"/api/graph",
"/api/compliance",
"/api/patient",
"/api/analytics",
"/api/eehrxf",
];
async function dump() {
const mockDir = path.join(__dirname, "ui", "public", "mock");
if (!fs.existsSync(mockDir)) {
fs.mkdirSync(mockDir, { recursive: true });
}
for (const ep of endpoints) {
console.log(`Fetching ${ep}...`);
try {
const res = await fetch(`http://localhost:3000${ep}`);
if (!res.ok) {
console.error(`Failed to fetch ${ep}: HTTP ${res.status}`);
continue;
}
const data = await res.json();
const filename = ep.replace("/api/", "") + ".json";
fs.writeFileSync(
path.join(mockDir, filename),
JSON.stringify(data, null, 2),
);
if (ep === "/api/patient" && Array.isArray(data) && data.length > 0) {
const firstId = data[0].id;
console.log(`Fetching patient details for ${firstId}...`);
const pRes = await fetch(
`http://localhost:3000/api/patient?patientId=${encodeURIComponent(
firstId,
)}`,
);
if (pRes.ok) {
const pData = await pRes.json();
fs.writeFileSync(
path.join(mockDir, "patient_default.json"),
JSON.stringify(
{
id: firstId,
data: pData,
},
null,
2,
),
);
}
}
} catch (err) {
console.error(`Failed to fetch ${ep}:`, err.message);
}
}
console.log("Mock data dump complete.");
}
dump();