Skip to content

Commit 743fd34

Browse files
committed
add additionalNotesObj
1 parent 5c5c8f0 commit 743fd34

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

reproschema/models/base.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
from pathlib import Path
4+
from typing import Any
45
from typing import Dict
56
from typing import List
67
from typing import Optional
@@ -43,6 +44,32 @@ def COMMON_SCHEMA_ORDER() -> list:
4344
]
4445

4546

47+
@define(kw_only=True)
48+
class AdditionalNoteObj(SchemaUtils):
49+
column: Optional[str] = field(
50+
factory=(str),
51+
converter=default_if_none(default=""), # type: ignore
52+
validator=optional(instance_of(str)),
53+
)
54+
source: Optional[str] = field(
55+
factory=(str),
56+
converter=default_if_none(default=""), # type: ignore
57+
validator=optional(instance_of(str)),
58+
)
59+
value: Any = field(default=None)
60+
61+
def __attrs_post_init__(self) -> None:
62+
63+
if self.schema_order in [None, []]:
64+
self.schema_order = [
65+
"column",
66+
"source",
67+
"value",
68+
]
69+
70+
self.update().sort_schema()
71+
72+
4673
@define(kw_only=True)
4774
class Message(SchemaUtils):
4875

@@ -216,6 +243,11 @@ def _default_context(self) -> str:
216243
converter=default_if_none(default={}), # type: ignore
217244
validator=optional(instance_of(dict)),
218245
)
246+
additionalNotesObj: Optional[list] = field(
247+
factory=(list),
248+
converter=default_if_none(default=[]), # type: ignore
249+
validator=optional(instance_of(list)),
250+
)
219251

220252
"""
221253
UI related
@@ -318,6 +350,7 @@ def update(self) -> None:
318350
"compute",
319351
"question",
320352
"messages",
353+
"additionalNotesObj",
321354
]
322355
for key in keys_to_update:
323356
self.schema[key] = self.__getattribute__(key)

reproschema/models/item.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pathlib import Path
2+
from typing import Any
23
from typing import Dict
4+
from typing import List
35
from typing import Optional
46
from typing import Union
57

@@ -27,6 +29,7 @@ def __init__(
2729
audio: Optional[Union[str, Dict[str, str]]] = None,
2830
video: Optional[Union[str, Dict[str, str]]] = None,
2931
preamble: Optional[str] = None,
32+
additionalNotesObj: List[Dict[str, Any]] = None,
3033
visible: Optional[bool] = True,
3134
required: Optional[bool] = False,
3235
skippable: Optional[bool] = True,
@@ -43,6 +46,7 @@ def __init__(
4346
schema_order = COMMON_SCHEMA_ORDER() + [
4447
"question",
4548
"responseOptions",
49+
"additionalNotesObj",
4650
]
4751

4852
super().__init__(
@@ -57,6 +61,7 @@ def __init__(
5761
image=image,
5862
audio=audio,
5963
video=video,
64+
additionalNotesObj=additionalNotesObj,
6065
schema_order=schema_order,
6166
visible=visible,
6267
required=required,

reproschema/models/tests/test_item.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
from asyncio import QueueEmpty
32
from pathlib import Path
43

54
import pytest
@@ -8,6 +7,7 @@
87
from utils import output_dir
98
from utils import read_json
109

10+
from reproschema.models.base import AdditionalNoteObj
1111
from reproschema.models.item import Item
1212
from reproschema.models.item import ResponseOption
1313

@@ -166,6 +166,20 @@ def test_slider():
166166

167167
def test_item1():
168168

169+
additionalNotes = [
170+
AdditionalNoteObj(
171+
column="notes", source="redcap", value="some extra note"
172+
).schema
173+
]
174+
print(additionalNotes)
175+
additionalNotes.append(
176+
AdditionalNoteObj(
177+
column="notes",
178+
source="redcap",
179+
value={"@id": "http://example.com/iri-example"},
180+
).schema
181+
)
182+
169183
item = Item(
170184
name="item1",
171185
input_type="radio",
@@ -179,6 +193,7 @@ def test_item1():
179193
"@type": "AudioObject",
180194
"contentUrl": "http://media.freesound.org/sample-file.mp4",
181195
},
196+
additionalNotesObj=additionalNotes,
182197
read_only=None,
183198
output_dir=item_dir,
184199
)

0 commit comments

Comments
 (0)