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

SMART on FHIR pt 2 - backend changes #452

Merged
merged 6 commits into from
Mar 25, 2025
Merged
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
98 changes: 49 additions & 49 deletions query-connector/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions query-connector/src/app/(pages)/.well-known/jwks.json/route.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { NextResponse } from "next/server";
import fs from "fs";
import path from "path";
import { getOrCreateKeys } from "../../../backend/dbServices/smartOnFhir/lib";

export async function GET() {
try {
// Path to the JWKS file
const jwksPath = path.join(process.cwd(), "keys", "jwks.json");
// Get or create JWKS
const jwks = await getOrCreateKeys();

// Read the JWKS file
const jwksContent = fs.readFileSync(jwksPath, "utf-8");
const jwks = JSON.parse(jwksContent);

// Return the JWKS as JSON
// Return the JWKS as JSON with appropriate headers
return NextResponse.json(jwks, {
headers: {
"Cache-Control": "public, max-age=3600", // Cache for 1 hour
@@ -20,6 +15,9 @@ export async function GET() {
});
} catch (error) {
console.error("Error serving JWKS:", error);
return NextResponse.json({ error: "Failed to load JWKS" }, { status: 500 });
return NextResponse.json(
{ error: "Failed to load or generate JWKS" },
{ status: 500 },
);
}
}
16 changes: 12 additions & 4 deletions query-connector/src/app/api/test-fhir-connection/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FHIRClient from "@/app/shared/fhirClient";
import { NextRequest, NextResponse } from "next/server";
import { testFhirServerConnection } from "../../shared/query-service";

/**
* Test FHIR connection
@@ -9,7 +9,7 @@ import { testFhirServerConnection } from "../../shared/query-service";
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { url, bearerToken } = body;
const { url, disableCertValidation, authData } = body;

if (!url) {
return NextResponse.json(
@@ -18,12 +18,20 @@ export async function POST(request: NextRequest) {
);
}

const result = await testFhirServerConnection(url, bearerToken);
const result = await FHIRClient.testConnection(
url,
disableCertValidation,
authData,
);

return NextResponse.json(result);
} catch (error) {
console.error("Error testing FHIR connection:", error);
return NextResponse.json(
{ success: false, error: "Internal server error" },
{
success: false,
error: error instanceof Error ? error.message : "Internal server error",
},
{ status: 500 },
);
}
12 changes: 12 additions & 0 deletions query-connector/src/app/backend/dbServices/fhir-servers.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,18 @@ import { transaction } from "./decorators";
import { FhirServerConfig } from "@/app/models/entities/fhir-servers";
import { superAdminAccessCheck } from "@/app/utils/auth";

// Define an interface for authentication data
export interface AuthData {
authType: "none" | "basic" | "client_credentials" | "SMART";
bearerToken?: string;
clientId?: string;
clientSecret?: string;
tokenEndpoint?: string;
scopes?: string;
accessToken?: string;
tokenExpiry?: string;
}

class FhirServerConfigService {
private static dbClient: Pool = getDbClient();
private static cachedFhirServerConfigs: FhirServerConfig[] | null = null;
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@ import { Pool } from "pg";
// The underlying functionality here is reused in Playwright to do some
// test setup, but for some DUMB reason Playwright refuses to play nicely with
// decorators. As a workaround, we're doing some fiddly imports to expose the
// underlying logic away from the decorated exports
// underlying logic away from the decorated exports available in the class exported
// in query-building.ts

/**
* Backend handler function for upserting a query
Loading
Loading