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

JMPI-742-update-notification-component #137

Merged
merged 47 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4731546
fix: notifications render conditions
issambaccouch Oct 31, 2023
2d0d1d9
fix: notfound page appear while fetching data
issambaccouch Nov 1, 2023
e044ddc
feat: sort notifications by createdAt
issambaccouch Nov 1, 2023
cc1de7a
feat: add quick top/bottom navigation
issambaccouch Nov 1, 2023
50fbb04
fix: quick top/bottom navigation
issambaccouch Nov 1, 2023
5be46e6
ref: quick top/bottom navigation
issambaccouch Nov 2, 2023
c59a315
feat: add pagination quick page navigation
issambaccouch Nov 3, 2023
aa0c73d
chore: make datagrid header sticky
issambaccouch Nov 6, 2023
7c10688
feat: implement datetime range filter
issambaccouch Nov 7, 2023
02cd4a9
chore: fix createdAt field and filter date range
issambaccouch Nov 8, 2023
dd2751b
feat: add multi states select option in front-end
issambaccouch Nov 9, 2023
b789000
feat: add multi states notifications filter
issambaccouch Nov 10, 2023
bc961f0
feat: add default states for notifications filter
issambaccouch Nov 10, 2023
6e49b59
fix: wrong pagination rows count
issambaccouch Nov 10, 2023
4c6063b
feat: refactor notification states
issambaccouch Nov 13, 2023
4da7695
ref: use generic type for slect props
issambaccouch Nov 13, 2023
7b4d27a
chore: set tanstack query settings globaly
issambaccouch Nov 14, 2023
2abf854
ref:use prepareStatement for injection prevention
issambaccouch Nov 18, 2023
ee7e580
chore: update psql queries for the new states
issambaccouch Nov 19, 2023
4331032
fix: conflict with dev branch
issambaccouch Nov 28, 2023
d9fbeae
ref:WIP browse component
issambaccouch Nov 15, 2023
f14f5ea
feat: finishing up browse enhancement
issambaccouch Nov 27, 2023
1c7c61b
chore: update upload menu position
issambaccouch Nov 28, 2023
84a4799
Merge branch 'dev-jmpi731-keycloak-backend' of github.com:jembi/JeMPI…
issambaccouch Nov 30, 2023
4210783
chore: update keycloak env
issambaccouch Dec 4, 2023
57d8447
feat: update dev build
issambaccouch Dec 4, 2023
4a99ea3
fix: api client undefined headers
issambaccouch Dec 4, 2023
2229610
Merge pull request #152 from jembi/JMPI-776-update-dev-build-and-keyc…
issambaccouch Dec 4, 2023
fb073a5
Merge branch 'dev-jmpi731-keycloak-backend' of github.com:jembi/JeMPI…
issambaccouch Dec 4, 2023
0c94400
Merge pull request #146 from jembi/JMPI-761-update-browse-component
issambaccouch Dec 4, 2023
cae02be
fix: build time warning
issambaccouch Dec 5, 2023
5cc48ea
fix: runtime warning
issambaccouch Dec 5, 2023
3fc4c9a
chore: enhance top bar padding
issambaccouch Dec 6, 2023
8b2d47d
Merge pull request #154 from jembi/JMPI-783-fix-ui-cli-warnings
issambaccouch Dec 6, 2023
5f8dce4
fix: review link undefined uid
issambaccouch Nov 29, 2023
d4985f1
chore: hide browse search
issambaccouch Dec 7, 2023
0769360
feat: implement import dashboard widget
issambaccouch Dec 7, 2023
3a66df6
Merge branch 'dev' of github.com:jembi/JeMPI into JMPI-742-update-not…
issambaccouch Dec 15, 2023
acff469
Merge pull request #158 from jembi/JMPI-785-hide-browse-search
issambaccouch Dec 15, 2023
14df5d3
Merge pull request #159 from jembi/JMPI-784-implement-csv-import-dash…
issambaccouch Dec 15, 2023
e759a6f
Merge branch 'JMPI-742-update-notification-component' of github.com:j…
issambaccouch Dec 15, 2023
38b929f
chore: merge dev branch and update env
issambaccouch Dec 15, 2023
63b4dd2
Updating the ui logic
walisc Jan 5, 2024
00ab145
updating package.json
walisc Jan 5, 2024
5ffb6a3
reverting some changes for now
walisc Jan 5, 2024
d634122
Adding initiating script to the bootstrapper
walisc Jan 5, 2024
ef35f08
Adding back the debugger logs
walisc Jan 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ CREATE TABLE IF NOT EXISTS Notification_Type
(
Id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
Type VARCHAR(50)
);
);

