I have been receiving API JSON data in a specific format and am currently working on reorganizing it. The goal is to group the data first by the start_date and then by the phys_id. The aim is to showcase the available appointment dates followed by each provider's availability.
"Today"
Provider Name #1
2:20pm
2:40pm
Provider Name #2
1:00pm
2:40pm
"Tomorrow"
Provider Name #1
3:20pm
4:40pm
Provider Name #2
12:00pm
1:40pm
This is how the data is currently structured:
results: [
{
start_date: "20191119",
begintime: "1220",
appResourceId: "DAD6C44B-3CAC-4BDA-A485-F4BB033FA928",
appLocationId: "14A1B866-8393-4510-8144-A45B5C4FD07D",
phys_id: "035B4177-EF4C-492F-86C8-7157B034DB4A"
},
...
]
To group the data by start_date, I've used the following code snippet:
let group = this.results.reduce((r, a) => {
r[a.start_date] = [...(r[a.start_date] || []), a];
return r;
}, {});
return group;
The code above helps in structuring the data by start_date, but my next step is to further group the nested array by phys_id so that each provider's available appointment times are displayed. Is there a more efficient way to achieve this, or should I approach it differently?