felicity-lims/felicity/apps/instrument/services.py

118 lines
2.9 KiB
Python
Raw Normal View History

2024-07-21 21:44:22 +08:00
from felicity.apps.abstract.service import BaseService
from felicity.apps.idsequencer.service import IdSequenceService
2024-09-22 23:15:27 +08:00
from felicity.apps.instrument.entities import (
CalibrationCertificate,
Instrument,
InstrumentCalibration,
InstrumentCompetence,
InstrumentType,
LaboratoryInstrument,
Method,
)
2024-07-28 03:52:31 +08:00
from felicity.apps.instrument.repository import (
2024-09-22 23:15:27 +08:00
CalibrationCertificateRepository,
InstrumentCalibrationRepository,
InstrumentCompetenceRepository,
InstrumentRepository,
InstrumentTypeRepository,
LaboratoryInstrumentRepository,
MethodRepository,
)
from felicity.apps.instrument.schemas import (
CalibrationCertificateCreate,
CalibrationCertificateUpdate,
InstrumentCalibrationCreate,
InstrumentCalibrationUpdate,
InstrumentCompetenceCreate,
InstrumentCompetenceUpdate,
InstrumentCreate,
InstrumentTypeCreate,
InstrumentTypeUpdate,
InstrumentUpdate,
LaboratoryInstrumentCreate,
LaboratoryInstrumentUpdate,
MethodCreate,
MethodUpdate,
)
2024-07-21 15:06:51 +08:00
2024-07-21 21:44:22 +08:00
class MethodService(
BaseService[Method, MethodCreate, MethodUpdate],
2024-07-21 15:06:51 +08:00
):
2024-07-28 03:52:31 +08:00
def __init__(
self,
):
2024-09-25 00:12:10 +08:00
super().__init__(MethodRepository())
2024-07-21 15:06:51 +08:00
2024-07-28 03:52:31 +08:00
2024-07-21 21:44:22 +08:00
class InstrumentTypeService(
BaseService[InstrumentType, InstrumentTypeCreate, InstrumentTypeUpdate],
):
2024-07-28 03:52:31 +08:00
def __init__(
self,
):
2024-09-25 00:12:10 +08:00
super().__init__(InstrumentTypeRepository())
2024-07-21 15:06:51 +08:00
2024-07-28 03:52:31 +08:00
2024-07-21 21:44:22 +08:00
class InstrumentService(
BaseService[Instrument, InstrumentCreate, InstrumentUpdate],
):
2024-07-28 03:52:31 +08:00
def __init__(
self,
):
2024-09-25 00:12:10 +08:00
super().__init__(InstrumentRepository())
2024-07-21 15:06:51 +08:00
2024-07-28 03:52:31 +08:00
2024-07-21 21:44:22 +08:00
class LaboratoryInstrumentService(
2024-07-28 03:52:31 +08:00
BaseService[
LaboratoryInstrument, LaboratoryInstrumentCreate, LaboratoryInstrumentUpdate
],
2024-07-21 21:44:22 +08:00
):
2024-07-28 03:52:31 +08:00
def __init__(
self,
):
2024-09-25 00:12:10 +08:00
super().__init__(LaboratoryInstrumentRepository())
2024-07-21 15:06:51 +08:00
class InstrumentCalibrationService(
2024-07-28 03:52:31 +08:00
BaseService[
InstrumentCalibration, InstrumentCalibrationCreate, InstrumentCalibrationUpdate
],
2024-07-21 15:06:51 +08:00
):
2024-07-28 03:52:31 +08:00
def __init__(
self,
2024-09-22 23:15:27 +08:00
):
2024-07-28 03:52:31 +08:00
self.id_service = IdSequenceService()
2024-09-25 00:12:10 +08:00
super().__init__(InstrumentCalibrationRepository())
2024-07-21 15:06:51 +08:00
2024-07-21 21:44:22 +08:00
async def create(
2024-07-28 03:52:31 +08:00
self, obj_in: dict | InstrumentCalibrationCreate
2024-07-21 21:44:22 +08:00
) -> InstrumentCalibration:
2024-07-28 03:52:31 +08:00
data = self._import(obj_in)
data["calibration_id"] = (await self.id_service.get_next_number("ICAL"))[1]
2024-07-24 17:04:53 +08:00
return await super().create(data)
2024-07-21 15:06:51 +08:00
2024-07-21 21:44:22 +08:00
class CalibrationCertificateService(
2024-07-28 03:52:31 +08:00
BaseService[
CalibrationCertificate,
CalibrationCertificateCreate,
CalibrationCertificateUpdate,
],
2024-07-21 21:44:22 +08:00
):
2024-07-28 03:52:31 +08:00
def __init__(
self,
):
2024-09-25 00:12:10 +08:00
super().__init__(CalibrationCertificateRepository())
2024-07-21 15:06:51 +08:00
2024-07-21 21:44:22 +08:00
class InstrumentCompetenceService(
2024-07-28 03:52:31 +08:00
BaseService[
InstrumentCompetence, InstrumentCompetenceCreate, InstrumentCompetenceUpdate
],
2024-07-21 21:44:22 +08:00
):
2024-07-28 03:52:31 +08:00
def __init__(
self,
):
2024-09-25 00:12:10 +08:00
super().__init__(InstrumentCompetenceRepository())