Skip to content

Commit

Permalink
Upgrade SQLA; fixup enum imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-c committed Jul 31, 2024
1 parent 83aaae8 commit 3b6ca31
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 49 deletions.
7 changes: 3 additions & 4 deletions portal/models/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
to address via foreign keys.
"""
from sqlalchemy.dialects.postgresql import ENUM

from sqlalchemy import Enum
from ..database import db

address_type = ENUM('postal', 'physical', 'both', name='address_type',
address_type = Enum('postal', 'physical', 'both', name='address_type',
create_type=False)
address_use = ENUM('home', 'work', 'temp', 'old', name='address_use',
address_use = Enum('home', 'work', 'temp', 'old', name='address_use',
create_type=False)


Expand Down
4 changes: 2 additions & 2 deletions portal/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask import current_app, url_for
from flask_dance.consumer.backend.sqla import OAuthConsumerMixin
from sqlalchemy import UniqueConstraint
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum

from ..audit import auditable_event
from ..database import db
Expand All @@ -18,7 +18,7 @@
from .role import ROLE, Role
from .user import User, UserRelationship, UserRoles, current_user

providers_list = ENUM(
providers_list = Enum(
*SUPPORTED_OAUTH_PROVIDERS, name='providers', create_type=False)


Expand Down
5 changes: 2 additions & 3 deletions portal/models/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

from flask import current_app, url_for
from flask_babel import force_locale, gettext as _
from sqlalchemy import UniqueConstraint
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum, UniqueConstraint
from sqlalchemy.orm.exc import NoResultFound

from ..audit import auditable_event
Expand All @@ -26,7 +25,7 @@
from .user import User

# https://www.hl7.org/fhir/valueset-event-status.html
event_status_types = ENUM(
event_status_types = Enum(
'preparation', 'in-progress', 'suspended', 'aborted', 'completed',
'entered-in-error', 'unknown', name='event_statuses',
create_type=False)
Expand Down
5 changes: 2 additions & 3 deletions portal/models/communication_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from datetime import datetime

from flask import current_app
from sqlalchemy import UniqueConstraint
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum, UniqueConstraint

from ..database import db
from ..date_tools import RelativeDelta
Expand All @@ -15,7 +14,7 @@
from .reference import Reference

# https://www.hl7.org/fhir/valueset-request-status.html
request_status_types = ENUM(
request_status_types = Enum(
'draft', 'active', 'suspended', 'cancelled', 'completed',
'entered-in-error', 'unknown', name='request_statuses',
create_type=False)
Expand Down
6 changes: 3 additions & 3 deletions portal/models/encounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from datetime import datetime

from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum

from ..database import db
from ..date_tools import FHIR_datetime, as_fhir
Expand All @@ -26,12 +26,12 @@ class EncounterCodings(db.Model):


# http://www.hl7.org/FHIR/encounter-definitions.html#Encounter.status
status_types = ENUM(
status_types = Enum(
'planned', 'arrived', 'in-progress', 'onleave', 'finished', 'cancelled',
name='statuses', create_type=False)

# authentication method type extension to the standard FHIR format
auth_method_types = ENUM(
auth_method_types = Enum(
'password_authenticated', 'url_authenticated', 'staff_authenticated',
'staff_handed_to_patient', 'service_token_authenticated',
'url_authenticated_and_verified', 'failsafe',
Expand Down
5 changes: 2 additions & 3 deletions portal/models/identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
from builtins import str
import json

from sqlalchemy import UniqueConstraint
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum, UniqueConstraint
from werkzeug.exceptions import BadRequest, Conflict

from ..database import db
from ..system_uri import TRUENTH_EXTERNAL_STUDY_SYSTEM

identifier_use = ENUM('usual', 'official', 'temp', 'secondary',
identifier_use = Enum('usual', 'official', 'temp', 'secondary',
name='id_use', create_type=False)
UNIQUE_IDENTIFIER_SYSTEMS = {TRUENTH_EXTERNAL_STUDY_SYSTEM}

Expand Down
5 changes: 2 additions & 3 deletions portal/models/intervention.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Intervention Module"""
from flask import current_app
from sqlalchemy import and_
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum, and_
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm.exc import NoResultFound
from werkzeug.exceptions import BadRequest
Expand Down Expand Up @@ -260,7 +259,7 @@ def __str__(self):


access_types = ('forbidden', 'granted', 'subscribed')
access_types_enum = ENUM(*access_types, name='access', create_type=False)
access_types_enum = Enum(*access_types, name='access', create_type=False)


