Skip to content

Commit

Permalink
Merge pull request #1643 from ChildMindInstitute/release/1.8.1
Browse files Browse the repository at this point in the history
Release/1.8.1
  • Loading branch information
mbanting authored Nov 6, 2024
2 parents 0e8956f + b5462bb commit a348544
Show file tree
Hide file tree
Showing 11 changed files with 386 additions and 134 deletions.
25 changes: 21 additions & 4 deletions .github/workflows/run_build_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ on:
# branches:
# - develop
workflow_dispatch: {}
# pull_request:
# types:
# - closed


concurrency:
cancel-in-progress: true
Expand All @@ -26,9 +24,12 @@ env:
BUILD_NAME: ${{github.event_name}}
BUILD_NUMBER: ${{github.run_id}}
ECR_ADDRESS: 917902836630.dkr.ecr.us-east-1.amazonaws.com
DR_ECR_ADDRESS: 973422231492.dkr.ecr.us-west-2.amazonaws.com
OUT_DIR: ./out
AWS_REGION : "us-east-1"
DR_AWS_REGION : "us-west-2"
ECR_REPO: 917902836630.dkr.ecr.us-east-1.amazonaws.com/api-server
DR_ECR_REPO: 973422231492.dkr.ecr.us-west-2.amazonaws.com/api-server


jobs:
Expand All @@ -37,6 +38,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
IMAGE_NAME: ${{ steps.sha.outputs.IMAGE_NAME }}
IMAGE_SHA: ${{ steps.sha.outputs.SHORT_SHA }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -77,6 +79,17 @@ jobs:
run: |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ env.ECR_ADDRESS }}
- name: configure aws DR credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::973422231492:role/cmiml-dr-oidc-github-role
role-session-name: gha-oidc-runner
aws-region: ${{ env.DR_AWS_REGION }}

- name: Login to DR ECR
run: |
aws ecr get-login-password --region ${{ env.DR_AWS_REGION }} | docker login --username AWS --password-stdin ${{ env.DR_ECR_ADDRESS }}
- name: Generate short sha
id: sha
run: |
Expand All @@ -94,7 +107,11 @@ jobs:
PIPENV_EXTRA_ARGS=--dev
cache-to: mode=max,image-manifest=true,oci-mediatypes=true,type=registry,ref=${{ env.ECR_REPO }}:cache
cache-from: type=registry,ref=${{ env.ECR_REPO }}:cache
tags: ${{ steps.sha.outputs.IMAGE_NAME }},${{ env.ECR_REPO }}:latest
tags: |
${{ env.ECR_REPO }}:latest
${{ env.ECR_REPO }}:${{ steps.sha.outputs.SHORT_SHA }}
${{ env.DR_ECR_REPO }}:latest
${{ env.DR_ECR_REPO }}:${{ steps.sha.outputs.SHORT_SHA }}
platforms: linux/amd64,linux/arm64

- name: Upload artifacts
Expand Down
50 changes: 1 addition & 49 deletions .github/workflows/run_deploy_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,7 @@ env:
IMAGE_NAME: ${{ inputs.IMAGE_NAME }}

jobs:
# run_migration:
# environment: dev
# name: Run Database Migrations
# runs-on: ubuntu-latest
# env:
# TASK_DEFINITION: migration
# ECS_SERVICE_NAME: migration
#
# steps:
# - name: echo IMAGE_NAME
# run: |
# echo $IMAGE_NAME
#
# - name: configure aws credentials
# uses: aws-actions/configure-aws-credentials@v3
# with:
# role-to-assume: arn:aws:iam::017925157769:role/cmiml-dev-oidc-github-role
# role-session-name: OIDC-GHA-session
# aws-region: ${{ env.AWS_REGION }}
#
# - name: Download task definition
# run: |
# aws ecs describe-task-definition --task-definition ${{ env.TASK_DEFINITION }} --query taskDefinition > task-definition.json
#
# - name: Render Amazon ECS task definition
# id: task-def
# uses: aws-actions/amazon-ecs-render-task-definition@v1
# with:
# task-definition: task-definition.json
# container-name: mind_logger
# image: ${{ inputs.IMAGE_NAME }}
#
# - name: Update Task Definition
# uses: aws-actions/amazon-ecs-deploy-task-definition@v1
# with:
# task-definition: ${{ steps.task-def.outputs.task-definition }}
#
# - name: Run migration container
# id: run-task
# uses: geekcell/github-action-aws-ecs-run-task@v4
# with:
# cluster: ${{ env.ECS_CLUSTER_NAME }}
# task-definition: ${{ env.TASK_DEFINITION }}
# subnet-ids: subnet-02b7cfd48947b31ef
# security-group-ids: sg-0976f7b2b2b5bf411
# override-container-command: |
# /bin/sh
# -c
# /fastapi-migrate all


