I have following response from a sql query
| timezoneanddate | source |description| interval_start | unique_id | timestampdifference |
| -------- | -------- |------------ --------------- --------- -------------------
|2024-08-01 06:05:25.930 |comments |provider will changed from null to john | 2024-08-01 06:00:00.000 | 1 | 2
|2024-08-01 06:07:25.930 |comments |Blood pressure | 2024-08-01 06:00:00.000 | 1 | 2
|2024-08-01 14:23:30.916 |status |processor_name Changed - From System to Amiya; | 2024-08-01 14:15:00.000 | 2 | 2
|2024-08-01 14:25:44.029 |record |urgency_reason Changed - From Check-up to Check-up needed; | 2024-08-01 14:15:00.000 | 2 | 2
|2024-08-01 15:18:56.665 |record |svc_from_date1 Changed - From 2024-03-01 to 2024-03-02; | 2024-08-01 15:15:00.000 | 3 | 1
|2024-08-01 15:19:43.206 |status |location_details Changed - From Intake to Work; | 2024-08-01 15:15:00.000 | 3 | 1
|2024-08-01 15:20:01.150 |comments |Surgery | 2024-08-01 15:15:00.000 | 3 | 1
|2024-08-01 15:34:01.150 |comments |auth type changes | 2024-08-01 15:30:00.000 | 4 | 6
|2024-08-01 15:40:01.150 |comments |Diabetes | 2024-08-01 15:30:00.000 | 4 | 6
|2024-08-01 15:45:01.150 |comments |provider will change | 2024-08-01 15:45:00.000 | 5 | 0
|2024-08-02 07:07:41.161 |status |location_details Changed - From Work to Medical Director Review; | 2024-08-02 07:00:00.000 | 6 | 0
|2024-08-05 06:50:38.348 |status |location_details Changed - From Medical Director Review to Information; | 2024-08-05 06:45:00.000 | 7 | 0
|2024-08-05 12:12:29.479 |status |processor_name Changed - From Amiya to Josephine; | 2024-08-05 12:00:00.000 | 8 | 0
Need to convert above result in to below format based on unique Id and Max timezoneanddate using java spring boot api
if source == "comments" then
{"dateandTime": "2024-08-01 06:07:25.930", "remarks": ["provider will changed from null to john, "Blood pressure"], "actionsandChanges":[], "duration": 2}
if source == "status" or source == "record" then
{"dateandtime":"2024-08-01 14:25:44.029", "remarks":[], "actionsandchanges":["processor_name Changed - From System to Amiya;, "urgency_reason Changed - From Check-up to Check-up needed;"], "duration": 2}