For a project, I'm using 3 columns to define teeth positions in a database. For these positions, I want to generate numbers according to this link.
Currently, I'm using a Teeth
and Section
enum, which has the numbers according to the link. The Section
defines which range, and the Teeth
defines the number.
class Section(Enum):
"""
A enum of possible teeth sections
UR = UPPER RIGHT
UL = UPPER LEFT
LR = LOWER RIGHT
LL = LOWER LEFT
"""
UL = 10
UR = 20
BL = 30
BR = 40
class Teeth(Enum):
"""
A clean enumeration of possible teeth variations
"""
CENTRAL_INCISOR = 1
LATERAL_INCISOR = 2
CANINE = 3
PREMOLAR_1ST = 4
PREMOLAR_2ND = 5
MOLAR_1ST = 6
MOLAR_2ND = 7
WISDOM = 8
The 3 columns teeth
(from the Teeth enum), upper
(bool) and left
(bool). I currently have a simple if-statemenent.
def resolve_value(self):
section: Section
if self.upper:
section = Section.UL if self.left else Section.UR
else:
section = Section.BL if self.left else Section.BR
return section.value + self.teeth.value
Is there any way you guys would improve this? Keep in mind that it also goes the way around, teeth positions can be created with for example an input 48
which resolves to the bottom right wisdom's teeth.
The model class looks like this; where resolve_value
is a method of:
class TeethPosition(Model):
id = Column(Integer, primary_key=True)
teeth = Column(Enum(Teeth), nullable=False)
upper = Column(Boolean, nullable=False)
left = Column(Boolean, nullable=False)
def __init__(self, teeth: Teeth, upper: bool, left: bool) -> None:
super().__init__(teeth=teeth, upper=upper, left=left)