Skip to content

Commit

Permalink
Added paths for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pmanko committed Jan 17, 2024
1 parent 80dadbc commit 7868dbf
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 5 deletions.
1 change: 0 additions & 1 deletion .eslintcache

This file was deleted.

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)
}
}
}
28 changes: 28 additions & 0 deletions src/routes/__tests__/fhir.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import request from 'supertest'
import express from 'express'
import { router } from '../fhir'

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

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

it('should return 200 OK for GET /metadata', async () => {
const response = await request(app).get('/metadata')
expect(response.status).toBe(200)
// Add more assertions for the response body if needed
})

it('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' })
})

// Add more test cases for other routes and scenarios
})
45 changes: 45 additions & 0 deletions src/routes/__tests__/ips.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import request from 'supertest'
import express from 'express'
import { router } from '../ips'

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

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

it('should return 200 OK for GET /metadata', async () => {
const response = await request(app).get('/metadata')
expect(response.status).toBe(200)
// Add more assertions for the response body if needed
})

it('should return 200 OK for GET /Patient/cruid/:id/:lastUpdated?', async () => {
const response = await request(app).get('/Patient/cruid/12345')
expect(response.status).toBe(200)
// Add more assertions for the response body if needed
})

it('should return 200 OK for GET /Patient/:id/:lastUpdated?', async () => {
const response = await request(app).get('/Patient/67890')
expect(response.status).toBe(200)
// Add more assertions for the response body if needed
})

it('should return 200 OK for GET /:location?/:lastUpdated?', async () => {
const response = await request(app).get('/location1')
expect(response.status).toBe(200)
// Add more assertions for the response body if needed
})

it('should return 500 Internal Server Error for GET /:location?/:lastUpdated? when golden record not found', async () => {
const response = await request(app).get('/location2')
expect(response.status).toBe(500)
})

// Add more test cases for other routes and scenarios
})
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

0 comments on commit 7868dbf

Please sign in to comment.