Skip to content

Commit

Permalink
Merge pull request #533 from anantmittal/registry-mark-review
Browse files Browse the repository at this point in the history
Registry Support for "Mark Reviewed" of "New" Patient Entries
  • Loading branch information
jayfo authored Aug 19, 2024
2 parents 9066a23 + 9f415c3 commit bae0546
Show file tree
Hide file tree
Showing 22 changed files with 857 additions and 48 deletions.
73 changes: 73 additions & 0 deletions scope_shared/scope/database/patient/review_marks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from typing import List, Optional

import pymongo.collection
import scope.database.collection_utils

DOCUMENT_TYPE = "reviewMark"
SEMANTIC_SET_ID = "reviewMarkId"


def get_review_marks(
*,
collection: pymongo.collection.Collection,
) -> Optional[List[dict]]:
"""
Get list of "reviewMark" documents.
"""

return scope.database.collection_utils.get_set(
collection=collection,
document_type=DOCUMENT_TYPE,
)


def get_review_mark(
*,
collection: pymongo.collection.Collection,
set_id: str,
) -> Optional[dict]:
"""
Get "reviewMark" document.
"""

return scope.database.collection_utils.get_set_element(
collection=collection,
document_type=DOCUMENT_TYPE,
set_id=set_id,
)


def post_review_mark(
*,
collection: pymongo.collection.Collection,
review_mark: dict,
) -> scope.database.collection_utils.SetPostResult:
"""
Post "reviewMark" document.
"""

return scope.database.collection_utils.post_set_element(
collection=collection,
document_type=DOCUMENT_TYPE,
semantic_set_id=SEMANTIC_SET_ID,
document=review_mark,
)


def put_review_mark(
*,
collection: pymongo.collection.Collection,
review_mark: dict,
set_id: str,
) -> scope.database.collection_utils.SetPutResult:
"""
Put "reviewMark" document.
"""

return scope.database.collection_utils.put_set_element(
collection=collection,
document_type=DOCUMENT_TYPE,
semantic_set_id=SEMANTIC_SET_ID,
set_id=set_id,
document=review_mark,
)
4 changes: 4 additions & 0 deletions scope_shared/scope/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
provider_identities_schema: Optional[jschon.JSONSchema] = None
referral_status_schema: Optional[jschon.JSONSchema] = None
regexes: Optional[jschon.JSONSchema] = None
review_mark_schema: Optional[jschon.JSONSchema] = None
review_marks_schema: Optional[jschon.JSONSchema] = None
resource_content_schema: Optional[jschon.JSONSchema] = None
resource_contents_schema: Optional[jschon.JSONSchema] = None
safety_plan_schema: Optional[jschon.JSONSchema] = None
Expand Down Expand Up @@ -100,6 +102,8 @@
"patient_profile_schema": "documents/patient-profile.json",
"provider_identity_schema": "documents/provider-identity.json",
"provider_identities_schema": "documents/provider-identities.json",
"review_mark_schema": "documents/review-mark.json",
"review_marks_schema": "documents/review-marks.json",
"safety_plan_schema": "documents/safety-plan.json",
"scheduled_activity_schema": "documents/scheduled-activity.json",
"scheduled_activities_schema": "documents/scheduled-activities.json",
Expand Down
3 changes: 3 additions & 0 deletions scope_shared/scope/schemas/api/patient.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"description": "IPatientProfile schema",
"$ref": "/schemas/documents/patient-profile"
},
"reviewMarks": {
"$ref": "/schemas/documents/review-marks"
},
"safetyPlan": {
"type": "object",
"description": "ISafetyPlan schema",
Expand Down
3 changes: 3 additions & 0 deletions scope_shared/scope/schemas/document.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
{
"$ref": "/schemas/documents/patient-profile"
},
{
"$ref": "/schemas/documents/review-mark"
},
{
"$ref": "/schemas/documents/safety-plan"
},
Expand Down
35 changes: 35 additions & 0 deletions scope_shared/scope/schemas/documents/review-mark.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://uwscope.org/schemas/documents/review-mark",
"title": "IReviewMark",
"description": "IReviewMark Type",
"type": "object",
"properties": {
"_id": {
"type": "string"
},
"_type": {
"const": "reviewMark"
},
"_set_id": {
"type": "string"
},
"_rev": {
"type": "number"
},
"reviewMarkId": {
"type": "string"
},
"editedDateTime": {
"$ref": "/schemas/utils/datetime#/properties/datetime"
},
"effectiveDateTime": {
"$ref": "/schemas/utils/datetime#/properties/datetime"
},
"providerId": {
"type": "string"
}
},
"additionalProperties": false,
"required": ["_type", "editedDateTime", "providerId"]
}
9 changes: 9 additions & 0 deletions scope_shared/scope/schemas/documents/review-marks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://uwscope.org/schemas/documents/review-marks",
"title": "IReviewMark[]",
"type": "array",
"items": {
"$ref": "/schemas/documents/review-mark"
}
}
2 changes: 2 additions & 0 deletions scope_shared/scope/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"scope.testing.fake_data.fixtures_fake_patient_profile",
"scope.testing.fake_data.fixtures_fake_provider_identity",
"scope.testing.fake_data.fixtures_fake_referral_status",
"scope.testing.fake_data.fixtures_fake_review_mark",
"scope.testing.fake_data.fixtures_fake_review_marks",
"scope.testing.fake_data.fixtures_fake_safety_plan",
"scope.testing.fake_data.fixtures_fake_session",
"scope.testing.fake_data.fixtures_fake_sessions",
Expand Down
74 changes: 74 additions & 0 deletions scope_shared/scope/testing/fake_data/fixtures_fake_review_mark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import datetime
import faker
import pytest
import pytz
from typing import Callable

