Skip to content

Commit c998773

Browse files
committed
feat(api,ui): Narrative ENUM migration;
This patch migrates the narrative field from a boolean type to a three-value enum across the API and client. This prepares the API and the client for the work being done for #1195. This work is independent of #1317 and #1318 but closely related to them. The latter needs to be safely integrated with this patch to ensure the changes don't conflict with one another.
1 parent 1761d7d commit c998773

17 files changed

Lines changed: 121 additions & 32 deletions

File tree

client/src/api/schemas/dbConfigurationSectionProcessing.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { DbSectionAction } from './dbSectionAction';
2+
import type { DbSectionNarrative } from './dbSectionNarrative';
23
import type { DbSectionType } from './dbSectionType';
34

45
/**
@@ -11,7 +12,7 @@ import type { DbSectionType } from './dbSectionType';
1112
*/
1213
export interface DbConfigurationSectionProcessing {
1314
include: boolean;
14-
narrative: boolean;
15+
narrative: DbSectionNarrative;
1516
action: DbSectionAction;
1617
name: string;
1718
code: string;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
export type DbSectionNarrative = typeof DbSectionNarrative[keyof typeof DbSectionNarrative];
3+
4+
5+
export const DbSectionNarrative = {
6+
retain: 'retain',
7+
remove: 'remove',
8+
refine: 'refine',
9+
} as const;

client/src/api/schemas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export * from './dbConfigurationCustomCode';
2727
export * from './dbConfigurationSectionProcessing';
2828
export * from './dbConfigurationStatus';
2929
export * from './dbSectionAction';
30+
export * from './dbSectionNarrative';
3031
export * from './dbSectionType';
3132
export * from './dbTotalConditionCodeCount';
3233
export * from './deleteSectionInput';

client/src/api/schemas/sectionUpdateInput.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { DbSectionAction } from './dbSectionAction';
2+
import type { DbSectionNarrative } from './dbSectionNarrative';
23

34
/**
4-
* Request body for modifying a section.
5+
* Input model for updating a section's processing instructions.
56
*/
67
export interface SectionUpdateInput {
78
include?: boolean | null;
8-
narrative?: boolean | null;
9+
narrative?: DbSectionNarrative | null;
910
action?: DbSectionAction | null;
1011
name?: string | null;
1112
current_code: string;

client/src/pages/Configurations/ConfigBuild/Sections/Sections.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const sections: DbConfigurationSectionProcessing[] = [
1212
action: 'refine',
1313
include: true,
1414
code: 'hist',
15-
narrative: false,
15+
narrative: 'remove',
1616
versions: ['1.1', '3.1'],
1717
section_type: 'standard',
1818
},
@@ -21,7 +21,7 @@ const sections: DbConfigurationSectionProcessing[] = [
2121
action: 'refine',
2222
include: false,
2323
code: 'med',
24-
narrative: false,
24+
narrative: 'remove',
2525
versions: ['1.1', '3.1', '3.1.1'],
2626
section_type: 'standard',
2727
},
@@ -30,7 +30,7 @@ const sections: DbConfigurationSectionProcessing[] = [
3030
action: 'retain',
3131
include: true,
3232
code: 'imm',
33-
narrative: false,
33+
narrative: 'remove',
3434
versions: ['3.1', '3.1.1'],
3535
section_type: 'standard',
3636
},
@@ -39,7 +39,7 @@ const sections: DbConfigurationSectionProcessing[] = [
3939
action: 'refine',
4040
include: true,
4141
code: 'mock-custom-section',
42-
narrative: true,
42+
narrative: 'retain',
4343
versions: [],
4444
section_type: 'custom',
4545
},

client/src/pages/Configurations/ConfigBuild/Sections/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ function NarrativeSwitch({
452452
<Field className="flex items-center gap-3">
453453
<Switch
454454
disabled={disabled}
455-
checked={currentSection.narrative}
455+
checked={currentSection.narrative === 'retain'}
456456
onChange={(checked) => {
457457
updateSection(currentSection, {
458-
narrative: checked,
458+
narrative: checked ? 'retain' : 'remove',
459459
});
460460
}}
461461
aria-label={`Toggle to refine or retain the narrative block in the ${currentSection.name} section`}

client/src/pages/Configurations/ConfigBuild/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const baseMockConfig: GetConfigurationResponse = {
104104
{
105105
name: 'Encounters Section',
106106
code: 'some code',
107-
narrative: false,
107+
narrative: 'remove',
108108
include: true,
109109
action: 'refine',
110110
versions: ['1.1'],

refiner/app/api/v1/configurations/model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
DbConfigurationSectionProcessing,
1010
DbConfigurationStatus,
1111
DbSectionAction,
12+
DbSectionNarrative,
1213
DbTotalConditionCodeCount,
1314
GetConfigurationResponseVersion,
1415
)
@@ -173,11 +174,11 @@ class DeleteSectionInput(SectionInputBase):
173174

174175
class SectionUpdateInput(BaseModel):
175176
"""
176-
Request body for modifying a section.
177+
Input model for updating a section's processing instructions.
177178
"""
178179

179180
include: bool | None = None
180-
narrative: bool | None = None
181+
narrative: DbSectionNarrative | None = None
181182
action: DbSectionAction | None = None
182183
name: str | None = None
183184
current_code: str

refiner/app/db/configurations/db.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async def insert_custom_section_db(
8989
name,
9090
"refine",
9191
True,
92-
False,
92+
"remove",
9393
versions,
9494
"custom",
9595
)
@@ -1051,9 +1051,7 @@ async def update_configuration_section_db(
10511051
(
10521052
prev_section.narrative,
10531053
section_update.narrative,
1054-
lambda old, new: (
1055-
f"narrative from '{_bool_label(old)}' to '{_bool_label(new)}'"
1056-
),
1054+
lambda old, new: (f"narrative from '{old}' to '{new}'"),
10571055
),
10581056
]
10591057

refiner/app/db/configurations/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
type DbSectionAction = Literal["retain", "refine"]
77

8+
type DbSectionNarrative = Literal["retain", "remove", "refine"]
9+
810
type DbConfigurationStatus = Literal["draft", "inactive", "active"]
911

1012
type DbSectionType = Literal["standard", "custom"]
@@ -60,7 +62,7 @@ class DbConfigurationSectionInstructions:
6062
"""
6163

6264
include: bool
63-
narrative: bool
65+
narrative: DbSectionNarrative
6466
action: DbSectionAction
6567

6668

0 commit comments

Comments
 (0)