-
Notifications
You must be signed in to change notification settings - Fork 582
refact:added patient age in patient retrive spec #3546
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
base: develop
Are you sure you want to change the base?
Changes from 4 commits
37913f8
d44e74f
dc294f3
87394be
35b6f0f
c005b2f
3213001
ac52f75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||||||||
| import secrets | ||||||||||||||||
| import sys | ||||||||||||||||
| from secrets import choice | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -6,11 +7,18 @@ | |||||||||||||||
| from model_bakery import baker | ||||||||||||||||
| from rest_framework.test import APITestCase | ||||||||||||||||
|
|
||||||||||||||||
| from care.emr.management.commands.load_fixtures import ( | ||||||||||||||||
| generate_unique_indian_phone_number, | ||||||||||||||||
| ) | ||||||||||||||||
| from care.emr.models.organization import FacilityOrganizationUser, OrganizationUser | ||||||||||||||||
| from care.emr.resources.encounter.constants import ( | ||||||||||||||||
| ClassChoices, | ||||||||||||||||
| EncounterPriorityChoices, | ||||||||||||||||
| ) | ||||||||||||||||
| from care.emr.resources.patient.spec import ( | ||||||||||||||||
| BloodGroupChoices, | ||||||||||||||||
| GenderChoices, | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| # Global mocking, since the types are loaded when specs load, mocking using patch was not working as the validations were already loaded. | ||||||||||||||||
| # TODO: figure out a more customizeable approach to mock this | ||||||||||||||||
|
|
@@ -83,6 +91,13 @@ def create_role_with_permissions(self, permissions, role_name=None): | |||||||||||||||
| def create_patient(self, **kwargs): | ||||||||||||||||
| from care.emr.models import Patient | ||||||||||||||||
|
|
||||||||||||||||
| kwargs.setdefault("name", self.fake.name()) | ||||||||||||||||
| kwargs.setdefault("gender", secrets.choice(list(GenderChoices)).value) | ||||||||||||||||
| kwargs.setdefault("phone_number", generate_unique_indian_phone_number()) | ||||||||||||||||
| kwargs.setdefault("address", self.fake.address()) | ||||||||||||||||
| kwargs.setdefault("pincode", self.fake.random_int(min=100000, max=999999)) | ||||||||||||||||
| kwargs.setdefault("blood_group", secrets.choice(list(BloodGroupChoices)).value) | ||||||||||||||||
| kwargs.setdefault("date_of_birth", self.fake.date_of_birth()) | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a deterministic Line 100 currently randomizes DOB, which can make age assertions drift over time. A fixed default is more reliable, and specific tests can still override it. Proposed change+from datetime import date
import secrets
import sys
from secrets import choice
@@
- kwargs.setdefault("date_of_birth", self.fake.date_of_birth())
+ kwargs.setdefault("date_of_birth", date(1990, 1, 1))As per coding guidelines, 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| return baker.make(Patient, **kwargs) | ||||||||||||||||
|
|
||||||||||||||||
| def create_facility(self, user, **kwargs): | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while creating and updating , on de serialization the date_of_birth is converted to str (in-memory) So on serialize the get_age() will crash since using data from the same in-memory obj !