Skip to content

Commit 9f440a2

Browse files
committed
[IMP] Add image type enum and property in image_data
* Add an enum for the image types. Currently mapped are the distinct values from an existing prod, with the one known value filled (prescription). Pending response from CP on others * Add `image_type` computed property in `image_data` that maps the type code using the enum
1 parent 49ac2d7 commit 9f440a2

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

carepoint/models/cph/image_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
Numeric,
1212
)
1313

14+
from ..enum_image_type import EnumImageType
15+
1416

1517
class ImageData(Carepoint.BASE):
1618
__tablename__ = 'cpimage_data'
@@ -55,5 +57,11 @@ class ImageData(Carepoint.BASE):
5557
chg_date = Column(DateTime)
5658
image_path = property(lambda s: s._compute_image_path())
5759

60+
@property
61+
def image_type(self):
62+
"""Return the canonical name for the image type."""
63+
return EnumImageType(self.image_type_cn).name
64+
5865
def _compute_image_path(self):
66+
"""Return the full network path for the image."""
5967
return '%s/%s' % (self.RootFolderName, self.FullFileName)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2017-TODAY LasLabs Inc.
3+
# License MIT (https://opensource.org/licenses/MIT).
4+
5+
import enum
6+
7+
from sqlalchemy import (Column,
8+
Integer,
9+
DateTime,
10+
ForeignKey,
11+
)
12+
from sqlalchemy.types import Enum
13+
from sqlalchemy.ext.declarative import declared_attr
14+
15+
16+
class EnumImageType(enum.Enum):
17+
"""Provide a PEP-0435 compliant Carepoint Image Type Enumerable."""
18+
19+
prescription = 2
20+
unknown_3 = 3
21+
unknown_7 = 7
22+
unknown_1001 = 1001

carepoint/tests/models/cph/test_image_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ def test_table_initialization(self):
1414
self.assertIsInstance(ImageData.__table__, Table)
1515

1616
def test_compute_image_path(self):
17+
"""It should return the full image path."""
1718
image = ImageData(
1819
RootFolderName='root',
1920
FullFileName='file',
2021
)
2122
self.assertEqual(image.image_path, 'root/file')
2223

24+
def test_image_type(self):
25+
"""It should return the canonical name for the type."""
26+
image = ImageData(
27+
image_type_cn=2,
28+
)
29+
self.assertEqual(image.image_type, 'prescription')
30+
2331

2432
if __name__ == '__main__':
2533
unittest.main()

0 commit comments

Comments
 (0)