Skip to content

Commit

Permalink
BOT-14 Add Metadata routes (#95)
Browse files Browse the repository at this point in the history
* Added paths for metadata

* Test update
  • Loading branch information
pmanko authored Jan 17, 2024
1 parent dc7c39d commit 1bd6171
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 66 deletions.
1 change: 0 additions & 1 deletion .eslintcache

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"@types/node": "^14.11.10",
"@types/request": "^2.48.7",
"@types/sprintf-js": "^1.1.2",
"@types/supertest": "^6.0.2",
"@types/swagger-jsdoc": "^6.0.1",
"@types/swagger-ui-express": "^4.1.3",
"@types/urijs": "^1.19.19",
Expand Down
22 changes: 22 additions & 0 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
'use strict'
import config from "../lib/config"
import { Request, Response } from "express"
import got from "got"
import logger from "../lib/winston"


export function invalidBundle(resource: any): boolean {
Expand All @@ -25,3 +29,21 @@ export function invalidBundleMessage(): any {
},
}
}
export function getMetadata(): any {
return async (req: Request, res: Response) => {
const targetUri = config.get('fhirServer:baseURL') + '/metadata'
logger.info(`Getting ${targetUri}`)

const options = {
username: config.get('fhirServer:username'),
password: config.get('fhirServer:password'),
}

try {
const result = await got.get(targetUri, options).json()
res.status(200).json(result)
} catch (error) {
return res.status(500).json(error)
}
}
}
20 changes: 20 additions & 0 deletions src/routes/__tests__/fhir.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import request from 'supertest'
import express from 'express'
import { router } from '../fhir'

const app = express()
app.use('/', router)

describe('FHIR Routes', () => {
it.skip('should return 200 OK for GET /metadata', async () => {
const response = await request(app).get('/metadata')
expect(response.status).toBe(200)
})

it.skip('should return 400 Bad Request for GET with invalid resource type', async () => {
const response = await request(app).get('/invalid-resource')
expect(response.status).toBe(400)
expect(response.body).toEqual({ message: 'Invalid resource type invalid-resource' })
})

})
17 changes: 17 additions & 0 deletions src/routes/__tests__/ips.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import request from 'supertest'
import express from 'express'
import { router } from '../ips'

const app = express()
app.use('/', router)

describe('IPS Routes', () => {

it.skip('should return 200 OK for GET /metadata', async () => {


const response = await request(app).get('/metadata')

expect(response.status).toBe(200)
})
})
5 changes: 4 additions & 1 deletion src/routes/fhir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import { invalidBundle, invalidBundleMessage } from '../lib/helpers'
import logger from '../lib/winston'
import { generateSimpleIpsBundle } from '../workflows/ipsWorkflows'
import { getResourceTypeEnum, isValidResourceType } from '../lib/validate'
import { getMetadata } from '../lib/helpers'

export const router = express.Router()

router.get('/', (req: Request, res: Response) => {
return res.status(200).send(req.url)
})

router.get('/:resource/:id?/:operation?', async (req, res) => {
router.get('/metadata', getMetadata())

router.get('/:resource/:id?/:operation?', async (req: Request, res: Response) => {
let result = {}
try {
let uri = URI(config.get('fhirServer:baseURL'))
Expand Down
8 changes: 5 additions & 3 deletions src/routes/ips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import fhirClient from 'fhirclient'
import config from '../lib/config'
import logger from '../lib/winston'
import { generateIpsbundle, generateUpdateBundle } from '../workflows/ipsWorkflows'
import { sprintf } from 'sprintf-js'
import { getMetadata } from '../lib/helpers'

export const router = express.Router()

import { sprintf } from 'sprintf-js'

const system = config.get('app:mpiSystem')

router.get('/', (req: Request, res: Response) => {
return res.status(200).send(req.url)
})

router.get('/metadata', getMetadata())

router.get('/Patient/cruid/:id/:lastUpdated?', async (req: Request, res: Response) => {
const cruid = req.params.id
const lastUpdated = req.params.lastUpdated
Expand Down Expand Up @@ -134,7 +136,7 @@ router.get('/:location?/:lastUpdated?', (req: Request, res: Response) => {
* 5. Combine them into a single bundle w/ composition
*
*/

const patientP = client.request<R4.IPatient[]>(`Patient?${query}`, {
flat: true,
})
Expand Down
61 changes: 0 additions & 61 deletions src/server/__tests__/mllpAdapter.ts

This file was deleted.

36 changes: 36 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,13 @@ __metadata:
languageName: node
linkType: hard

"@types/cookiejar@npm:^2.1.5":
version: 2.1.5
resolution: "@types/cookiejar@npm:2.1.5"
checksum: 04d5990e87b6387532d15a87d9ec9b2eb783039291193863751dcfd7fc723a3b3aa30ce4c06b03975cba58632e933772f1ff031af23eaa3ac7f94e71afa6e073
languageName: node
linkType: hard

"@types/express-serve-static-core@npm:^4.17.33":
version: 4.17.41
resolution: "@types/express-serve-static-core@npm:4.17.41"
Expand Down Expand Up @@ -1304,6 +1311,13 @@ __metadata:
languageName: node
linkType: hard

"@types/methods@npm:^1.1.4":
version: 1.1.4
resolution: "@types/methods@npm:1.1.4"
checksum: ad2a7178486f2fd167750f3eb920ab032a947ff2e26f55c86670a6038632d790b46f52e5b6ead5823f1e53fc68028f1e9ddd15cfead7903e04517c88debd72b1
languageName: node
linkType: hard

"@types/mime-db@npm:*":
version: 1.43.4
resolution: "@types/mime-db@npm:1.43.4"
Expand Down Expand Up @@ -1478,6 +1492,27 @@ __metadata:
languageName: node
linkType: hard

"@types/superagent@npm:^8.1.0":
version: 8.1.1
resolution: "@types/superagent@npm:8.1.1"
dependencies:
"@types/cookiejar": ^2.1.5
"@types/methods": ^1.1.4
"@types/node": "*"
checksum: 02b987833cf0d85da9b137fd296fe8ad25a470d60f7e9d81a6ed3f8f8a5d6bace8780816bd35885e2928f467e819a4aa509879a7da0f28018ab1453845eb91e2
languageName: node
linkType: hard

"@types/supertest@npm:^6.0.2":
version: 6.0.2
resolution: "@types/supertest@npm:6.0.2"
dependencies:
"@types/methods": ^1.1.4
"@types/superagent": ^8.1.0
checksum: 1eafa472665757a6fd984439d11f388ae0480c6d243a6884066c474c4e0357de5373316488da503b1690c3163e075ca8c64c0c4853b3bb7deb09e05d1b64e556
languageName: node
linkType: hard

"@types/swagger-jsdoc@npm:^6.0.1":
version: 6.0.2
resolution: "@types/swagger-jsdoc@npm:6.0.2"
Expand Down Expand Up @@ -7556,6 +7591,7 @@ __metadata:
"@types/node": ^14.11.10
"@types/request": ^2.48.7
"@types/sprintf-js": ^1.1.2
"@types/supertest": ^6.0.2
"@types/swagger-jsdoc": ^6.0.1
"@types/swagger-ui-express": ^4.1.3
"@types/urijs": ^1.19.19
Expand Down

0 comments on commit 1bd6171

Please sign in to comment.