Skip to content

Commit 8cd3b92

Browse files
authored
Merge pull request #203 from NyashaMuusha/Jmpi-bug-notification-screen-pointing-to-deleted-GR-2
Jmpi bug notification screen pointing to deleted golden record
2 parents f72986f + 58dbc07 commit 8cd3b92

File tree

15 files changed

+94
-32
lines changed

15 files changed

+94
-32
lines changed

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,11 @@ private Behavior<Event> getGidsPagedHandler(final GetGidsPagedRequest request) {
435435

436436
private Behavior<Event> postUpdateNotificationHandler(final PostUpdateNotificationRequest request) {
437437
try {
438-
psqlNotifications.updateNotificationState(request.notificationId);
439-
} catch (SQLException exception) {
438+
libMPI.startTransaction();
439+
psqlNotifications.updateNotificationState(request.notificationId, request.oldGoldenId, request.currentGoldenId);
440+
libMPI.sendUpdatedNotificationEvent(request.notificationId, request.oldGoldenId, request.currentGoldenId);
441+
libMPI.closeTransaction();
442+
} catch (SQLException exception) {
440443
LOGGER.error(exception.getMessage());
441444
}
442445
request.replyTo.tell(new PostUpdateNotificationResponse());
@@ -608,7 +611,9 @@ public record PatchIidNewGidLinkResponse(Either<MpiGeneralError, LinkInfo> linkI
608611

609612
public record PostUpdateNotificationRequest(
610613
ActorRef<PostUpdateNotificationResponse> replyTo,
611-
String notificationId) implements Event {
614+
String notificationId,
615+
String oldGoldenId,
616+
String currentGoldenId) implements Event {
612617
}
613618

614619
public record PostUpdateNotificationResponse() implements EventResponse {

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

Lines changed: 16 additions & 9 deletions
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_LibMPI/src/main/java/org/jembi/jempi/libmpi/LibMPI.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,23 @@ public LinkInfo createInteractionAndLinkToClonedGoldenRecord(
375375
return result;
376376
}
377377

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public final class GlobalConstants {
8282

8383
public enum AuditEventType {
8484
LINKING_EVENT,
85+
NOTIFICATION_EVENT,
8586
UNKNOWN_EVENT
8687
}
8788

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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)