Skip to content

Commit

Permalink
Adding initialization work to display conditions.category and build q…
Browse files Browse the repository at this point in the history
…ueries (#103)
  • Loading branch information
robertandremitchell authored Nov 4, 2024
1 parent d8fabbf commit 695963b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions query-connector/src/app/api/customize-query/conditions.ts
Original file line number Diff line number Diff line change
@@ -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 },
);
}
}
14 changes: 14 additions & 0 deletions query-connector/src/app/database-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,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;
}

0 comments on commit 695963b

Please sign in to comment.