Skip to content

Commit bded662

Browse files
committed
Merge branch 'feature/PI-650-read_as_device' into release/2024-12-11
2 parents 2daf63b + 3297c3c commit bded662

File tree

5 files changed

+461
-9
lines changed

5 files changed

+461
-9
lines changed

src/api/createDeviceAccreditedSystem/src/v1/steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def add_device_reference_data_id(data, cache) -> Device:
115115
device_reference_data: DeviceReferenceData = data[read_device_reference_data]
116116
for drd in device_reference_data:
117117
as_device.add_device_reference_data_id(
118-
device_reference_data_id=str(drd.id), path_to_data=["*.Interaction ID"]
118+
device_reference_data_id=str(drd.id), path_to_data=["Interaction ID"]
119119
)
120120
return as_device
121121

src/api/readDevice/src/v1/steps.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,34 @@ def read_device_reference_data(data, cache) -> list[DeviceReferenceData]:
7474
id=id,
7575
)
7676
device_reference_datas.append(drd)
77-
7877
return device_reference_datas
7978

8079

80+
def filter_by_jsonpath(data, filters: list) -> dict:
81+
response = {}
82+
if "*" not in filters:
83+
response = {filter_key: data[filter_key] for filter_key in filters}
84+
return response
85+
return data
86+
87+
88+
def filter_device_reference_data(data, cache) -> list[DeviceReferenceData]:
89+
device: Device = data[read_device]
90+
device_reference_data_list: list[DeviceReferenceData] = data[
91+
read_device_reference_data
92+
]
93+
94+
for drd in device_reference_data_list:
95+
filters = device.device_reference_data[str(drd.id)]
96+
for questionnaire_response in drd.questionnaire_responses.values():
97+
for qr in questionnaire_response:
98+
qr.data = filter_by_jsonpath(data=qr.data, filters=filters)
99+
return device_reference_data_list
100+
101+
81102
def update_device_with_device_reference_data(data, cache) -> Device:
82103
device: Device = data[read_device]
83104
device_reference_datas = data[read_device_reference_data]
84-
85105
[
86106
device.questionnaire_responses.setdefault(key, []).extend(responses)
87107
for drd in device_reference_datas
@@ -102,6 +122,7 @@ def device_to_dict(data, cache) -> tuple[str, dict]:
102122
read_product,
103123
read_device,
104124
read_device_reference_data,
125+
filter_device_reference_data,
105126
update_device_with_device_reference_data,
106127
device_to_dict,
107128
]

0 commit comments

Comments
 (0)