import scope.database.date_utils as date_utils
import scope.database.patient.review_marks
import scope.enums
import scope.schema
import scope.schema_utils


def fake_review_mark_factory(
*,
faker_factory: faker.Faker,
) -> Callable[[], dict]:
"""
Obtain a factory that will generate fake recent entry review documents.
"""

def factory() -> dict:
fake_review_mark = {
"_type": scope.database.patient.review_marks.DOCUMENT_TYPE,
"editedDateTime": date_utils.format_datetime(
pytz.utc.localize(
faker_factory.date_time_between_dates(
datetime_start=datetime.datetime.now()
- datetime.timedelta(weeks=1),
datetime_end=datetime.datetime.now(),
)
)
),
"effectiveDateTime": date_utils.format_datetime(
pytz.utc.localize(
faker_factory.date_time_between_dates(
datetime_start=datetime.datetime.now()
- datetime.timedelta(weeks=2),
datetime_end=datetime.datetime.now(),
)
)
),
# TODO: this should be a providerId
"providerId": faker_factory.name(),
}

return fake_review_mark

return factory


@pytest.fixture(name="data_fake_review_mark_factory")
def fixture_data_fake_review_mark_factory(
faker: faker.Faker,
) -> Callable[[], dict]:
"""
Fixture for data_fake_review_mark_factory.
"""

unvalidated_factory = fake_review_mark_factory(
faker_factory=faker,
)

def factory() -> dict:
fake_review_mark = unvalidated_factory()

scope.schema_utils.xfail_for_invalid_schema(
schema=scope.schema.review_mark_schema,
data=fake_review_mark,
)

return fake_review_mark

return factory
49 changes: 49 additions & 0 deletions scope_shared/scope/testing/fake_data/fixtures_fake_review_marks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytest
import random
from typing import Callable, List

import scope.schema
import scope.schema_utils


def fake_review_marks_factory(
*,
fake_review_mark_factory: Callable[[], dict],
) -> Callable[[], List[dict]]:
"""
Obtain a factory that will generate a list of fake recent entry review documents.
"""

def factory() -> List[dict]:
fake_review_marks = [
fake_review_mark_factory() for _ in range(random.randint(1, 5))
]

return fake_review_marks

return factory


@pytest.fixture(name="data_fake_review_marks_factory")
def fixture_data_fake_review_marks_factory(
data_fake_review_mark_factory: Callable[[], dict],
) -> Callable[[], List[dict]]:
"""
Fixture for data_fake_review_marks_factory.
"""

unvalidated_factory = fake_review_marks_factory(
fake_review_mark_factory=data_fake_review_mark_factory,
)

def factory() -> List[dict]:
fake_review_marks = unvalidated_factory()

