Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Omit Report Scores with Scoring Type "Score" from the Report Summary Screen (M2-8097) #875

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
20.10.0
9 changes: 9 additions & 0 deletions src/entities/activity/lib/types/activityReportSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,20 @@ export type ScoreConditionalLogic = {
conditions: Array<Condition>;
};

export const ScoreReportScoringType = ['score', 'raw_score'] as const;

export type ScoreReportScoringType = (typeof ScoreReportScoringType)[number];

export type Report = {
id: string;
calculationType: CalculationType;
includedItems: Array<string>;
name: string;
type: ReportType;
conditionalLogic: Array<ScoreConditionalLogic>;

/** Whether to show raw score or T scores in the report */
scoringType: ScoreReportScoringType;
/** The name of a subscale to use for a lookup table, if `scoringType` is set to "score" */
subscaleName?: string;
};
1 change: 1 addition & 0 deletions src/entities/activity/model/mappers.input.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ export const conditionalInput: ActivityDto = {
{
itemsScore: ['one'],
type: 'score',
scoringType: 'raw_score',
id: '1',
name: 'name',
calculationType: 'sum',
Expand Down
1 change: 1 addition & 0 deletions src/entities/activity/model/mappers.output.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,7 @@ export const conditionalOutput: ActivityDetails = {
includedItems: ['one'],
name: 'name',
type: 'score',
scoringType: 'raw_score',
},
],
showAllAtOnce: false,
Expand Down
2 changes: 2 additions & 0 deletions src/entities/activity/model/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ export function mapToActivity(dto: ActivityDto): ActivityDetails {
calculationType: x.calculationType,
conditionalLogic: x.conditionalLogic,
includedItems: x.itemsScore,
scoringType: x.scoringType,
subscaleName: x.subscaleName,
})),
};

Expand Down
8 changes: 8 additions & 0 deletions src/features/pass-survey/model/ScoresExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export class ScoresExtractor implements IScoresExtractor {
);

for (const scoreSettings of settings) {
if (
scoreSettings.type === 'score' &&
scoreSettings.scoringType === 'score'
) {
// Skip report scores that are not configured as raw scores
continue;
}

const logScore = `'${scoreSettings.name}' for settings with index '${settingsIndex}'`;

try {
Expand Down
32 changes: 32 additions & 0 deletions src/features/pass-survey/model/tests/ScoresExtractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ describe('ScoresCalculator: test collectScoreForRadio', () => {
includedItems: [RadioItemName, CheckboxesItemName, SliderItemName],
name: 'mock-report-name-1',
type: 'score',
scoringType: 'raw_score',
},
];

Expand Down Expand Up @@ -247,6 +248,7 @@ describe('ScoresCalculator: test collectScoreForRadio', () => {
includedItems: [RadioItemName, CheckboxesItemName, SliderItemName],
name: 'mock-report-name-1',
type: 'score',
scoringType: 'raw_score',
},
{
calculationType: 'average',
Expand All @@ -255,6 +257,7 @@ describe('ScoresCalculator: test collectScoreForRadio', () => {
includedItems: [RadioItemName, CheckboxesItemName, SliderItemName],
name: 'mock-report-name-2',
type: 'score',
scoringType: 'raw_score',
},
{
calculationType: 'percentage',
Expand All @@ -263,6 +266,7 @@ describe('ScoresCalculator: test collectScoreForRadio', () => {
includedItems: [RadioItemName, CheckboxesItemName, SliderItemName],
name: 'mock-report-name-3',
type: 'score',
scoringType: 'raw_score',
},
];

Expand Down Expand Up @@ -328,6 +332,7 @@ describe('ScoresCalculator: test collectScoreForRadio', () => {
includedItems: selectedItems,
name: 'mock-report-name-1',
type: 'score',
scoringType: 'raw_score',
},
];

Expand All @@ -347,6 +352,32 @@ describe('ScoresCalculator: test collectScoreForRadio', () => {
},
);

it('Should exclude report items with scoringType "score"', () => {
const { pipelineItems, answers } = getItemsAndAnswers();

const reportSettings: Report[] = [
{
calculationType: 'sum',
conditionalLogic: [],
id: 'mock-report-id-1',
includedItems: ['item-radio', 'item-checkboxes'],
name: 'mock-report-name-1',
type: 'score',
scoringType: 'score',
subscaleName: 'mock-subscale-name-1',
},
];

const result: ScoreRecord[] = extractor.extract(
pipelineItems,
answers,
reportSettings,
'mock-log-activity-name-1',
);

expect(result).toHaveLength(0);
});

it("Should return 517 and flagged set to true when calculationType is 'sum' and one condition is set: equal to 517", () => {
const { pipelineItems, answers } = getItemsAndAnswers();

Expand All @@ -372,6 +403,7 @@ describe('ScoresCalculator: test collectScoreForRadio', () => {
includedItems: [RadioItemName, CheckboxesItemName, SliderItemName],
name: 'mock-report-name-1',
type: 'score',
scoringType: 'raw_score',
},
];

Expand Down
8 changes: 8 additions & 0 deletions src/shared/api/services/ActivityReportSettingsDtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ type CalculationType = 'average' | 'percentage' | 'sum';

type MatchType = 'all' | 'any';

const ScoreReportScoringType = ['score', 'raw_score'] as const;

type ScoreReportScoringType = (typeof ScoreReportScoringType)[number];

type ConditionDto =
| GreaterThanCondition
| LessThanCondition
Expand Down Expand Up @@ -77,4 +81,8 @@ export type ReportDto = {
name: string;
type: ReportType;
conditionalLogic: Array<ScoreConditionalLogicDto>;
/** Whether to show raw score or T scores in the report */
scoringType: ScoreReportScoringType;
/** The name of a subscale to use for a lookup table, if `scoringType` is set to "score" */
subscaleName?: string;
};
Loading