Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating condition category mapping work in database-services #112

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions query-connector/src/app/api/customize-query/conditions.ts

This file was deleted.

35 changes: 31 additions & 4 deletions query-connector/src/app/database-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,39 @@ export async function checkValueSetInsertion(vs: ValueSet) {
* Retrieves all records from the conditions table in the database.
* This function queries the database to fetch condition data, including
* condition name, code, and category.
* @returns results.rows A promise that resolves to an array of rows,
* each representing a condition with its associated fields (e.g., id, condition name,
* condition code, category). If no records are found, an empty array is returned.
* @returns An object containing:
* - `conditionCatergories`: a JSON object grouped by category with id:name pairs,
* to display on build-query page
* - `conditionLookup`: a JSON object with id as the key and name as the value in
* order to make a call to the DB with the necessary ID(s) to get the valuesets
* on subsequent pages.
*/
export async function getConditionsData() {
const query = "SELECT * FROM conditions";
const result = await dbClient.query(query);
return result.rows;
const rows = result.rows;

// 1. Grouped by category with id:name pairs
const conditionCatergories = rows.reduce(
(acc, row) => {
const { category, id, name } = row;
if (!acc[category]) {
acc[category] = [];
}
acc[category].push({ [id]: name });
return acc;
},
{} as Record<string, Array<Record<string, string>>>,
);

// 2. ID-Name mapping
const conditionLookup = rows.reduce(
(acc, row) => {
acc[row.id] = row.name;
return acc;
},
{} as Record<string, string>,
);

return { conditionCatergories, conditionLookup };
}
Loading