Skip to content

[IMP] Add image type enum and property in image_data #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions carepoint/models/cph/image_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
Numeric,
)

from ..enum_image_type import EnumImageType


class ImageData(Carepoint.BASE):
__tablename__ = 'cpimage_data'
Expand Down Expand Up @@ -55,5 +57,11 @@ class ImageData(Carepoint.BASE):
chg_date = Column(DateTime)
image_path = property(lambda s: s._compute_image_path())

@property
def image_type(self):
"""Return the canonical name for the image type."""
return EnumImageType(self.image_type_cn).name

def _compute_image_path(self):
"""Return the full network path for the image."""
return '%s/%s' % (self.RootFolderName, self.FullFileName)
22 changes: 22 additions & 0 deletions carepoint/models/enum_image_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2017-TODAY LasLabs Inc.
# License MIT (https://opensource.org/licenses/MIT).

import enum

from sqlalchemy import (Column,
Integer,
DateTime,
ForeignKey,
)
from sqlalchemy.types import Enum
from sqlalchemy.ext.declarative import declared_attr


class EnumImageType(enum.Enum):
"""Provide a PEP-0435 compliant Carepoint Image Type Enumerable."""

prescription = 2
unknown_3 = 3
unknown_7 = 7
unknown_1001 = 1001
8 changes: 8 additions & 0 deletions carepoint/tests/models/cph/test_image_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ def test_table_initialization(self):
self.assertIsInstance(ImageData.__table__, Table)

def test_compute_image_path(self):
"""It should return the full image path."""
image = ImageData(
RootFolderName='root',
FullFileName='file',
)
self.assertEqual(image.image_path, 'root/file')

def test_image_type(self):
"""It should return the canonical name for the type."""
image = ImageData(
image_type_cn=2,
)
self.assertEqual(image.image_type, 'prescription')


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