Skip to content

Commit

Permalink
Merge pull request #494 from vselvarajijay/go-live-version
Browse files Browse the repository at this point in the history
Go live version
  • Loading branch information
vselvarajijay committed Apr 14, 2024
2 parents e270c9f + 1d116ea commit fc55672
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/server/akello/db/models_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import datetime
import json
from decimal import Decimal

from botocore.exceptions import ClientError
from pydantic import BaseModel
Expand Down Expand Up @@ -135,6 +137,7 @@ def __add_attribute(self, attribute_name: str, attribute_value: any):
ExpressionAttributeValues = {
':value': attribute_value
}

response = registry_db.update_item(
Key={
'partition_key': self.partition_key,
Expand Down
44 changes: 36 additions & 8 deletions packages/server/akello/db/models_v2/registry_treatment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json
from decimal import Decimal
from typing import Optional, List
import uuid

Expand All @@ -10,7 +11,7 @@

class RegistryTreatment(AkelloBaseModel):
registry_id: str
user_id: str # User ID of the patient
user_id: str # User ID of the patient
mrn: str
referring_npi: Optional[str] = None
payer: Optional[str] = None
Expand Down Expand Up @@ -56,25 +57,52 @@ def lookup_approved_provider(self, authorized_user: User):

def add_approved_provider(self, authorized_user: User, requesting_user: User):
## Add a new column for every approvede provider ID
assert requesting_user.id == self.patient_id, 'Only the patient can approve a provider'
self.add_attribute('approved_provider_id-%s' % authorized_user.id, datetime.datetime.utcnow().timestamp())
assert requesting_user.id == self.user_id, 'Only the patient can approve a provider'
self._AkelloBaseModel__add_attribute('approved_provider_id:%s' % authorized_user.id,
Decimal(datetime.datetime.utcnow().timestamp()))

def remove_approved_provider(self, authorized_user: User):
## Remove the column for the approvede provider ID
self.remove_attribute('approved_provider_id-%s' % authorized_user.id)
self._AkelloBaseModel__remove_attribute('approved_provider_id-%s' % authorized_user.id)


class RegistryTreatmentLog(AkelloBaseModel):
registry_id: str
user_id: str
timestamp: str

@property
def partition_key(self) -> str:
return 'treatment-log::registry-id:%s::user-id%s' % (self.registry_id, self.user_id)

@property
def sort_key(self) -> float:
return self.created_at
def sort_key(self) -> str:
return str(self.timestamp)

def put(self):
self._AkelloBaseModel__put()

def set_scores(self, key: str, value: any):
self._AkelloBaseModel__add_attribute(key, value)


class RegistryTreatmentLogCommentLog(AkelloBaseModel):
registry_id: str
user_id: str
timestamp: str
comment: str
author_user_id: str

@property
def partition_key(self) -> str:
return 'treatment-log-comment::registry-id:%s::user-id%s' % (self.registry_id, self.user_id)

@property
def sort_key(self) -> str:
return str(self.timestamp)

def put(self):
self._AkelloBaseModel__put()



def set_scores(self, key: str, value: dict):
self.add_attribute(key, value)
33 changes: 32 additions & 1 deletion packages/server/akello/db/tests/manual_test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from akello.db.models_v2.organization import User
from akello.db.models_v2.organization import Organization
from akello.db.models_v2.user import UserRegistryRole
from akello.db.models_v2.registry_treatment import RegistryTreatment
from akello.db.models_v2.registry_treatment import RegistryTreatment, RegistryTreatmentLog, RegistryTreatmentLogCommentLog
import datetime

test_organization_owner = User()

Expand All @@ -25,6 +26,36 @@


# Add a patient to the registry
patient_user = User()
test_registry_1.add_user(user=patient_user, role=UserRegistryRole.patient, requesting_user=test_organization_owner)

# grant a user access to the patient (test access)

# add treatment log and set scores
patient_registry_treatment = RegistryTreatment(
registry_id=test_registry_1.id,
user_id=patient_user.id,
mrn='test mrn',
)

patient_registry_treatment.add_approved_provider(authorized_user=care_manager_user, requesting_user=patient_user)

treatment_log = RegistryTreatmentLog(
registry_id=test_registry_1.id,
user_id=patient_user.id,
timestamp=str(datetime.datetime.utcnow().timestamp())
)
treatment_log.set_scores(key='PHQ-9', value={'score': 1, 'date': '2021-01-01'})
treatment_log.set_scores(key='GAD-7', value={'score': 1, 'date': '2021-01-01'})


comment = RegistryTreatmentLogCommentLog(
registry_id=test_registry_1.id,
user_id=patient_user.id,
timestamp=str(datetime.datetime.utcnow().timestamp()),
comment='test comment',
author_user_id=care_manager_user.id
)
comment.put()


0 comments on commit fc55672

Please sign in to comment.