Skip to content

Commit 931a82a

Browse files
authored
Merge pull request #343 from ansforge/feat/rc-sr-conversion
Feat/rc sr conversion
2 parents 6f9d244 + 3eb130e commit 931a82a

7 files changed

Lines changed: 316 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from typing import Dict, Any
2+
3+
from converter.cisu.base_cisu_converter import BaseCISUConverter
4+
5+
6+
class ResourcesStatusConverter(BaseCISUConverter):
7+
@classmethod
8+
def get_rs_message_type(cls) -> str:
9+
return "resourcesStatus"
10+
11+
@classmethod
12+
def get_cisu_message_type(cls) -> str:
13+
return "resourcesStatusCisu"
14+
15+
@classmethod
16+
def from_rs_to_cisu(cls, edxl_json) -> Dict[str, Any]:
17+
output_json = cls.copy_rs_input_content(edxl_json)
18+
output_use_case_json = cls.copy_rs_input_use_case_content(edxl_json)
19+
return cls.format_cisu_output_json(output_json, output_use_case_json)
20+
21+
@classmethod
22+
def from_cisu_to_rs(cls, edxl_json: Dict[str, Any]) -> Dict[str, Any]:
23+
output_json = cls.copy_cisu_input_content(edxl_json)
24+
output_use_case_json = cls.copy_cisu_input_use_case_content(edxl_json)
25+
return cls.format_rs_output_json(output_json, output_use_case_json)