deploy_to_ecs:
runs-on: ubuntu-latest
Expand Down
31 changes: 29 additions & 2 deletions src/apps/activities/domain/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pydantic import Field, root_validator, validator

from apps.activities.errors import IncorrectMaxTimeRange, IncorrectMinTimeRange, IncorrectTimeRange
from apps.shared.domain import PublicModel, PublicModelNoExtra


Expand Down Expand Up @@ -152,7 +153,7 @@ def dict(self, *args, **kwargs):


class TimePayload(PublicModel):
type: str | None = None
type: TimePayloadType | None = None
value: datetime.time

def dict(self, *args, **kwargs):
Expand All @@ -163,14 +164,40 @@ def dict(self, *args, **kwargs):

class SingleTimePayload(PublicModel):
time: Optional[datetime.time] = None
max_value: Optional[datetime.time] = None
min_value: Optional[datetime.time] = None

@root_validator(pre=True)
def validate_time(cls, values: Dict[str, Any]) -> Dict[str, Any]:
time_value = values.get("time")
max_time_value = values.get("max_value")
min_time_value = values.get("min_value")

if isinstance(time_value, dict):
values["time"] = cls._dict_to_time(time_value)
elif isinstance(time_value, str):
values["time"] = cls._string_to_time(time_value)
if max_time_value and min_time_value:
if isinstance(max_time_value, dict):
max_time_value = cls._dict_to_time(max_time_value)
elif isinstance(max_time_value, str):
max_time_value = cls._string_to_time(max_time_value)

if isinstance(min_time_value, dict):
min_time_value = cls._dict_to_time(min_time_value)
elif isinstance(min_time_value, str):
min_time_value = cls._string_to_time(min_time_value)

if max_time_value < min_time_value:
raise IncorrectTimeRange()

if min_time_value is not None:
if max_time_value is None:
raise IncorrectMaxTimeRange()
if max_time_value is not None:
if min_time_value is None:
raise IncorrectMinTimeRange()

return values

def dict(self, *args, **kwargs) -> Dict[str, Any]:
Expand Down Expand Up @@ -554,7 +581,7 @@ class EqualToDateCondition(_EqualToDateCondition):


class EqualCondition(_EqualCondition):
payload: ValuePayload | ValueIndexPayload | TimePayload
payload: ValuePayload | ValueIndexPayload | TimePayload | SingleTimePayload


class NotEqualToDateCondition(_NotEqualToDateCondition):
Expand Down
56 changes: 41 additions & 15 deletions src/apps/activities/domain/custom_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from apps.activities.domain.response_type_config import PerformanceTaskType, ResponseType
from apps.activities.domain.response_values import PhrasalTemplateFieldType
from apps.activities.domain.scores_reports import ReportType, SubscaleItemType
from apps.activities.domain.scores_reports import ReportType, Score, SubscaleItemType, SubscaleSetting
from apps.activities.errors import (
IncorrectConditionItemError,
IncorrectConditionItemIndexError,
Expand All @@ -19,9 +19,14 @@
IncorrectSectionPrintItemTypeError,
IncorrectSubscaleInsideSubscaleError,
IncorrectSubscaleItemError,
SubscaleDoesNotExist,
SubscaleInsideSubscaleError,
SubscaleItemDoesNotExist,
SubscaleItemScoreError,
SubscaleItemTypeError,
SubscaleItemTypeItemDoesNotExist,
SubscaleNameDoesNotExist,
SubscaleSettingDoesNotExist,
)


Expand Down Expand Up @@ -68,6 +73,23 @@ def validate_item_flow(values: dict):
return values


def validate_subscale_setting_match_reports(report: Score, subscale_setting: SubscaleSetting):
report_subscale_linked = report.subscale_name
subscales = subscale_setting.subscales
if not subscales:
raise SubscaleDoesNotExist()

linked_subscale = next((subscale for subscale in subscales if subscale.name == report_subscale_linked), None)
if not linked_subscale:
raise SubscaleNameDoesNotExist()
elif not linked_subscale.items:
raise SubscaleItemDoesNotExist()
else:
has_non_subscale_items = any(item.type == SubscaleItemType.ITEM for item in linked_subscale.items)
if not has_non_subscale_items:
raise SubscaleItemTypeItemDoesNotExist()


def validate_score_and_sections(values: dict): # noqa: C901
items = values.get("items", [])
item_names = [item.name for item in items]
Expand All @@ -83,6 +105,13 @@ def validate_score_and_sections(values: dict): # noqa: C901