CREATE TABLE IF NOT EXISTS Action_Type
(
Id UUID DEFAULT gen_random_uuid() PRIMARY KEY UNIQUE,
Type VARCHAR(50)
);
);

CREATE TABLE IF NOT EXISTS Notification_State
(
Id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
State VARCHAR(50)
);
);

CREATE TABLE IF NOT EXISTS Notification
(
Id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
Type VARCHAR(50),
Created date,
Created timestamp without time zone,
Reviewd_By uuid,
Reviewed_At timestamp without time zone,
State VARCHAR(50),
Patient_Id VARCHAR(50),
Names VARCHAR(100),
Golden_Id VARCHAR(50),
Score Numeric
);
);

CREATE TABLE IF NOT EXISTS Action
(
Expand All @@ -37,32 +37,32 @@ CREATE TABLE IF NOT EXISTS Action
Action_Type_Id UUID,
Date date,
CONSTRAINT FK_Notification
FOREIGN KEY(Notification_Id)
REFERENCES Notification(Id),
FOREIGN KEY(Notification_Id)
REFERENCES Notification(Id),
CONSTRAINT FK_Action_Type
FOREIGN KEY(Action_Type_Id)
REFERENCES Action_Type(Id)
);
FOREIGN KEY(Action_Type_Id)
REFERENCES Action_Type(Id)
);

CREATE TABLE IF NOT EXISTS Match
(
Notification_Id UUID,
Score Numeric,
Golden_Id VARCHAR(50),
CONSTRAINT FK_Notification
FOREIGN KEY(Notification_Id)
REFERENCES Notification(Id)
);
FOREIGN KEY(Notification_Id)
REFERENCES Notification(Id)
);

CREATE TABLE IF NOT EXISTS candidates
(
Notification_Id UUID,
Score Numeric,
Golden_Id VARCHAR(50),
CONSTRAINT FK_Notification
FOREIGN KEY(Notification_Id)
REFERENCES Notification(Id)
);
FOREIGN KEY(Notification_Id)
REFERENCES Notification(Id)
);

CREATE TABLE IF NOT EXISTS users
(
Expand All @@ -71,10 +71,10 @@ CREATE TABLE IF NOT EXISTS users
family_name VARCHAR(255),
email VARCHAR(255) UNIQUE,
username VARCHAR(255) UNIQUE
);
);

INSERT INTO Notification_State(State)
VALUES ('New'), ('Seen'), ('Actioned'), ('Accepted'), ('Pending');
VALUES ('OPEN'), ('CLOSED');

INSERT INTO Notification_Type(Type)
VALUES ('THRESHOLD'), ('MARGIN'), ('UPDATE');
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.sql.Timestamp;
import java.util.UUID;

