-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
68 lines (51 loc) · 2.23 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (c) University College London Hospitals NHS Foundation Trust
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Interaction with PIXL database"""
from __future__ import annotations
from typing import Optional
from sqlalchemy import MetaData
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
from sqlalchemy.schema import ForeignKey
from sqlalchemy.types import Date, DateTime
class Base(DeclarativeBase):
"""sqlalchemy base class"""
metadata = MetaData(schema="pipeline")
class Extract(Base):
"""extract table"""
__tablename__ = "extract"
extract_id: Mapped[int] = mapped_column(primary_key=True)
slug: Mapped[str]
def __repr__(self) -> str:
"""Nice representation for printing."""
return f"<{self.__class__.__name__} {self.extract_id=} {self.slug=}>".replace(" self.", " ")
class Image(Base):
"""image table"""
__tablename__ = "image"
image_id: Mapped[int] = mapped_column(primary_key=True)
accession_number: Mapped[str]
study_date: Mapped[Date] = mapped_column(Date())
mrn: Mapped[str]
study_uid: Mapped[Optional[str]]
pseudo_study_uid: Mapped[Optional[str]]
exported_at: Mapped[DateTime] = mapped_column(DateTime(timezone=True), nullable=True)
extract: Mapped[Extract] = relationship()
extract_id: Mapped[int] = mapped_column(ForeignKey("extract.extract_id"))
pseudo_patient_id: Mapped[Optional[str]]
def __repr__(self) -> str:
"""Nice representation for printing."""
return (
f"<{self.__class__.__name__} "
f"{self.image_id=} {self.accession_number=} {self.mrn=} {self.study_uid=}"
f"{self.pseudo_study_uid} {self.extract_id}>"
).replace(" self.", " ")