for report in list(scores):
score_item_ids.append(report.id)
if report.scoring_type == "score":
subscale_setting = values.get("subscale_setting")
if not subscale_setting: # report of type score exist then we need a subscale setting
raise SubscaleSettingDoesNotExist()
else:
validate_subscale_setting_match_reports(report, subscale_setting)

# check if all item names are same as values.name
for item in report.items_score:
if item not in item_names:
Expand All @@ -98,17 +127,20 @@ def validate_score_and_sections(values: dict): # noqa: C901
if not items[score_item_index].config.add_scores:
raise IncorrectScoreItemConfigError()

print_item_types = [
ResponseType.SINGLESELECT,
ResponseType.MULTISELECT,
ResponseType.SLIDER,
ResponseType.TEXT,
ResponseType.PARAGRAPHTEXT,
ResponseType.NUMBERSELECT,
]

for item in report.items_print:
if item not in item_names:
raise IncorrectScorePrintItemError()
else:
if items[item_names.index(item)].response_type not in [
ResponseType.SINGLESELECT,
ResponseType.MULTISELECT,
ResponseType.SLIDER,
ResponseType.TEXT,
ResponseType.PARAGRAPHTEXT,
]:
if items[item_names.index(item)].response_type not in print_item_types:
raise IncorrectScorePrintItemTypeError()

if report.conditional_logic:
Expand All @@ -118,13 +150,7 @@ def validate_score_and_sections(values: dict): # noqa: C901
if item not in item_names:
raise IncorrectScorePrintItemError()
else:
if items[item_names.index(item)].response_type not in [
ResponseType.SINGLESELECT,
ResponseType.MULTISELECT,
ResponseType.SLIDER,
ResponseType.TEXT,
ResponseType.PARAGRAPHTEXT,
]:
if items[item_names.index(item)].response_type not in print_item_types:
raise IncorrectScorePrintItemTypeError()

for report in list(sections):
Expand Down
7 changes: 7 additions & 0 deletions src/apps/activities/domain/scores_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class CalculationType(enum.StrEnum):
PERCENTAGE = "percentage"


class ScoringType(enum.StrEnum):
SCORE = "score"
RAW_SCORE = "raw_score"


class ScoreConditionalLogic(PublicModel):
name: str
id: str
Expand Down Expand Up @@ -59,6 +64,8 @@ class Score(PublicModel):
message: str | None = None
items_print: list[str] | None = Field(default_factory=list)
conditional_logic: list[ScoreConditionalLogic] | None = None
scoring_type: ScoringType | None = None
subscale_name: str | None = None

@validator("conditional_logic")
def validate_conditional_logic(cls, value, values):
Expand Down
43 changes: 43 additions & 0 deletions src/apps/activities/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ class IncorrectTimeRange(ValidationError):
message = _("Incorrect timerange")


class IncorrectMinTimeRange(ValidationError):
message = _("Mix timerange was not passed")


class IncorrectMaxTimeRange(ValidationError):
message = _("Max timerange was not passed")


class FlowDoesNotExist(NotFoundError):
message = _("Flow does not exist.")

Expand All @@ -274,3 +282,38 @@ class IncorrectPhrasalTemplateItemTypeError(ValidationError):

class IncorrectPhrasalTemplateItemIndexError(ValidationError):
message = _("Invalid item index for activity item inside phrasal template")


class SubscaleIsNotLinked(ValidationError):
message = _("The scoring_type is score but no suscale_name string pased")
code = _("no_subscale_items_exist")


class SubscaleDoesNotExist(ValidationError):
message = _("The scoring_type is score but there are no subscales")
code = _("no_subscale_linked")


class SubscaleNameDoesNotExist(ValidationError):
message = _("The lookup table with the passed name does not exist in subscale settings")
code = _("no_subscale_name_exist")


class SubscaleDataDoesNotExist(ValidationError):
message = _("The scoring_type is score but the subscale data does not exist")
code = _("no_subscaledata_exist")


class SubscaleSettingDoesNotExist(ValidationError):
message = _("The scoring_type is score but there are no subscale settings associated with activity")
code = _("no_subscale_setting_exist")


class SubscaleItemDoesNotExist(ValidationError):
message = _("The linked subscale should contain at least one item")
code = _("no_items_exist")


class SubscaleItemTypeItemDoesNotExist(ValidationError):
message = _("The linked subscale should contain at least one non-subscale type item")
code = _("no_subscale_type_items_exist")
Loading

0 comments on commit a348544

Please sign in to comment.