In my dataset, each client is associated with a set of cases. I am looking to extract only those clients who have cases with the status "Open". Clients with cases marked as "Closed" should not be included in the filtered list. Currently, my filtering method successfully filters out clients with "Open" cases, but those with "Closed" cases are still visible with a case type of 0. I want to completely hide these clients.
var clientData = {
"clientId": "1cb8fe0f-2d21-4e5b-99e9-fbbdf0eebdc7",
"staffId": "b7b0897a-8d40-408e-841b-598c3c425762",
"clientFirstName": "Antonia",
"clientMiddleName": "Elliott",
"clientLastName": "Schmeler",
"preferredName": "Randall_Jenkins36",
"clientNumber": "10459431",
"clientDOB": "1967-04-18T18:59:57.291",
"streetAddress": "073 Logan Plains",
"city": "Camarillo",
"state": "VT",
"zip": "81652",
"homePhone": "424-790-1552",
"mobilePhone": "850-265-2651",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="edaf9f8282869edbdead948c858282c38e8280">[email protected]</a>",
"isActive": "Y",
"createdDate": "08/09/2022 08:50:46",
"modifiedDate": null,
"reportStatus": null,
"clientCases": [
{
"caseId": "1045868d-4fca-424d-9221-c287dbd6ecde",
"clientId": "1cb8fe0f-2d21-4e5b-99e9-fbbdf0eebdc7",
"caseName": "International Infrastructure Supervisor",
"caseNumber": "96511392",
"caseType": "Private referral",
"caseStatus": "Open",
"createdDate": "01/01/2022 09:10:00",
"modifiedDate": null
},
{
"caseId": "2045868d-4fca-424d-9221-c287dbd6ecde",
"clientId": "1cb8fe0f-2d21-4e5b-99e9-fbbdf0eebdc7",
"caseName": "Infrastructure Supervisor",
"caseNumber": "26511392",
"caseType": "Private referral",
"caseStatus": "Closed",
"createdDate": "01/01/2022 09:10:00",
"modifiedDate": null
}
]
},
{
"clientId": "1cb8fe0f-2d21-4e5b-99e9-fbbdf0eebdc7",
"staffId": "b7b0897a-8d40-408e-841b-598c3c425762",
"clientFirstName": "Antonia",
"clientMiddleName": "Elliott",
"clientLastName": "Schmeler",
"preferredName": "Randall_Jenkins36",
"clientNumber": "10459431",
"clientDOB": "1967-04-18T18:59:57.291",
"streetAddress": "073 Logan Plains",
"city": "Camarillo",
"state": "VT",
"zip": "81652",
"homePhone": "424-790-1552",
"mobilePhone": "850-265-2651",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="76340419191d054045360f171e19195815191b">[email protected]</a>",
"isActive": "Y",
"createdDate": "08/09/2022 08:50:46",
"modifiedDate": null,
"reportStatus": null,
"clientCases": [
{
"caseId": "1045868d-4fca-424d-9221-c287dbd6ecde",
"clientId": "1cb8fe0f-2d21-4e5b-99e9-fbbdf0eebdc7",
"caseName": "International Infrastructure Supervisor",
"caseNumber": "96511392",
"caseType": "Private referral",
"caseStatus": "Closed",
"createdDate": "01/01/2022 09:10:00",
"modifiedDate": null
}
]
}
Expected Value
{
"clientId": "1cb8fe0f-2d21-4e5b-99e9-fbbdf0eebdc7",
"staffId": "b7b0897a-8d40-408e-841b-598c3c425762",
"clientFirstName": "Antonia",
"clientMiddleName": "Elliott",
"clientLastName": "Schmeler",
"preferredName": "Randall_Jenkins36",
"clientNumber": "10459431",
"clientDOB": "1967-04-18T18:59:57.291",
"streetAddress": "073 Logan Plains",
"city": "Camarillo",
"state": "VT",
"zip": "81652",
"homePhone": "424-790-1552",
"mobilePhone": "850-265-2651",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c684b4a9a9adb5f0f586bfa7aea9a9e8a5a9ab">[email protected]</a>",
"isActive": "Y",
"createdDate": "08/09/2022 08:50:46",
"modifiedDate": null,
"reportStatus": null,
"clientCases": [
{
"caseId": "1045868d-4fca-424d-9221-c287dbd6ecde",
"clientId": "1cb8fe0f-2d21-4e5b-99e9-fbbdf0eebdc7",
"caseName": "International Infrastructure Supervisor",
"caseNumber": "96511392",
"caseType": "Private referral",
"caseStatus": "Open",
"createdDate": "01/01/2022 09:10:00",
"modifiedDate": null
}
}
The current filtering method successfully narrows down the results, but if clients have closed cases, I do not want them to appear in the array at all.
let cloned = _.cloneDeep(this.clientData);
let filtered = cloned.map((i) => {
i.clientCases = i.clientCases.filter((c) => c.caseStatus == 'Open');
return i;
});