Skip to content

Commit

Permalink
Deleted all fuctions related to read lenses files. Now it returns a b…
Browse files Browse the repository at this point in the history
…undle with the FHIR Lens Resource
  • Loading branch information
aalonsolopez committed Jun 14, 2024
1 parent 6ab19fb commit da097e8
Showing 1 changed file with 4 additions and 35 deletions.
39 changes: 4 additions & 35 deletions src/controllers/lensesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@ import fs, { readFile, readdir } from "fs"

const fhirIpsURL = process.env.BASE_URL + "/ips/api/fhir"

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 retrieveLensesNames = async () => {
try {
let response = []
Expand All @@ -40,18 +20,13 @@ const retrieveLensesNames = async () => {
}
}

const retrieveLense = async (lenseId: string): Promise<{lensResource: Object, lens: string} | null> => {
const retrieveLense = async (lenseId: string): Promise<Object | null> => {
let lensPath = `/Library?name:exact=${lenseId}`
try {
return await fetch(`${fhirIpsURL}${lensPath}`)
.then(res => res.json())
.then(bundle => {
const dataBase64 = bundle.entry[0].resource.content[0].data
const data = atob(dataBase64)
return {
lensResource: bundle.entry[0].resource,
lens: data
}
return bundle
})
} catch (error) {
console.log(error);
Expand All @@ -69,21 +44,15 @@ export const getLens = async (req: Request, res: Response) => {
}
try {
let lens = await retrieveLense(reqlens)
let lensObject

if (lens === null) {
console.log(`Lens ${reqlens} not found.`);
res.status(404).send({
message: `Lens ${reqlens} not found.`
})
} else {
lensObject = {
lens: lens.lens,
lensResource: lens.lensResource
}
}
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

0 comments on commit da097e8

Please sign in to comment.