Skip to content

Commit a7bb221

Browse files
Setting up FHIR Servers save last connection (#668)
1 parent 1206666 commit a7bb221

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/app/(pages)/fhirServers/page.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
insertFhirServer,
2424
updateFhirServer,
2525
deleteFhirServer,
26+
updateFhirServerConnectionStatus,
2627
} from "@/app/backend/fhir-servers";
2728

2829
const Modal = dynamic<ModalProps>(
@@ -103,6 +104,7 @@ const FhirServers: React.FC = () => {
103104
setConnectionStatus("idle");
104105
setDisableCertValidation(server.disableCertValidation);
105106
setDefaultServer(server.defaultServer);
107+
setErrorMessage("");
106108

107109
// Set auth method and corresponding fields based on server data
108110
if (server.authType) {
@@ -207,11 +209,45 @@ const FhirServers: React.FC = () => {
207209
}
208210
};
209211
const handleTestConnection = async () => {
210-
const result = await testFhirConnection(serverUrl);
212+
// 1. Test the connection (returns { success, error })
213+
const result = await testFhirServerConnection(
214+
serverUrl,
215+
disableCertValidation,
216+
{
217+
authType: authMethod,
218+
bearerToken: authMethod === "basic" ? bearerToken : undefined,
219+
clientId: ["client_credentials", "SMART"].includes(authMethod)
220+
? clientId
221+
: undefined,
222+
clientSecret:
223+
authMethod === "client_credentials" ? clientSecret : undefined,
224+
tokenEndpoint: ["client_credentials", "SMART"].includes(authMethod)
225+
? tokenEndpoint
226+
: undefined,
227+
scopes: ["client_credentials", "SMART"].includes(authMethod)
228+
? scopes
229+
: undefined,
230+
},
231+
);
232+
233+
// 2. Update connection status in DB
234+
const updateResult = await updateFhirServerConnectionStatus(
235+
selectedServer?.name || serverName,
236+
result.success,
237+
);
238+
211239
setConnectionStatus(result.success ? "success" : "error");
212240
setErrorMessage(result.error);
213-
};
214241

242+
// 3. Update the frontend server row to reflect new last checked time
243+
if (updateResult.server) {
244+
setFhirServers((prev) =>
245+
prev.map((srv) =>
246+
srv.id === updateResult.server.id ? updateResult.server : srv,
247+
),
248+
);
249+
}
250+
};
215251
const handleSave = async () => {
216252
const connectionResult = await testFhirConnection(serverUrl);
217253

0 commit comments

Comments
 (0)