1. Ticket Details
| Ticket ID | AMM-1887 |
| Severity | High |
| Category | Bug |
| Affected Module / Feature | HWC-UI Nurse Module |
...
2. Issue Description
User facing issue in the HWC application. After filling in all the details under the Nurse section, when user tries to submit, an error screen appears.
...
3. Root Cause Analysis (RCA)
Primary Root Cause Identified:
Incorrect filter chaining in VAN list processing - The second filter operation infilterVanList()operates on the original unfiltered array instead of the result from the first filter, causing it to overwrite correctly filtered results with incorrect data. service.component.ts:104-114 of HWC-UIWhy it happened:
- Incorrect variable reference: The second filter uses
vanServicepointDetails(original array) instead ofthis.vansList(filtered result) service.component.ts:111-114- Lack of intermediate variable: No intermediate variable was used to store the first filter's result before applying the second filter
- Duplicate code pattern: The same bug exists in both
ServiceComponentandServicePointComponent, suggesting copy-paste without proper review service-point.component.ts:146-156
Why wasn't it caught earlier?
The bug has low visibility because it requires specific data patterns to manifest, explaining why it wasn't caught in testing(still not reproducible in lower environments) or early production use.
...
4. Corrective Actions (Fixes for this instance)
Replace the second filter to operate on the filtered result:
this.vansList = vanServicepointDetails.filter((van: any) => { if (van.vanSession === 3) { return van; } });
// Fix: Use this.vansList instead of vanServicepointDetails this.vansList = this.vansList.filter( (thing: any, i: any, arr: any) => arr.findIndex((t: any) => t.vanID === thing.vanID) === i, );Apply the same fix to both
ServiceComponent.filterVanList()andServicePointComponent.filterVanList(). service.component.ts:104-116 service-point.component.ts:146-157
...
5. Preventive Actions (To prevent recurrence)
1. Code Review Checklist
- Verify filter chains operate on intermediate results, not original arrays
- Check for duplicate filtering logic across components (e.g.,
ServiceComponentandServicePointComponent) - Ensure variable references match intended data flow
...
- Extract filtering logic into a shared service to prevent code duplication.
...
6. Verification of Effectiveness
- Test with API response containing multiple VANs with same
vanID- Verify correct VAN selection when
vanSession: 3is not first entry- Confirm proper error messaging when no active sessions exist
...
7. Lessons Learned
1. Filter Chain Pitfalls
- Always operate on intermediate results, not original arrays in multi-step transformations
- JavaScript filter methods don't modify the original array - reassignment matters
2. Code Duplication Risks
- Duplicate logic across components (
ServiceComponentandServicePointComponent) doubles maintenance burden and bug surface area3. Silent Failures
- Bugs that fail silently (setting
undefinedwithout errors) are harder to detect- Add explicit validation and error handling for critical data flows
...
8. CAPA Review & Closure
| Reviewed By | Date | Remarks |
|---|---|---|