Skip to content

Commit ed42c4c

Browse files
committed
clean link/match streams & add new cr-link-update http request
2 parents 46567f3 + 8cd3b92 commit ed42c4c

File tree

16 files changed

+98
-33
lines changed

16 files changed

+98
-33
lines changed

JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/notifications-schema.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ CREATE TABLE IF NOT EXISTS Notification
2626
State VARCHAR(50),
2727
Patient_Id VARCHAR(50),
2828
Names VARCHAR(100),
29-
Golden_Id VARCHAR(50),
29+
Old_Golden_Id VARCHAR(50),
30+
Current_Golden_Id VARCHAR(50),
3031
Score Numeric
3132
);
3233

JeMPI_Apps/JeMPI_Controller/src/main/java/org/jembi/jempi/controller/PsqlNotifications.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ void insert(
2828
final String dID) throws SQLException {
2929

3030
psqlClient.connect(AppConfig.POSTGRESQL_NOTIFICATIONS_DB);
31-
String sql = "INSERT INTO notification (id, type, state, names, created, patient_id, golden_id, score) "
32-
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
31+
String sql = "INSERT INTO notification (id, type, state, names, created, patient_id, old_golden_id, current_golden_id, score) "
32+
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
3333
try (PreparedStatement pstmt = psqlClient.prepareStatement(sql)) {
3434
psqlClient.setAutoCommit(false);
3535
pstmt.setObject(1, id);
@@ -39,7 +39,8 @@ void insert(
3939
pstmt.setTimestamp(5, created);
4040
pstmt.setString(6, dID);
4141
pstmt.setString(7, gID);
42-
pstmt.setFloat(8, score);
42+
pstmt.setString(8, gID);
43+
pstmt.setFloat(9, score);
4344
pstmt.executeUpdate();
4445
} catch (SQLException e) {
4546
LOGGER.error("Error executing INSERT statement: {}", e.getMessage(), e);

JeMPI_Apps/JeMPI_LibAPI/src/main/java/org/jembi/jempi/libapi/Ask.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ static CompletionStage<BackEnd.PostUpdateNotificationResponse> postUpdateNotific
330330
CompletionStage<BackEnd.PostUpdateNotificationResponse> stage = AskPattern
331331
.ask(backEnd,
332332
replyTo -> new BackEnd.PostUpdateNotificationRequest(replyTo,
333-
notificationRequest.notificationId()),
333+
notificationRequest.notificationId(),
334+
notificationRequest.oldGoldenId(),
335+
notificationRequest.currentGoldenId()),
334336
java.time.Duration.ofSeconds(11),
335337
actorSystem.scheduler());
336338
return stage.thenApply(response -> response);

JeMPI_Apps/JeMPI_LibAPI/src/main/java/org/jembi/jempi/libapi/BackEnd.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,11 @@ private Behavior<Event> getGidsPagedHandler(final GetGidsPagedRequest request) {
433433

434434
private Behavior<Event> postUpdateNotificationHandler(final PostUpdateNotificationRequest request) {
435435
try {
436-
psqlNotifications.updateNotificationState(request.notificationId);
437-
} catch (SQLException exception) {
436+
libMPI.startTransaction();
437+
psqlNotifications.updateNotificationState(request.notificationId, request.oldGoldenId, request.currentGoldenId);
438+
libMPI.sendUpdatedNotificationEvent(request.notificationId, request.oldGoldenId, request.currentGoldenId);
439+
libMPI.closeTransaction();
440+
} catch (SQLException exception) {
438441
LOGGER.error(exception.getMessage());
439442
}
440443
request.replyTo.tell(new PostUpdateNotificationResponse());
@@ -611,7 +614,9 @@ public record PatchIidNewGidLinkResponse(Either<MpiGeneralError, LinkInfo> linkI
611614

612615
public record PostUpdateNotificationRequest(
613616
ActorRef<PostUpdateNotificationResponse> replyTo,
614-
String notificationId) implements Event {
617+
String notificationId,
618+
String oldGoldenId,
619+
String currentGoldenId) implements Event {
615620
}
616621

617622
public record PostUpdateNotificationResponse() implements EventResponse {

JeMPI_Apps/JeMPI_LibAPI/src/main/java/org/jembi/jempi/libapi/PsqlNotifications.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class PsqlNotifications {
1111

1212
private static final String NOTIFICATION_TABLE_NAME = "notification";
1313
private static final String QUERY = """
14-
SELECT patient_id, id, names, created, state,type, score, golden_id
14+
SELECT patient_id, id, names, created, state,type, score, old_golden_id, current_golden_id
1515
FROM notification
1616
WHERE created BETWEEN ? AND ? AND state IN (?, ?)
1717
ORDER BY created
@@ -38,6 +38,7 @@ final class PsqlNotifications {
3838
* @param states The state of notification.
3939
* @return A {@link MatchesForReviewResult} object containing the matches and related information.
4040
*/
41+
4142
MatchesForReviewResult getMatchesForReview(
4243
final int limit,
4344
final int offset,
@@ -166,15 +167,21 @@ void insertCandidates(
166167
}
167168
}
168169

169-
void updateNotificationState(
170-
final String id) throws SQLException {
170+
void updateNotificationState(final String notificationId, final String oldGoldenId, final String currentGoldenId) throws SQLException {
171171
psqlClient.connect();
172-
try (Statement stmt = psqlClient.createStatement()) {
173-
ResultSet rs = stmt.executeQuery(String.format(Locale.ROOT,
174-
"update notification set state = '%s' where id = '%s'",
175-
"CLOSED",
176-
id));
177-
psqlClient.commit();
172+
String sql = String.format(Locale.ROOT, "update notification set state = '%s', old_golden_id = '%s', current_golden_id = '%s' where id = '%s'",
173+
"CLOSED",
174+
oldGoldenId,
175+
currentGoldenId,
176+
notificationId);
177+
try (PreparedStatement stmt = psqlClient.prepareStatement(sql)) {
178+
int rowsAffected = stmt.executeUpdate();
179+
if (rowsAffected > 0) {
180+
LOGGER.info("Updated notification {} with new currentGoldenId {}", notificationId, currentGoldenId);
181+
psqlClient.commit();
182+
} else {
183+
LOGGER.warn("Notification with ID {} not found", notificationId);
184+
}
178185
}
179186
}
180187

JeMPI_Apps/JeMPI_LibAPI/src/main/java/org/jembi/jempi/libapi/Routes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ private static Route postCrCandidates(
892892
try {
893893
return onComplete(postCrCandidatesProxy(linkerIP, linkerPort, http, obj),
894894
response -> {
895-
if (response.isSuccess()) {
895+
if (!response.isSuccess()) {
896896
LOGGER.warn(IM_A_TEA_POT_LOG);
897897
return complete(ApiModels.getHttpErrorResponse(GlobalConstants.IM_A_TEA_POT));
898898
}

JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/LibMPI.java

+20
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,24 @@ public LinkInfo createInteractionAndLinkToClonedGoldenRecord(
371371
return result;
372372
}
373373

374+
/*
375+
* *****************************************************************************
376+
* *
377+
* Notifications
378+
* *****************************************************************************
379+
* *
380+
*/
381+
382+
public void sendUpdatedNotificationEvent(
383+
final String notificationId,
384+
final String oldGoldenId,
385+
final String currentGoldenId) {
386+
final var message = String.format(
387+
"Notification -> new GoldenID: old(%s) new(%s), new State: old(OPEN) new(CLOSED)",
388+
oldGoldenId,
389+
currentGoldenId);
390+
final var eventData = new NotificationAuditEventData(message, notificationId);
391+
auditTrailUtil.sendAuditEvent(GlobalConstants.AuditEventType.NOTIFICATION_EVENT, eventData);
392+
}
393+
374394
}

JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/GlobalConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public final class GlobalConstants {
8383

8484
public enum AuditEventType {
8585
LINKING_EVENT,
86+
NOTIFICATION_EVENT,
8687
UNKNOWN_EVENT
8788
}
8889

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.jembi.jempi.shared.models;
2+
3+
public record NotificationAuditEventData(
4+
String message,
5+
String notificationId
6+
) {
7+
}

JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/NotificationRequest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
@JsonInclude(JsonInclude.Include.NON_NULL)
77
public record NotificationRequest(
88
@JsonProperty("notificationId") String notificationId,
9-
@JsonProperty("state") String state) {
9+
@JsonProperty("state") String state,
10+
@JsonProperty("oldGoldenId") String oldGoldenId,
11+
@JsonProperty("currentGoldenId") String currentGoldenId) {
1012

1113
}

JeMPI_Apps/JeMPI_UI/src/components/notificationWorklist/NotificationWorklist.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const NotificationWorklist = () => {
6565
endDateFilter.format('YYYY-MM-DD HH:mm:ss'),
6666
selectedStates
6767
),
68-
refetchOnWindowFocus: false,
68+
refetchOnWindowFocus: true,
6969
keepPreviousData: true
7070
})
7171

@@ -186,7 +186,7 @@ const NotificationWorklist = () => {
186186
notificationId: params.row.id,
187187
notificationType: params.row.type,
188188
patient_id: params.row.patient_id,
189-
golden_id: params.row.golden_id,
189+
golden_id: params.row.current_golden_id,
190190
score: params.row.score,
191191
candidates: params.row.candidates
192192
}

JeMPI_Apps/JeMPI_UI/src/components/notificationWorklist/notificationsColumns.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,22 @@ const NOTIFICATIONS_COLUMNS: GridColDef[] = [
3838
filterable: false
3939
},
4040
{
41-
field: 'golden_id',
42-
headerName: 'Golden ID',
41+
field: 'old_golden_id',
42+
headerName: 'Initial Golden ID',
4343
type: 'number',
4444
flex: 1,
4545
headerClassName: 'super-app-theme--header',
46-
filterable: false
46+
filterable: false,
47+
hideable: true
48+
},
49+
{
50+
field: 'current_golden_id',
51+
headerName: 'Current Golden ID',
52+
type: 'number',
53+
flex: 1,
54+
headerClassName: 'super-app-theme--header',
55+
filterable: false,
56+
hideable: true
4757
},
4858
{
4959
field: 'score',

JeMPI_Apps/JeMPI_UI/src/components/reviewLink/ReviewLink.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ const ReviewLink = () => {
8989
}
9090
})
9191

92-
const updateNotification = () => {
92+
const updateNotification = (oldGoldenId: string, currentGoldenId: string) => {
9393
mutateNotification.mutate(
9494
{
95-
notificationId: payload?.notificationId
95+
notificationId: payload?.notificationId,
96+
oldGoldenId: oldGoldenId,
97+
currentGoldenId: currentGoldenId,
9698
},
9799
{
98100
onSuccess: () => {
@@ -117,7 +119,7 @@ const ReviewLink = () => {
117119
{
118120
onSuccess: data => {
119121
if (payload?.notificationId) {
120-
updateNotification()
122+
updateNotification(id, goldenRecord ? goldenRecord.uid : '')
121123
}
122124
enqueueSnackbar('New record linked', {
123125
variant: 'success'
@@ -153,7 +155,7 @@ const ReviewLink = () => {
153155
{
154156
onSuccess: () => {
155157
if (payload?.notificationId) {
156-
updateNotification()
158+
updateNotification(id, goldenRecord ? goldenRecord.uid : '')
157159
navigate('/notifications')
158160
} else {
159161
navigate(`/record-details/${id}`)

JeMPI_Apps/JeMPI_UI/src/services/mockData.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const notifications: Notification[] = [
1212
names: 'Bob Smith',
1313
patient_id: '0x5a',
1414
status: NotificationState.CLOSED,
15-
golden_id: '0x9833',
15+
old_golden_id: '0x9493',
16+
current_golden_id: '0x9833',
1617
score: 0.5,
1718
candidates: [
1819
{
@@ -28,7 +29,8 @@ const notifications: Notification[] = [
2829
names: 'Jane Doe',
2930
patient_id: '0x7j',
3031
status: NotificationState.OPEN,
31-
golden_id: '0x9824',
32+
old_golden_id: '0x9493',
33+
current_golden_id: '0x9833',
3234
score: 0.9,
3335
candidates: [
3436
{
@@ -44,7 +46,8 @@ const notifications: Notification[] = [
4446
names: 'Jane Smith',
4547
patient_id: '0x1a',
4648
status: NotificationState.OPEN,
47-
golden_id: '0x9847',
49+
old_golden_id: '0x9493',
50+
current_golden_id: '0x9833',
4851
score: 0.3,
4952
candidates: [
5053
{
@@ -60,7 +63,8 @@ const notifications: Notification[] = [
6063
names: 'John Themba',
6164
patient_id: '0x9a',
6265
status: NotificationState.OPEN,
63-
golden_id: '0x9866',
66+
old_golden_id: '0x9493',
67+
current_golden_id: '0x9833',
6468
score: 0.7,
6569
candidates: [
6670
{

JeMPI_Apps/JeMPI_UI/src/types/BackendResponse.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88

99
export interface NotificationRequest {
1010
notificationId: string
11+
oldGoldenId: string
12+
currentGoldenId: string
1113
}
1214

1315
export interface LinkRequest {

JeMPI_Apps/JeMPI_UI/src/types/Notification.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export default interface Notification {
66
names: string
77
patient_id: string | null
88
status: NotificationState
9-
golden_id: string
9+
old_golden_id: string
10+
current_golden_id: string
1011
score: number
1112
linkedTo?: GoldenRecordCandidate
1213
candidates?: GoldenRecordCandidate[]

0 commit comments

Comments
 (0)