forked from OHDSI/WebAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.js
More file actions
51 lines (44 loc) · 1.5 KB
/
Copy pathsource.js
File metadata and controls
51 lines (44 loc) · 1.5 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
import { Router } from 'express'
import { getAllSourceInfos, toSourceInfo, getSource } from '../sources.js'
import config from '../config.js'
const router = Router()
// List all sources
router.get('/sources', (req, res) => {
res.json(getAllSourceInfos())
})
// Refresh endpoint — no-op in our static config model
router.get('/refresh', (req, res) => {
res.json(getAllSourceInfos())
})
// Priority vocabulary source — first source that has a Vocabulary daimon
router.get('/priorityVocabulary', (req, res) => {
const idx = config.sources.findIndex(s => s.vocabSchema)
if (idx === -1) return res.status(404).json({ message: 'No vocabulary source configured' })
res.json(toSourceInfo(config.sources[idx], idx))
})
// Priority source per daimon type — returns { CDM: SourceInfo, Vocabulary: SourceInfo, ... }
router.get('/daimon/priority', (req, res) => {
const result = {}
const daimonChecks = [
['CDM', s => s.cdmSchema],
['Vocabulary', s => s.vocabSchema],
['Results', s => s.resultsSchema],
['Temp', s => s.tempSchema],
]
for (const [type, hasDaimon] of daimonChecks) {
const idx = config.sources.findIndex(hasDaimon)
if (idx !== -1) result[type] = toSourceInfo(config.sources[idx], idx)
}
res.json(result)
})
// Single source by key
router.get('/:key', (req, res, next) => {
try {
const source = getSource(req.params.key)
const idx = config.sources.indexOf(source)
res.json(toSourceInfo(source, idx))
} catch (err) {
next(err)
}
})
export default router