class UserIntervention(db.Model):
Expand Down
6 changes: 3 additions & 3 deletions portal/models/questionnaire.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Questionnaire module"""
from flask import url_for
from sqlalchemy import UniqueConstraint
from sqlalchemy.dialects.postgresql import ENUM, JSONB
from sqlalchemy import Enum, UniqueConstraint
from sqlalchemy.dialects.postgresql import JSONB

from ..database import db
from ..date_tools import FHIR_datetime
Expand All @@ -10,7 +10,7 @@
from .identifier import Identifier

status_types = ('draft', 'published', 'retired')
status_types_enum = ENUM(
status_types_enum = Enum(
*status_types, name='questionnaire_status_enum', create_type=False)


Expand Down
5 changes: 2 additions & 3 deletions portal/models/questionnaire_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from flask import url_for
from flask_babel import gettext as _
from flask_sqlalchemy_caching import FromCache
from sqlalchemy import CheckConstraint, UniqueConstraint
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import CheckConstraint, Enum, UniqueConstraint

from ..cache import FIVE_MINS, TWO_HOURS, cache
from ..database import db
Expand All @@ -23,7 +22,7 @@
from .user_consent import consent_withdrawal_dates

classification_types = ('baseline', 'recurring', 'indefinite', 'other')
classification_types_enum = ENUM(
classification_types_enum = Enum(
*classification_types, name='classification_enum', create_type=False)


Expand Down
6 changes: 3 additions & 3 deletions portal/models/questionnaire_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from flask import current_app, has_request_context, url_for
from flask_swagger import swagger
import jsonschema
from sqlalchemy import or_
from sqlalchemy.dialects.postgresql import ENUM, JSONB
from sqlalchemy import Enum, or_
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm.exc import MultipleResultsFound

from ..database import db
Expand Down Expand Up @@ -64,7 +64,7 @@ def default_status(context):

# Fields derived from document content
status = db.Column(
ENUM(
Enum(
'in-progress',
'completed',
name='questionnaire_response_statuses'
Expand Down
4 changes: 2 additions & 2 deletions portal/models/research_study.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum

from ..cache import TWO_HOURS, cache
from ..database import db
Expand All @@ -15,7 +15,7 @@
"closed-to-accrual-and-intervention", "completed", "disapproved",
"in-review", "temporarily-closed-to-accrual",
"temporarily-closed-to-accrual-and-intervention", "withdrawn")
status_types_enum = ENUM(
status_types_enum = Enum(
*status_types, name='research_study_status_enum', create_type=False)


Expand Down
5 changes: 2 additions & 3 deletions portal/models/table_preference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
from datetime import datetime
import json

from sqlalchemy import UniqueConstraint
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum, UniqueConstraint

from ..database import db
from ..date_tools import FHIR_datetime

sort_order_types = ('asc', 'desc')
sort_order_types_enum = ENUM(
sort_order_types_enum = Enum(
*sort_order_types, name='sort_order_enum', create_type=False)


Expand Down
6 changes: 3 additions & 3 deletions portal/models/telecom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"""
from flask import current_app
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum

from ..database import db

cp_sys_list = ['phone', 'fax', 'email', 'pager', 'url', 'sms', 'other']
cp_use_list = ['home', 'work', 'temp', 'old', 'mobile']

contactpoint_sys = ENUM(*cp_sys_list, name='cp_sys', create_type=False)
contactpoint_use = ENUM(*cp_use_list, name='cp_use', create_type=False)
contactpoint_sys = Enum(*cp_sys_list, name='cp_sys', create_type=False)
contactpoint_use = Enum(*cp_use_list, name='cp_use', create_type=False)


class ContactPoint(db.Model):
Expand Down
4 changes: 2 additions & 2 deletions portal/models/tou.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""ToU (Terms of Use) module"""
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum

from ..database import db
from ..date_tools import FHIR_datetime
from .notification import Notification, UserNotification
from .organization import Organization, OrgTree
from .role import ROLE, Role
from .user import User
tou_types = ENUM('website terms of use', 'subject website consent',
tou_types = Enum('website terms of use', 'subject website consent',
'stored website consent form', 'privacy policy',
'EMPRO website terms of use',
name='tou_types', create_type=False)
Expand Down
5 changes: 2 additions & 3 deletions portal/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
from flask_login import current_user as flask_login_current_user
from flask_user import UserMixin, _call_or_get
from fuzzywuzzy import fuzz
from sqlalchemy import UniqueConstraint, and_, func, or_
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import and_, func, Enum, or_, UniqueConstraint
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import ColumnProperty, class_mapper, synonym
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
Expand Down Expand Up @@ -66,7 +65,7 @@
DELETED_REGEX = r"__deleted_\d+__(.*)"

# https://www.hl7.org/fhir/valueset-administrative-gender.html
gender_types = ENUM('male', 'female', 'other', 'unknown', name='genders',
gender_types = Enum('male', 'female', 'other', 'unknown', name='genders',
create_type=False)

internal_identifier_systems = (
Expand Down
4 changes: 2 additions & 2 deletions portal/models/user_consent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""User Consent module"""
from datetime import datetime, timedelta

from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Enum
from sqlalchemy.ext.hybrid import hybrid_property
from validators import ValidationFailure, url as url_validation

Expand All @@ -22,7 +22,7 @@ def default_expires():
SEND_REMINDERS_MASK = 0b100

status_types = ('consented', 'suspended', 'deleted')
status_types_enum = ENUM(
status_types_enum = Enum(
*status_types, name='status_enum', create_type=False)


Expand Down
6 changes: 3 additions & 3 deletions portal/trigger_states/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from copy import deepcopy
from datetime import datetime, timedelta
from flask import current_app
from sqlalchemy import UniqueConstraint
from sqlalchemy.dialects.postgresql import ENUM, JSONB
from sqlalchemy import Enum, UniqueConstraint
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import make_transient

from ..database import db
Expand All @@ -12,7 +12,7 @@
opt_out_this_visit_key = '_opt_out_this_visit'


trigger_state_enum = ENUM(
trigger_state_enum = Enum(
'unstarted',
'due',
'inprocess',
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ requests-oauthlib==1.1.0 # pyup: <1.2.0 # pin until OAuthlib>=3.0.0 # via flask
requests==2.25.1 # via flask-recaptcha, requests-cache, requests-oauthlib, sphinx
six==1.14.0
# via bcrypt, packaging, python-dateutil, python-memcached, sphinx, swagger-spec-validator, tox, validators, webtest
sqlalchemy==1.3.23 # via alembic, flask-sqlalchemy
sqlalchemy==1.3.24 # via alembic, flask-sqlalchemy
swagger-spec-validator==2.7.3
typing-extensions==4.12.2
# via kombu
Expand Down

0 comments on commit 3b6ca31

Please sign in to comment.