final class PsqlNotifications {
Expand All @@ -21,24 +22,28 @@ void insert(
final String type,
final String patientNames,
final Float score,
final Long created,
final Timestamp created,
final String gID,
final String dID) throws SQLException {

psqlClient.connect();
try (Statement stmt = psqlClient.createStatement()) {

// Set auto-commit to false
String sql = "INSERT INTO notification (id, type, state, names, created, patient_id, golden_id, score) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement pstmt = psqlClient.prepareStatement(sql)) {
psqlClient.setAutoCommit(false);
Date res = new Date(created);
String state = "New";

String sql = "INSERT INTO notification (id, type, state, names, created, patient_id, golden_id, score) "
+ "VALUES ('" + id + "','" + type + "','" + state + "','" + patientNames + "', '" + res + "', '" + dID
+ "', '" + gID + "', '" + score + "')";
stmt.addBatch(sql);
stmt.executeBatch();
psqlClient.commit();
pstmt.setObject(1, id);
pstmt.setString(2, type);
pstmt.setString(3, "OPEN");
pstmt.setString(4, patientNames);
pstmt.setTimestamp(5, created);
pstmt.setString(6, dID);
pstmt.setString(7, gID);
pstmt.setFloat(8, score);
pstmt.executeUpdate();
} catch (SQLException e) {
LOGGER.error("Error executing INSERT statement: {}", e.getMessage(), e);
} finally {
psqlClient.setAutoCommit(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jembi.jempi.shared.serdes.JsonPojoSerializer;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.UUID;

Expand Down Expand Up @@ -46,20 +47,20 @@ void open() {
try {
UUID id = UUID.randomUUID();
psqlNotifications.insert(id,
value.notificationType().toString(),
value.patientNames(),
value.linkedTo().score(),
value.timeStamp(),
value.linkedTo().gID(),
value.dID());
value.notificationType().toString(),
value.patientNames(),
value.linkedTo().score(),
new Timestamp(value.timeStamp()),
value.linkedTo().gID(),
value.dID());

for (int i = 0; i < value.candidates().size(); i++) {
psqlNotifications.insertCandidates(id,
value.candidates().get(i).score(),
value.candidates().get(i).gID());
value.candidates().get(i).score(),
value.candidates().get(i).gID());
}
} catch (SQLException e) {
LOGGER.debug(e.toString());
LOGGER.debug("Error inserting notification", e.toString());
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.jembi.jempi.shared.models.*;

import java.io.File;
import java.time.LocalDate;
import java.sql.Timestamp;
import java.util.List;
import java.util.concurrent.CompletionStage;

Expand Down Expand Up @@ -70,11 +70,12 @@ static CompletionStage<BackEnd.GetNotificationsResponse> getNotifications(
final ActorRef<BackEnd.Event> backEnd,
final int limit,
final int offset,
final LocalDate date,
final String state) {
final Timestamp startDate,
final Timestamp endDate,
final List<String> states) {
CompletionStage<BackEnd.GetNotificationsResponse> stage = AskPattern
.ask(backEnd,
replyTo -> new BackEnd.GetNotificationsRequest(replyTo, limit, offset, date, state),
replyTo -> new BackEnd.GetNotificationsRequest(replyTo, limit, offset, startDate, endDate, states),
java.time.Duration.ofSeconds(30),
actorSystem.scheduler());
return stage.thenApply(response -> response);
Expand Down Expand Up @@ -309,8 +310,7 @@ static CompletionStage<BackEnd.PostUpdateNotificationResponse> postUpdateNotific
CompletionStage<BackEnd.PostUpdateNotificationResponse> stage = AskPattern
.ask(backEnd,
replyTo -> new BackEnd.PostUpdateNotificationRequest(replyTo,
notificationRequest.notificationId(),
notificationRequest.state()),
notificationRequest.notificationId()),
java.time.Duration.ofSeconds(11),
actorSystem.scheduler());
return stage.thenApply(response -> response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.time.LocalDate;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;

Expand Down Expand Up @@ -234,8 +234,8 @@ private Behavior<Event> postFilterGidsWithInteractionCountHandler(final PostFilt
}

private Behavior<Event> getNotificationsHandler(final GetNotificationsRequest request) {
MatchesForReviewResult result =
psqlNotifications.getMatchesForReview(request.limit(), request.offset(), request.date(), request.state);
MatchesForReviewResult result = psqlNotifications.getMatchesForReview(request.limit(), request.offset(),
request.startDate(), request.endDate(), request.states());
request.replyTo.tell(new GetNotificationsResponse(result.getCount(),
result.getSkippedRecords(),
result.getNotifications()));
Expand Down Expand Up @@ -428,7 +428,7 @@ private Behavior<Event> getGidsPagedHandler(final GetGidsPagedRequest request) {

private Behavior<Event> postUpdateNotificationHandler(final PostUpdateNotificationRequest request) {
try {
psqlNotifications.updateNotificationState(request.notificationId, request.state);
psqlNotifications.updateNotificationState(request.notificationId);
} catch (SQLException exception) {
LOGGER.error(exception.getMessage());
}
Expand Down Expand Up @@ -548,8 +548,9 @@ public record GetNotificationsRequest(
ActorRef<GetNotificationsResponse> replyTo,
int limit,
int offset,
LocalDate date,
String state) implements Event {
Timestamp startDate,
Timestamp endDate,
List<String> states) implements Event {
}

public record GetNotificationsResponse(
Expand Down Expand Up @@ -592,8 +593,7 @@ public record PatchIidNewGidLinkResponse(Either<MpiGeneralError, LinkInfo> linkI

public record PostUpdateNotificationRequest(
ActorRef<PostUpdateNotificationResponse> replyTo,
String notificationId,
String state) implements Event {
String notificationId) implements Event {
}

public record PostUpdateNotificationResponse() implements EventResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import org.jembi.jempi.shared.models.MatchesForReviewResult;

import java.sql.*;
import java.time.LocalDate;
import java.util.*;

final class PsqlNotifications {
private static final String QUERY = """
SELECT patient_id, id, names, created, state,type, score, golden_id
FROM notification
WHERE created <= ? AND state = ?
ORDER BY created
LIMIT ? OFFSET ?
""";
SELECT patient_id, id, names, created, state,type, score, golden_id
FROM notification
WHERE created BETWEEN ? AND ? AND state IN (?, ?)
ORDER BY created
LIMIT ? OFFSET ?
""";
private static final Logger LOGGER = LogManager.getLogger(PsqlNotifications.class);
private final PsqlClient psqlClient;

Expand All @@ -34,29 +33,34 @@ final class PsqlNotifications {
* @param limit The maximum number of matches to retrieve.
* @param offset The number of matches to skip from the beginning.
* @param date The date threshold for match creation.
* @param state The state of notification.
* @param states The state of notification.
* @return A {@link MatchesForReviewResult} object containing the matches and related information.
*/
MatchesForReviewResult getMatchesForReview(
final int limit,
final int offset,
final LocalDate date,
final String state) {
final Timestamp startDate,
final Timestamp endDate,
final List<String> states) {
final var list = new ArrayList<HashMap<String, Object>>();
MatchesForReviewResult result = new MatchesForReviewResult();
int skippedRows = 0;
psqlClient.connect();
try (PreparedStatement preparedStatement = psqlClient.prepareStatement(QUERY);
PreparedStatement countStatement = psqlClient.prepareStatement("SELECT COUNT(*) FROM notification")) {
PreparedStatement countStatement = psqlClient.prepareStatement("SELECT COUNT(*) FROM notification WHERE created BETWEEN ? AND ? AND state IN (?, ?)")) {
countStatement.setTimestamp(1, startDate);
countStatement.setTimestamp(2, endDate);
countStatement.setString(3, extractState(0, states));
walisc marked this conversation as resolved.
Show resolved Hide resolved
countStatement.setString(4, extractState(1, states));
ResultSet countRs = countStatement.executeQuery();
countRs.next();
int totalCount = countRs.getInt(1);

preparedStatement.setDate(1, java.sql.Date.valueOf(date));
preparedStatement.setString(2, state);
preparedStatement.setInt(3, limit);
preparedStatement.setInt(4, offset);
LOGGER.debug("{}", preparedStatement);
preparedStatement.setTimestamp(1, startDate);
preparedStatement.setTimestamp(2, endDate);
preparedStatement.setString(3, extractState(0, states));
preparedStatement.setString(4, extractState(1, states));
preparedStatement.setInt(5, limit);
preparedStatement.setInt(6, offset);
ResultSet rs = preparedStatement.executeQuery();
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
Expand All @@ -82,6 +86,15 @@ MatchesForReviewResult getMatchesForReview(
return result;
}

String extractState(
final int index,
final List<String> states) {
if (index + 1 > states.size()) {
return null;
}
return states.get(index);
};

List<HashMap<String, Object>> getCandidates(final UUID nID) {
final var list = new ArrayList<HashMap<String, Object>>();
String candidates = "select notification_id, score, golden_id from candidates where notification_id IN ('" + nID + "')";
Expand Down Expand Up @@ -128,12 +141,11 @@ void insertCandidates(
}

void updateNotificationState(
final String id,
final String state) throws SQLException {
final String id) throws SQLException {
psqlClient.connect();
try (Statement stmt = psqlClient.createStatement()) {
ResultSet rs = stmt.executeQuery(String.format(Locale.ROOT,
"update notification set state = \'%s\' where id = \'%s\'", state, id));
"update notification set state = \'%s\' where id = \'%s\'", "CLOSED", id));
psqlClient.commit();
}
}
Expand Down
Loading