From 81891026a0cac5e4c14cb018bad26b2e357f7a70 Mon Sep 17 00:00:00 2001 From: Rob Mitchell Date: Thu, 31 Oct 2024 15:18:51 -0400 Subject: [PATCH 1/2] adding initialization work for API --- .../src/app/api/customize-query/conditions.ts | 19 +++++++++++++++++++ query-connector/src/app/database-service.ts | 14 ++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 query-connector/src/app/api/customize-query/conditions.ts diff --git a/query-connector/src/app/api/customize-query/conditions.ts b/query-connector/src/app/api/customize-query/conditions.ts new file mode 100644 index 000000000..9659122ae --- /dev/null +++ b/query-connector/src/app/api/customize-query/conditions.ts @@ -0,0 +1,19 @@ +import { NextResponse } from "next/server"; +import { getConditionsData } from "@/app/database-service"; + +/** + * Handles a GET request to fetch conditions data. + * @returns Response with conditions data in JSON format. + */ +export async function GET() { + try { + const conditionsData = await getConditionsData(); + return NextResponse.json(conditionsData, { status: 200 }); + } catch (error) { + console.error("Error fetching conditions data:", error); + return NextResponse.json( + { error: "Failed to fetch conditions data" }, + { status: 500 }, + ); + } +} diff --git a/query-connector/src/app/database-service.ts b/query-connector/src/app/database-service.ts index ecf27998a..6bb10623a 100644 --- a/query-connector/src/app/database-service.ts +++ b/query-connector/src/app/database-service.ts @@ -453,3 +453,17 @@ export async function insertQuery(input: UserQueryInput) { if (errorArray.length === 0) return { success: true }; return { success: false, error: errorArray.join(",") }; } + +/** + * 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. + */ +export async function getConditionsData() { + const query = "SELECT * FROM conditions"; + const result = await dbClient.query(query); + return result.rows; +} From 1c2d59f96b8f75b3f2e24214a486d98c74c4722a Mon Sep 17 00:00:00 2001 From: Rob Mitchell Date: Fri, 1 Nov 2024 14:52:43 -0400 Subject: [PATCH 2/2] fixing } --- query-connector/src/app/database-service.ts | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/query-connector/src/app/database-service.ts b/query-connector/src/app/database-service.ts index 36d1197e0..3d905e811 100644 --- a/query-connector/src/app/database-service.ts +++ b/query-connector/src/app/database-service.ts @@ -454,19 +454,6 @@ export async function insertQuery(input: QueryInput) { } /** - * 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. - */ -export async function getConditionsData() { - const query = "SELECT * FROM conditions"; - const result = await dbClient.query(query); - return result.rows; - - /** * Function that verifies that a particular value set and all its affiliated * concepts were successfully inserted into the DB. Given a FHIR formatted * value set, the function checks three things: @@ -574,3 +561,17 @@ export async function checkValueSetInsertion(vs: ValueSet) { return missingData; } + +/** + * 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. + */ +export async function getConditionsData() { + const query = "SELECT * FROM conditions"; + const result = await dbClient.query(query); + return result.rows; +}