forked from smart-on-fhir/bulk-data-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbulk_data_handler.js
110 lines (85 loc) · 3.72 KB
/
bulk_data_handler.js
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
const express = require("express");
const cors = require("cors");
const Lib = require("./lib");
const OpDef = require("./fhir/OperationDefinition/index");
const bulkImporter = require("./import/bulk_data_import_handler");
const ExportManager = require("./ExportManager");
const router = express.Router({ mergeParams: true });
const jsonTypes = [
"application/json",
"application/fhir+json",
"application/json+fhir"
];
// Start helper express middlewares --------------------------------------------
function extractSim(req, res, next) {
req.sim = Lib.getRequestedParams(req);
next();
}
// =============================================================================
// BulkData Export Endpoints
// =============================================================================
// System Level Export
// Export data from a FHIR server whether or not it is associated with a patient.
// This supports use cases like backing up a server or exporting terminology
// data by restricting the resources returned using the _type parameter.
router.route("/\\$export")
.post(express.json({ type: jsonTypes }))
.all(
extractSim,
Lib.requireFhirJsonAcceptHeader,
Lib.requireRespondAsyncHeader,
Lib.checkAuth,
ExportManager.createKickOffHandler(true)
);
// /Patient/$export - Returns all data on all patients
// /$export - does the same on this server because we don't
router.route(["/Patient/\\$export", "/group/:groupId/\\$export"])
.post(express.json({ type: jsonTypes }))
.all(
extractSim,
Lib.requireFhirJsonAcceptHeader,
Lib.requireRespondAsyncHeader,
Lib.checkAuth,
ExportManager.createKickOffHandler()
);
// This is the endPoint that should provide progress information
router.get("/bulkstatus/:id", [
Lib.checkAuth,
ExportManager.createStatusHandler()
]);
// The actual file downloads
router.get("/bulkfiles/:file", [
extractSim,
Lib.checkAuth,
ExportManager.createDownloadHandler()
]);
router.delete("/bulkstatus/:id", [
extractSim,
Lib.checkAuth,
ExportManager.createCancelHandler()
]);
// =============================================================================
// BulkData Import Endpoints
// =============================================================================
// Return import progress by task id generated during kick-off request
// and provide time interval for client to wait before checking again
router.get("/import-status/:taskId", bulkImporter.createImportStatusHandler());
// Stop an import that has not completed
router.delete("/import-status/:taskId", bulkImporter.cancelImport);
// Kick-off import
router.post("/\\$import", bulkImporter.createImportKickOffHandler());
// =============================================================================
// FHIR/Other Endpoints
// =============================================================================
// host dummy conformance statement
router.get("/metadata", cors({ origin: true }), extractSim, require("./fhir/metadata"));
// list all the groups with their IDs and the number of patients included
router.get("/Group", cors({ origin: true }), require("./fhir/group"));
router.get("/\\$get-patients", cors({ origin: true }), require("./fhir/patient"));
// $get-resource-counts operation
router.get("/\\$get-resource-counts", cors({ origin: true }), require("./fhir/get-resource-counts"));
// operation definitions
router.use("/OperationDefinition", cors({ origin: true }), OpDef);
// router.get("/files/", Lib.checkAuth, express.static(__dirname + "/attachments"));
router.use('/attachments', cors({ origin: true }), extractSim, Lib.checkAuth, express.static(__dirname + "/attachments"));
module.exports = router;