Skip to content

Commit

Permalink
Merge pull request #21 from Gravitate-Health/18-change-lens-selector-…
Browse files Browse the repository at this point in the history
…to-fhir-ips-server

18 change lens selector to fhir ips server
  • Loading branch information
aalonsolopez authored Jun 14, 2024
2 parents c37b5c5 + 0908144 commit df64018
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 1,194 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-slim as buildstage
FROM node:20-slim as buildstage

WORKDIR /usr/src/app

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ limitations under the License.
## Authors and history
- Guillermo Mejías ([@gmej](https://github.com/gmej))
- Alejo Esteban ([@10alejopain](https://github.com/))
- Alejo Esteban ([@10alejospain](https://github.com/10alejospain))
- Alejandro Alonso ([@aalonsolopez](https://github.com/aalonsolopez))
---
Expand Down
20 changes: 11 additions & 9 deletions kubernetes/002_lens-selector-example-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ spec:
app: lens-selector-mvp2
spec:
containers:
- name: lens-selector-mvp2
image: gravitate-registry.cr.de-fra.ionos.com/lens-selector-mvp2:latest
imagePullPolicy: Always
env:
- name: ENVIRONMENT
value: "prod"
ports:
- containerPort: 3000
protocol: TCP
- name: lens-selector-mvp2
image: gravitate-registry.cr.de-fra.ionos.com/lens-selector-mvp2:dev
imagePullPolicy: Always
env:
- name: ENVIRONMENT
value: "prod"
- name: BASE_URL
value: "http://gravitate-health.lst.tfo.upm.es"
ports:
- containerPort: 3000
protocol: TCP
restartPolicy: Always
status: {}
88 changes: 81 additions & 7 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ info:
description: Gravitate Health Focusing Service. Focuses a Focused ePI.
contact: {}
servers:
- url: https://fosps.gravitatehealth.eu
- url: https://fosps.gravitatehealth.eu
paths:
/lenses:
get:
tags:
- Lenses
- Lenses
description: Returns all lenses IDs.
responses:
"200":
Expand All @@ -26,10 +26,10 @@ paths:
type: string
example: ["lense1", "lense2", "lense3"]

/lenses/{id}:
/lenses/{name}:
get:
tags:
- Lenses
- Lenses
description: Returns the lense itself.
responses:
"200":
Expand All @@ -39,9 +39,83 @@ paths:
schema:
type: object
properties:
metadata:
resourceType:
type: string
example: "Library"
id:
type: string
example: "588"
meta:
type: object
extension:
type: array
items:
type: object
url:
type: string
example: "http://hl7.eu/fhir/ig/gravitate-health/Library/mock-lib"
identifier:
type: array
items:
type: object
version:
type: string
example: "0.0.1"
name:
type: string
example: "pregnancy-lens"
title:
type: string
example: "pregnancy-lens"
status:
type: string
example: "draft"
experimental:
type: boolean
example: true
type:
type: object
lense:
date:
type: string
example: "2024-06-12T12:23:10.005Z"
publisher:
type: string
example: "console.log('Hello World!')"
example: "Gravitate Health Project - UPM Team"
contact:
type: array
items:
type: object
description:
type: string
example: "Lens that highlight or collapses pregnancy related information"
jurisdiction:
type: array
items:
type: object
purpose:
type: string
example: "Collapse or highlight pregnancy related information on a preprocessed ePI."
usage:
type: string
example: "You can import this lens directly to your FHIR Server which suports Library Resource type."
copiright:
type: string
example: "© 2024 Gravitate Health"
parameter:
type: array
items:
type: object
content:
type: array
items:
type: object

parameters:
- name: name
in: path
required: true
schema:
type: string
description: The name of the lense to return.


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "ts-node-dev ./src/index.ts",
"build": "if [ -d \"$PWD/build\" ]; then rm -r \"$PWD/build\"; fi && tsc --incremental && cp -r ./src/lenses ./build",
"build": "if [ -d \"$PWD/build\" ]; then rm -r \"$PWD/build\"; fi && tsc --incremental",
"start": "node build/index.js"
},
"repository": {
Expand Down
73 changes: 32 additions & 41 deletions src/controllers/lensesController.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,40 @@
import { Response, Request } from "express";
import { Logger } from "../utils/Logger";
import fs, { readFile, readdir } from "fs"

const readLensesDir = async () => {
try {
let path = `${process.cwd()}/build/lenses/`
console.log(`Looking for lenses in path: ${path}`);
let discoveredLenses = await fs.promises.readdir(path);
console.log(`Discovered the following files in dir: ${discoveredLenses || "None"}`);
return discoveredLenses
} catch (err) {
console.error('Error occurred while reading directory!', err);
}
}

const readLensFile = async (path: string) => {
try {
return await fs.promises.readFile(path, 'utf-8');
} catch (err) {
console.error('Error occurred while reading file!', err);
}
}
const fhirIpsURL = process.env.BASE_URL + "/ips/api/fhir"

const retrieveLensesNames = async () => {
try {
let lensesNames = await readLensesDir()
console.log(`Found the following lenses: ${lensesNames || "None"}`);
return await lensesNames
let response = []
let lensPath = "/Library"
let lenses = await fetch(`${fhirIpsURL}${lensPath}`)

let lensesBundle = await lenses.json()
if (lensesBundle.total === 0) {
return []
}
for (let entry of lensesBundle.entry) {
response.push(entry.resource.name)
}
return response
} catch (error) {
console.log(error);
return null
}
}

const retrieveLense = async (lenseId: string) => {
let lensFilename: string = lenseId + ".js"
let lensPath = `${process.cwd()}/build/lenses/${lensFilename}`

let lensesNames = await retrieveLensesNames()
console.log(`Looking for lens: ${lensFilename}`);
if (lensesNames?.includes(lensFilename)) {
try {
return await readLensFile(lensPath)
} catch (error) {
console.log(error);
const retrieveLense = async (lenseId: string): Promise<Object | null> => {
let lensPath = `/Library?name:exact=${lenseId}`
try {
let lenses = await fetch(`${fhirIpsURL}${lensPath}`)
let lensesBundle = await lenses.json()
if (lensesBundle.total === 0) {
return `No lens found with ${lenseId} name`
}
} else {
return null
return lensesBundle.entry[0].resource
} catch (error) {
console.log(error);
return null
}
}

Expand All @@ -60,12 +48,15 @@ export const getLens = async (req: Request, res: Response) => {
}
try {
let lens = await retrieveLense(reqlens)
let lensObject = {
metadata: {},
lens: lens

if (lens === null) {
console.log(`Lens ${reqlens} not found.`);
res.status(404).send({
message: `Lens ${reqlens} not found.`
})
}
console.log(`Sending lens: ${JSON.stringify(lensObject)}`);
res.status(200).send(lensObject)
console.log(`Sending lens: ${JSON.stringify(lens)}`);
res.status(200).send(lens)
return
} catch (error) {
console.log(error);
Expand Down
Loading

0 comments on commit df64018

Please sign in to comment.