converter/converter/conversion_strategy/cisu_conversion_strategy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from converter.cisu.resources_info.resources_info_cisu_converter import (
88
ResourcesInfoCISUConverter,
99
)
10+
from converter.cisu.resources_status.resources_status_converter import (
11+
ResourcesStatusConverter,
12+
)
1013
from converter.constants import Constants
1114
from converter.cisu.constants import CISUConstants
1215
from converter.conversion_strategy.health_conversion_strategy import (
@@ -81,6 +84,10 @@ def select_conversion_strategy(message_content):
8184
return CreateCaseCISUConverter
8285
elif "resourcesInfo" in message_content or "resourcesInfoCisu" in message_content:
8386
return ResourcesInfoCISUConverter
87+
elif (
88+
"resourcesStatus" in message_content or "resourcesStatusCisu" in message_content
89+
):
90+
return ResourcesStatusConverter
8491
elif "reference" in message_content:
8592
return ReferenceConverter
8693
else:
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# -*- coding: utf-8 -*-
2+
# snapshottest: v1 - https://goo.gl/zC4yUc
3+
from __future__ import unicode_literals
4+
5+
from snapshottest import Snapshot
6+
7+
8+
snapshots = Snapshot()
9+
10+
snapshots["TestResourcesStatusConverter::test_exhaustive_snapshot_cisu_to_rs 1"] = """{
11+
"distributionID": "fr.health.samuA_2608323d-507d-4cbf-bf74-52007f8124ea",
12+
"senderID": "fr.health.samuA",
13+
"dateTimeSent": "2022-09-27T08:23:34+02:00",
14+
"dateTimeExpires": "2072-09-27T08:23:34+02:00",
15+
"distributionStatus": "Actual",
16+
"distributionKind": "Report",
17+
"descriptor": {
18+
"language": "fr-FR",
19+
"explicitAddress": {
20+
"explicitAddressScheme": "hubex",
21+
"explicitAddressValue": "fr.health.samuB"
22+
}
23+
},
24+
"content": [
25+
{
26+
"jsonContent": {
27+
"embeddedJsonContent": {
28+
"message": {
29+
"messageId": "2608323d-507d-4cbf-bf74-52007f8124ea",
30+
"sender": {
31+
"name": "samuA",
32+
"URI": "hubsante:fr.health.samuA"
33+
},
34+
"sentAt": "2022-09-27T08:23:34+02:00",
35+
"status": "Actual",
36+
"kind": "Report",
37+
"recipient": [
38+
{
39+
"name": "samuB",
40+
"URI": "hubsante:fr.health.samuB"
41+
}
42+
],
43+
"resourcesStatus": {
44+
"caseId": "fr.health.samu440.DRFR154402413800236",
45+
"resourceId": "fr.health.samu440.resource.VLM2",
46+
"state": {
47+
"datetime": "2024-05-18T18:46:00+02:00",
48+
"status": "RETOUR",
49+
"availability": true
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
]
57+
}"""
58+
59+
snapshots["TestResourcesStatusConverter::test_exhaustive_snapshot_rs_to_cisu 1"] = """{
60+
"distributionID": "fr.health.samuA_2608323d-507d-4cbf-bf74-52007f8124ea",
61+
"senderID": "fr.health.samuA",
62+
"dateTimeSent": "2022-09-27T08:23:34+02:00",
63+
"dateTimeExpires": "2072-09-27T08:23:34+02:00",
64+
"distributionStatus": "Actual",
65+
"distributionKind": "Report",
66+
"descriptor": {
67+
"language": "fr-FR",
68+
"explicitAddress": {
69+
"explicitAddressScheme": "hubex",
70+
"explicitAddressValue": "fr.health.samuB"
71+
}
72+
},
73+
"content": [
74+
{
75+
"jsonContent": {
76+
"embeddedJsonContent": {
77+
"message": {
78+
"messageId": "2608323d-507d-4cbf-bf74-52007f8124ea",
79+
"sender": {
80+
"name": "samuA",
81+
"URI": "hubsante:fr.health.samuA"
82+
},
83+
"sentAt": "2022-09-27T08:23:34+02:00",
84+
"status": "Actual",
85+
"kind": "Report",
86+
"recipient": [
87+
{
88+
"name": "samuB",
89+
"URI": "hubsante:fr.health.samuB"
90+
}
91+
],
92+
"resourcesStatusCisu": {
93+
"caseId": "fr.health.samu440.DRFR154402413800236",
94+
"resourceId": "fr.health.samu440.resource.VLM2",
95+
"state": {
96+
"datetime": "2024-05-18T18:46:00+02:00",
97+
"status": "RETOUR",
98+
"availability": true
99+
}
100+
}
101+
}
102+
}
103+
}
104+
}
105+
]
106+
}"""
107+
108+
snapshots["TestResourcesStatusConverter::test_required_snapshot_cisu_to_rs 1"] = """{
109+
"distributionID": "fr.health.samuA_2608323d-507d-4cbf-bf74-52007f8124ea",
110+
"senderID": "fr.health.samuA",
111+
"dateTimeSent": "2022-09-27T08:23:34+02:00",
112+
"dateTimeExpires": "2072-09-27T08:23:34+02:00",
113+
"distributionStatus": "Actual",
114+
"distributionKind": "Report",
115+
"descriptor": {
116+
"language": "fr-FR",
117+
"explicitAddress": {
118+
"explicitAddressScheme": "hubex",
119+
"explicitAddressValue": "fr.health.samuB"
120+
}
121+
},
122+
"content": [
123+
{
124+
"jsonContent": {
125+
"embeddedJsonContent": {
126+
"message": {
127+
"messageId": "2608323d-507d-4cbf-bf74-52007f8124ea",
128+
"sender": {
129+
"name": "samuA",
130+
"URI": "hubsante:fr.health.samuA"
131+
},
132+
"sentAt": "2022-09-27T08:23:34+02:00",
133+
"status": "Actual",
134+
"kind": "Report",
135+
"recipient": [
136+
{
137+
"name": "samuB",
138+
"URI": "hubsante:fr.health.samuB"
139+
}
140+
],
141+
"resourcesStatus": {
142+
"caseId": "fr.health.samu440.DRFR154402413800236",
143+
"resourceId": "fr.health.samu440.resource.VLM2",
144+
"state": {
145+
"datetime": "2024-05-18T18:46:00+02:00",
146+
"status": "ORIENTAT"
147+
}
148+
}
149+
}
150+
}
151+
}
152+
}
153+
]
154+
}"""
155+
156+
snapshots["TestResourcesStatusConverter::test_required_snapshot_rs_to_cisu 1"] = """{
157+
"distributionID": "fr.health.samuA_2608323d-507d-4cbf-bf74-52007f8124ea",
158+
"senderID": "fr.health.samuA",
159+
"dateTimeSent": "2022-09-27T08:23:34+02:00",
160+
"dateTimeExpires": "2072-09-27T08:23:34+02:00",
161+
"distributionStatus": "Actual",
162+
"distributionKind": "Report",
163+
"descriptor": {
164+
"language": "fr-FR",
165+
"explicitAddress": {
166+
"explicitAddressScheme": "hubex",
167+
"explicitAddressValue": "fr.health.samuB"
168+
}
169+
},
170+
"content": [
171+
{
172+
"jsonContent": {
173+
"embeddedJsonContent": {
174+
"message": {
175+
"messageId": "2608323d-507d-4cbf-bf74-52007f8124ea",
176+
"sender": {
177+
"name": "samuA",
178+
"URI": "hubsante:fr.health.samuA"
179+
},
180+
"sentAt": "2022-09-27T08:23:34+02:00",
181+
"status": "Actual",
182+
"kind": "Report",
183+
"recipient": [
184+
{
185+
"name": "samuB",
186+
"URI": "hubsante:fr.health.samuB"
187+
}
188+
],
189+
"resourcesStatusCisu": {
190+
"caseId": "fr.health.samu440.DRFR154402413800236",
191+
"resourceId": "fr.health.samu440.resource.VLM2",
192+
"state": {
193+
"datetime": "2024-05-18T18:46:00+02:00",
194+
"status": "ORIENTAT"
195+
}
196+
}
197+
}
198+
}
199+
}
200+
}
201+
]
202+
}"""
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import json
2+
from snapshottest import TestCase
3+
from converter.cisu.resources_status.resources_status_converter import (
4+
ResourcesStatusConverter,
5+
)
6+
from tests.constants import TestConstants
7+
from tests.test_helpers import TestHelper
8+
9+
RS_SR_SCHEMA = TestHelper.load_schema("RS-SR.schema.json")
10+
RC_SR_SCHEMA = TestHelper.load_schema("RC-SR.schema.json")
11+
12+
13+
class TestResourcesStatusConverter(TestCase):
14+
def test_exhaustive_snapshot_rs_to_cisu(self):
15+
message = TestHelper.create_edxl_json_from_sample(
16+
TestConstants.EDXL_HEALTH_TO_HEALTH_ENVELOPE_PATH,
17+
"tests/fixtures/RS-SR/RS-SR_V3.0_exhaustive_fill.json",
18+
)
19+
output_data = ResourcesStatusConverter.from_rs_to_cisu(message)
20+
self.assertMatchSnapshot(json.dumps(output_data, indent=2))
21+
22+
def test_exhaustive_snapshot_cisu_to_rs(self):
23+
message = TestHelper.create_edxl_json_from_sample(
24+
TestConstants.EDXL_HEALTH_TO_HEALTH_ENVELOPE_PATH,
25+
"tests/fixtures/RC-SR/RC-SR_V3.0_exhaustive_fill.json",
26+
)
27+
output_data = ResourcesStatusConverter.from_cisu_to_rs(message)
28+
self.assertMatchSnapshot(json.dumps(output_data, indent=2))
29+
30+
def test_required_snapshot_rs_to_cisu(self):
31+
message = TestHelper.create_edxl_json_from_sample(
32+
TestConstants.EDXL_HEALTH_TO_HEALTH_ENVELOPE_PATH,
33+
"tests/fixtures/RS-SR/RS-SR_V3.0_required_fields.json",
34+
)
35+
output_data = ResourcesStatusConverter.from_rs_to_cisu(message)
36+
self.assertMatchSnapshot(json.dumps(output_data, indent=2))
37+
38+
def test_required_snapshot_cisu_to_rs(self):
39+
message = TestHelper.create_edxl_json_from_sample(
40+
TestConstants.EDXL_HEALTH_TO_HEALTH_ENVELOPE_PATH,
41+
"tests/fixtures/RC-SR/RC-SR_V3.0_required_fields.json",
42+
)
43+
output_data = ResourcesStatusConverter.from_cisu_to_rs(message)
44+
self.assertMatchSnapshot(json.dumps(output_data, indent=2))
45+
46+
def test_rs_to_cisu(self):
47+
TestHelper.conversion_tests_runner(
48+
sample_dir=TestConstants.RS_SR_TAG,
49+
envelope_file=TestConstants.EDXL_HEALTH_TO_FIRE_ENVELOPE_PATH,
50+
converter_method=ResourcesStatusConverter.from_rs_to_cisu,
51+
target_schema=RC_SR_SCHEMA,
52+
)
53+
54+
def test_cisu_to_rs(self):
55+
TestHelper.conversion_tests_runner(
56+
sample_dir=TestConstants.RC_SR_TAG,
57+
envelope_file=TestConstants.EDXL_HEALTH_TO_FIRE_ENVELOPE_PATH,
58+
converter_method=ResourcesStatusConverter.from_cisu_to_rs,
59+
target_schema=RS_SR_SCHEMA,
60+
)

converter/tests/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ class TestConstants:
3030
RS_RR_TAG = "RS-RR"
3131
RS_SR_TAG = "RS-SR"
3232
RS_URL_TAG = "RS-URL"
33+
RC_SR_TAG = "RC-SR"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"resourcesStatusCisu": {
3+
"caseId": "fr.health.samu440.DRFR154402413800236",
4+
"resourceId": "fr.health.samu440.resource.VLM2",
5+
"state": {
6+
"datetime": "2024-05-18T18:46:00+02:00",
7+
"status": "RETOUR",
8+
"availability": true
9+
}
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"resourcesStatusCisu": {
3+
"caseId": "fr.health.samu440.DRFR154402413800236",
4+
"resourceId": "fr.health.samu440.resource.VLM2",
5+
"state": {
6+
"datetime": "2024-05-18T18:46:00+02:00",
7+
"status": "ORIENTAT"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)