Sensory ZPP refactor - #46
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request successfully refactors the Sensory Zone of Partial Preservation (Sensory ZPP) calculation to use a step-based, chain-of-command design pattern that mirrors the existing Motor ZPP implementation. The refactor improves code maintainability and transparency by breaking down the calculation into discrete, traceable steps that clinicians can follow.
Changes:
- Refactored Sensory ZPP calculation from a procedural loop-based approach to a step-based chain-of-command pattern with five distinct steps: checkIfSensoryZPPIsApplicable, checkSacralLevel, getTopAndBottomLevelsForCheck, checkLevel, and sortSensoryZPP
- Extracted shared Step and StepHandler types to
src/classification/common/step.tsfor reuse across both Motor and Sensory ZPP modules - Added comprehensive documentation including a detailed README and architecture specification document explaining the algorithm logic and step-by-step flow
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/classification/common/step.ts | New shared module defining generic Step |
| src/classification/zoneOfPartialPreservation/sensoryZPP.ts | Complete refactor of sensory ZPP calculation using step-based pattern; maintains algorithm fidelity with original implementation |
| src/classification/zoneOfPartialPreservation/sensoryZPPErrors.ts | New error handling with SensoryZPPError class and centralized error messages following Motor ZPP pattern |
| src/classification/zoneOfPartialPreservation/sensoryZPP.spec.ts | Comprehensive test suite covering all step functions, edge cases, and generator function; 300+ tests maintained |
| src/classification/zoneOfPartialPreservation/motorZPP.ts | Updated to use shared step types from common/step.ts; added params to translation keys for better templating |
| src/en.ts | Added 13 new Sensory ZPP translation keys; updated 3 Motor ZPP translation keys to include level name parameters |
| src/classification/zoneOfPartialPreservation/README.md | New comprehensive documentation explaining both Sensory and Motor ZPP algorithms with step-by-step descriptions and flow diagrams |
| docs/sensoryZPP-architecture.md | Detailed architecture specification document describing the refactor design, step definitions, and implementation details |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - Else: | ||
| - Call `checkLevelForSensoryZPP(side, currentLevel.name, variable)`. | ||
| - `variable = variable || result.variable`. | ||
| - If `result.level` → unshift `result.level` to zpp. |
There was a problem hiding this comment.
The architecture documentation states "If result.level → unshift result.level to zpp" (line 115), but the actual implementation uses push (append) with [...state.zpp, result.level]. The documentation should say "push" or "append" instead of "unshift" to match the implementation.
| - If `result.level` → unshift `result.level` to zpp. | |
| - If `result.level` → push/append `result.level` to zpp. |
441dacd to
6c9279a
Compare
Closes #43
Refactors the calculation for the Sensory Zone of Partial Preservation using the chain-of-command design pattern to match the calculations for motor ZPP.