Add Dispatch_V0.1.1
This commit is contained in:
54
Dispatch_V0.1.1/domain/location_catalog.py
Normal file
54
Dispatch_V0.1.1/domain/location_catalog.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# hub/ticket/domain/location_catalog.py
|
||||
|
||||
"""Справочник соответствия button_id и локации Ticket."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
|
||||
DEFAULT_BUTTON_LOCATIONS = {
|
||||
1: "ГБУЗ ФМБА ГП№1 (томограф Siemens, каб. 101)",
|
||||
2: "ГБУЗ ФМБА ГП№2 (ангиограф Амико, каб. 205)",
|
||||
3: "ГБУЗ ФМБА ГП№3 (рентген Philips, каб. 112)",
|
||||
4: "ГБУЗ ФМБА ГП№4 (рентген Shimadzu, каб. 305)",
|
||||
5: "ГБУЗ ФМБА ГП№5 (рентген Toshiba, каб. 208)",
|
||||
6: "ГБУЗ ФМБА ГП№6 (рентген GE, каб. 410)",
|
||||
7: "ГБУЗ ФМБА ГП№7 (рентген Canon, каб. 312)",
|
||||
8: "ГБУЗ ФМБА ГП№8 (рентген Hitachi, каб. 415)",
|
||||
}
|
||||
|
||||
|
||||
class LocationCatalog:
|
||||
"""Канонический справочник локаций Ticket."""
|
||||
|
||||
def __init__(self, locations: Mapping[int, str] | None = None):
|
||||
self._locations = dict(DEFAULT_BUTTON_LOCATIONS)
|
||||
if locations:
|
||||
self._locations.update({int(key): value for key, value in locations.items()})
|
||||
|
||||
def get_location(self, button_id: int) -> str:
|
||||
"""Вернуть локацию по button_id или fallback-описание."""
|
||||
return self._locations.get(button_id, f"Неизвестная локация #{button_id}")
|
||||
|
||||
|
||||
def parse_location_parts(location: str) -> tuple[str, str, str]:
|
||||
"""Разобрать строку локации на учреждение, кабинет и оборудование."""
|
||||
normalized_location = str(location or "").strip()
|
||||
if not normalized_location:
|
||||
return "", "", ""
|
||||
if "(" not in normalized_location or ")" not in normalized_location:
|
||||
return normalized_location, "", ""
|
||||
|
||||
institution = normalized_location.split("(", 1)[0].strip()
|
||||
inside_brackets = normalized_location.split("(", 1)[1].split(")", 1)[0].strip()
|
||||
if not inside_brackets:
|
||||
return institution, "", ""
|
||||
if "каб." not in inside_brackets:
|
||||
return institution, "", inside_brackets
|
||||
|
||||
device_part, room_part = inside_brackets.split("каб.", 1)
|
||||
room = f"каб. {room_part.strip().rstrip(',')}"
|
||||
device = device_part.strip().rstrip(",")
|
||||
return institution, room, device
|
||||
Reference in New Issue
Block a user