Skip to content

Commit 19af2d3

Browse files
authored
Merge pull request #13583 from SORMAS-Foundation/bugfix-13555-phone_dd_save_error
#13555 - Fixed notifier query to correctly get the most recent version
2 parents 5e36a64 + 0a3b2ff commit 19af2d3

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

sormas-backend/src/main/java/de/symeda/sormas/backend/person/notifier/NotifierService.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,10 @@ public Notifier getByUuidAndTime(String uuid, Instant time) {
9191

9292
final Timestamp timestamp = Timestamp.from(time);
9393

94-
final String sql = "SELECT " + "a.id AS id, a.uuid AS uuid," + "COALESCE(b.changedate, a.changedate) AS changedate,"
95-
+ "a.creationdate AS creationdate, a.change_user_id AS change_user_id,"
96-
+ "COALESCE(b.registrationnumber, a.registrationnumber) AS registrationnumber," + "COALESCE(b.firstname, a.firstname) AS firstname,"
97-
+ "COALESCE(b.lastname, a.lastname) AS lastname," + "COALESCE(b.address, a.address) AS address," + "COALESCE(b.email, a.email) AS email,"
98-
+ "COALESCE(b.phone, a.phone) AS phone, "+ "COALESCE(b.agentfirstname, a.agentfirstname) AS agentfirstname, "
99-
+ "COALESCE(b.agentlastname, a.agentlastname) AS agentlastname "+ "FROM notifier a " + "LEFT JOIN " + "(SELECT * FROM notifier_history "
100-
+ "WHERE uuid = :uuid AND changedate <= CAST(:changeDate AS TIMESTAMP) " + "ORDER BY changedate DESC LIMIT 1" + ") b ON a.uuid = b.uuid "
101-
+ "WHERE a.uuid = :uuid";
94+
final String sql = "SELECT * FROM ("
95+
+ "SELECT * FROM (SELECT * FROM notifier_history b WHERE b.uuid = :uuid AND changedate <= CAST(:changeDate AS TIMESTAMP) ORDER BY changedate DESC LIMIT 1) "
96+
+ "UNION SELECT * FROM notifier a WHERE a.uuid = :uuid) "
97+
+ "WHERE uuid = :uuid AND changedate <= CAST(:changeDate AS TIMESTAMP) ORDER BY changedate DESC LIMIT 1;";
10298

10399
Query query = em.createNativeQuery(sql, Notifier.class);
104100
query.setParameter("uuid", uuid);

0 commit comments

Comments
 (0)