scope.schema_utils.xfail_for_invalid_schema(
schema=scope.schema.review_marks_schema,
data=fake_review_marks,
)

return fake_review_marks

return factory
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import scope.database.patient.assessments
import scope.database.patient.case_reviews
import scope.database.patient.mood_logs
import scope.database.patient.sessions
import scope.database.patient.review_marks
import scope.database.patient.scheduled_activities
import scope.database.patient.scheduled_assessments
import scope.database.patient.sessions
Expand All @@ -38,6 +38,8 @@
import scope.testing.fake_data.fixtures_fake_mood_logs
import scope.testing.fake_data.fixtures_fake_patient_profile
import scope.testing.fake_data.fixtures_fake_provider_identity
import scope.testing.fake_data.fixtures_fake_review_mark
import scope.testing.fake_data.fixtures_fake_review_marks
import scope.testing.fake_data.fixtures_fake_referral_status
import scope.testing.fake_data.fixtures_fake_safety_plan
import scope.testing.fake_data.fixtures_fake_session
Expand Down Expand Up @@ -270,6 +272,26 @@ class ConfigTestFakeDataSchema:
expected_semantic_set_id=scope.database.providers.PROVIDER_IDENTITY_SEMANTIC_SET_ID,
expected_set_ids=None,
),
ConfigTestFakeDataSchema(
name="review-mark",
schema=scope.schema.review_mark_schema,
data_factory_fixture="data_fake_review_mark_factory",
expected_document=True,
expected_singleton=False,
expected_set_element=True,
expected_semantic_set_id=scope.database.patient.review_marks.SEMANTIC_SET_ID,
expected_set_ids=None,
),
ConfigTestFakeDataSchema(
name="review-marks",
schema=scope.schema.review_marks_schema,
data_factory_fixture="data_fake_review_marks_factory",
expected_document=False,
expected_singleton=False,
expected_set_element=False,
expected_semantic_set_id=None,
expected_set_ids=None,
),
ConfigTestFakeDataSchema(
name="referral-status",
schema=scope.schema.referral_status_schema,
Expand Down
5 changes: 5 additions & 0 deletions server_flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import blueprints.registry.patient_profile
import blueprints.registry.patients
import blueprints.registry.providers
import blueprints.registry.review_marks
import blueprints.registry.safety_plan
import blueprints.registry.sessions
import blueprints.registry.scheduled_activities
Expand Down Expand Up @@ -149,6 +150,10 @@ def status():
blueprints.registry.values.values_blueprint,
url_prefix="/patient/",
)
app.register_blueprint(
blueprints.registry.review_marks.review_marks_blueprint,
url_prefix="/patient/",
)

# # Register all the `patient` blueprints, i.e. blueprints for web_patient
# patient = Blueprint("patient", __name__, url_prefix="/patient")
Expand Down
7 changes: 7 additions & 0 deletions server_flask/blueprints/registry/patients.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import scope.database.patient.clinical_history
import scope.database.patient.mood_logs
import scope.database.patient.patient_profile
import scope.database.patient.review_marks
import scope.database.patient.safety_plan
import scope.database.patient.scheduled_activities
import scope.database.patient.scheduled_assessments
Expand Down Expand Up @@ -58,6 +59,7 @@ def _construct_patient_document(
scope.database.patient.assessment_logs.DOCUMENT_TYPE,
scope.database.patient.case_reviews.DOCUMENT_TYPE,
scope.database.patient.mood_logs.DOCUMENT_TYPE,
scope.database.patient.review_marks.DOCUMENT_TYPE,
scope.database.patient.scheduled_activities.DOCUMENT_TYPE,
scope.database.patient.sessions.DOCUMENT_TYPE,
scope.database.patient.values.DOCUMENT_TYPE,
Expand Down Expand Up @@ -109,6 +111,11 @@ def _construct_patient_document(
scope.database.patient.patient_profile.DOCUMENT_TYPE
]

# Review Marks
patient_document["reviewMarks"] = documents_by_type[
scope.database.patient.review_marks.DOCUMENT_TYPE
]

# Safety Plan
patient_document["safetyPlan"] = documents_by_type[
scope.database.patient.safety_plan.DOCUMENT_TYPE
Expand Down
Loading

0 comments on commit bae0546

Please sign in to comment.