hamyar_paygah.services.mission_details_service

Services to get mission details from server.

Attributes

Functions

_fetch_mission_details(server_address, mission_id, ...)

Fetch details of a mission from the EMS SOAP service.

_get_cache_file_path(mission_id, patient_id)

Generate a cache file path for a given mission and patient ID.

_save_xml_cache(mission_id, patient_id, xml_text)

Save XML response as compressed LZMA file.

_load_xml_cache(mission_id, patient_id)

Load compressed XML response from cache.

get_mission_details(server_address, mission_id, patient_id)

Get mission details with caching mechanism.

Module Contents

hamyar_paygah.services.mission_details_service.CACHE_DIR
async hamyar_paygah.services.mission_details_service._fetch_mission_details(server_address, mission_id, patient_id)

Fetch details of a mission from the EMS SOAP service.

This function send an asynchronous SOAP request to the EMS reporting service and retrieves the raw XML response containing mission details for the given mission ID and patient ID.

The request uses a legacy SOAP endpoint with strict field names.

Parameters:
  • server_address (str) – Base address of the EMS server (without trailing slash).

  • mission_id (int) – ID of the mission.

  • patient_id (int) – ID of the patient.

Returns:

The raw SOAP response body as a string. The returned value is unparsed XML and must be processed by the caller if structured data is required.

Return type:

str

hamyar_paygah.services.mission_details_service._get_cache_file_path(mission_id, patient_id)

Generate a cache file path for a given mission and patient ID.

This function constructs a unique file path within the CACHE_DIR directory based on the provided mission ID and patient ID. The resulting file name follows the format mission_{mission_id}_patient_{patient_id}.xml.xz, ensuring that cached data for different missions and patients are stored separately.

Parameters:
  • mission_id (int) – The ID of the mission.

  • patient_id (int) – The ID of the patient.

Returns:

The path to the cache file.

Return type:

anyio.Path

hamyar_paygah.services.mission_details_service._save_xml_cache(mission_id, patient_id, xml_text)

Save XML response as compressed LZMA file.

Parameters:
  • mission_id (int)

  • patient_id (int)

  • xml_text (str)

Return type:

None

hamyar_paygah.services.mission_details_service._load_xml_cache(mission_id, patient_id)

Load compressed XML response from cache.

Parameters:
  • mission_id (int)

  • patient_id (int)

Return type:

str

async hamyar_paygah.services.mission_details_service.get_mission_details(server_address, mission_id, patient_id)

Get mission details with caching mechanism.

This function first checks if the mission details for the given mission ID and patient ID are available in the cache. If a cached file exists, it reads the data from the cache and parses it into a MissionDetails object. If no cache is found, it fetches the details from the server, parses it, and saves the raw response to the cache for future use if mission is older than 2 days.

Parameters:
  • server_address (str) – The base address of the EMS server.

  • mission_id (int) – The ID of the mission.

  • patient_id (int) – The ID of the patient.

Returns:

An object containing the details of the mission.

Return type:

MissionDetails