first commit
This commit is contained in:
34
mdrsclient/models/laboratory.py
Normal file
34
mdrsclient/models/laboratory.py
Normal file
@ -0,0 +1,34 @@
|
||||
from typing import Generator
|
||||
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Laboratory:
|
||||
id: int
|
||||
name: str
|
||||
pi_name: str
|
||||
full_name: str
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Laboratories:
|
||||
items: list[Laboratory]
|
||||
|
||||
def __iter__(self) -> Generator[Laboratory, None, None]:
|
||||
yield from self.items
|
||||
|
||||
def empty(self) -> bool:
|
||||
return len(self.items) == 0
|
||||
|
||||
def clear(self) -> None:
|
||||
self.items.clear()
|
||||
|
||||
def append(self, item: Laboratory) -> None:
|
||||
self.items.append(item)
|
||||
|
||||
def find_by_id(self, id: int) -> Laboratory | None:
|
||||
return next((x for x in self.items if x.id == id), None)
|
||||
|
||||
def find_by_name(self, name: str) -> Laboratory | None:
|
||||
return next((x for x in self.items if x.name == name), None)
|
Reference in New Issue
Block a user