-
Notifications
You must be signed in to change notification settings - Fork 0
feat(converter): conversion RC-RI/RS-RI #326
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
Changes from all commits
21dac11
3c742fe
e363642
6a8861f
811c7f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class ResourcesInfoCISUConstants: | ||
| RESOURCE_PATH = "$.resource" | ||
| STATE_PATH = "$.state" | ||
| VEHICLE_TYPE_PATH = "$.vehicleType" | ||
|
|
||
| PATIENT_ID_KEY = "patientId" | ||
|
|
||
| VEHICLE_TYPE_SIS = "SIS" | ||
| DEFAULT_CISU_STATE_VEHICLE_TYPE = "SMUR" | ||
|
|
||
| DEFAULT_CISU_STATE_STATUS = "DECISION" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| import datetime | ||
|
|
||
| from converter.cisu.base_cisu_converter import BaseCISUConverter | ||
| from typing import Any, Dict | ||
|
|
||
| from converter.cisu.resources_info.resources_info_cisu_constants import ( | ||
| ResourcesInfoCISUConstants, | ||
| ) | ||
| from converter.utils import get_field_value, set_value, delete_paths | ||
|
|
||
|
|
||
| class ResourcesInfoCISUConverter(BaseCISUConverter): | ||
|
|
@@ -9,3 +17,63 @@ def get_rs_message_type(cls) -> str: | |
| @classmethod | ||
| def get_cisu_message_type(cls) -> str: | ||
| return "resourcesInfoCisu" | ||
|
|
||
| @classmethod | ||
| def from_cisu_to_rs(cls, edxl_json: Dict[str, Any]) -> Dict[str, Any]: | ||
| output_json = cls.copy_cisu_input_content(edxl_json) | ||
| output_use_case_json = cls.copy_cisu_input_use_case_content(edxl_json) | ||
| resources = get_field_value( | ||
| output_use_case_json, ResourcesInfoCISUConstants.RESOURCE_PATH | ||
| ) | ||
|
|
||
| for resource in resources: | ||
| state = get_field_value(resource, ResourcesInfoCISUConstants.STATE_PATH) | ||
| set_value(resource, ResourcesInfoCISUConstants.STATE_PATH, [state]) | ||
|
|
||
| return cls.format_rs_output_json(output_json, output_use_case_json) | ||
|
Comment on lines
+25
to
+33
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment gère-t-on la différence de cardinalité entre cisu (0..n) et health (1..n) ? si le RC-RI ne contient aucune ressource ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bonne question, pour l'instant on laissera le dispatcher échouer à la validation en attendant de voir s'il s'agit d'une coquille dans le modèle de nexsis (il semble peu pertinent d'envoyer un RC-RI sans ressource, le message étant alors presque vide) |
||
|
|
||
| @classmethod | ||
| def from_rs_to_cisu(cls, edxl_json: Dict[str, Any]) -> Dict[str, Any]: | ||
| output_json = cls.copy_rs_input_content(edxl_json) | ||
| output_use_case_json = cls.copy_rs_input_use_case_content(edxl_json) | ||
|
|
||
| resources = get_field_value( | ||
| output_use_case_json, ResourcesInfoCISUConstants.RESOURCE_PATH | ||
| ) | ||
| for resource in resources: | ||
| rs_vehicle_type = get_field_value( | ||
| resource, ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH | ||
| ) | ||
| cisu_vehicle_type = cls.translate_to_cisu_vehicle_type(rs_vehicle_type) | ||
| set_value( | ||
| resource, | ||
| ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH, | ||
| cisu_vehicle_type, | ||
| ) | ||
|
|
||
| cls.keep_last_state(resource) | ||
|
|
||
| delete_paths(resource, [ResourcesInfoCISUConstants.PATIENT_ID_KEY]) | ||
|
|
||
| return cls.format_cisu_output_json(output_json, output_use_case_json) | ||
|
|
||
| @classmethod | ||
| def translate_to_cisu_vehicle_type(cls, rs_vehicle_type: str) -> str: | ||
| if rs_vehicle_type.startswith(ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS): | ||
| return ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS | ||
| return ResourcesInfoCISUConstants.DEFAULT_CISU_STATE_VEHICLE_TYPE | ||
|
|
||
| @classmethod | ||
| def keep_last_state(cls, resource: Dict[str, Any]) -> None: | ||
| states = get_field_value(resource, ResourcesInfoCISUConstants.STATE_PATH) | ||
| if states and len(states) > 0: | ||
| latest_state = sorted(states, key=lambda x: x.get("datetime", ""))[-1] | ||
| else: | ||
| latest_state = { | ||
| "datetime": datetime.datetime.now(datetime.timezone.utc).isoformat( | ||
| timespec="seconds" | ||
| ), | ||
| "status": ResourcesInfoCISUConstants.DEFAULT_CISU_STATE_STATUS, | ||
| } | ||
|
|
||
| set_value(resource, ResourcesInfoCISUConstants.STATE_PATH, latest_state) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok pour le moment, en espérant obtenir une troisième valeur dans l'enum