Skip to content
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

Added estimated birthdate field to Patient content type #113

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
1.5.0 (unreleased)
------------------

- #113 Added estimated birthdate field to Patient content type
- #112 Use default TZ when calculating birthdate if `on_date` param is not set
- #111 Allow/Disallow the introduction of future dates of birth
- #110 Compatibility with core#2584 (SampleType to DX)
Expand Down
1 change: 1 addition & 0 deletions src/senaite/patient/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def update_patient(patient, **values):
patient.setSex(values.get("sex", ""))
patient.setGender(values.get("gender", ""))
patient.setBirthdate(values.get("birthdate"))
patient.setEstimatedBirthdate(values.get("estimated_birthdate", False))
patient.setAddress(values.get("address"))
# reindex the new values
patient.reindexObject()
Expand Down
7 changes: 4 additions & 3 deletions src/senaite/patient/browser/patient/add2.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ def get_default_value(self, field, context, arnum):
address = self.context.getFormattedAddress()
return api.to_utf8(address)
elif name == "DateOfBirth":
birthdate = self.context.getBirthdate()
if birthdate:
return birthdate.strftime("%Y-%m-%d")
from_age = False
birthdate = self.context.getBirthdate(as_date=False)
estimated = self.context.getEstimatedBirthdate()
return [birthdate, from_age, estimated]
elif name == "Sex":
return self.context.getSex()
elif name == "Gender":
Expand Down
3 changes: 3 additions & 0 deletions src/senaite/patient/browser/patientfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ def folderitem(self, obj, item, index):

# Birthdate
item["birthdate"] = obj.getLocalizedBirthdate()
if obj.getEstimatedBirthdate():
item["after"]["birthdate"] = get_image(
"warning.png", title=t(_("The birthdate is estimated")))

# Folder
parent = api.get_parent(obj)
Expand Down
29 changes: 29 additions & 0 deletions src/senaite/patient/content/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ class IPatientSchema(model.Schema):
# property is explicitly set to the widget
birthdate.get_max = get_max_birthdate

estimated_birthdate = schema.Bool(
title=_(
u"label_patient_estimated_birthdate",
default=u"Birthdate is estimated"
),
description=_(
u"description_patient_estimated_birthdate",
default=u"Select this option if the patient's date of birth is "
u"estimated"
),
default=False,
required=False,
)

deceased = schema.Bool(
title=_(
u"label_patient_deceased",
Expand Down Expand Up @@ -735,6 +749,7 @@ def getBirthdate(self, as_date=True):
accessor = self.accessor("birthdate")
value = accessor(self)
# Return a plain date object to avoid timezone issues
# TODO Convert to current timezone and keep it as datetime instead!
if dtime.is_dt(value) and as_date:
value = value.date()
return value
Expand Down Expand Up @@ -796,3 +811,17 @@ def setDeceased(self, value):
"""
mutator = self.mutator("deceased")
return mutator(self, value)

@security.protected(permissions.View)
def getEstimatedBirthdate(self):
"""Returns whether the patient's date of birth is estimated
"""
accessor = self.accessor("estimated_birthdate")
return accessor(self)

@security.protected(permissions.ModifyPortalContent)
def setEstimatedBirthdate(self, value):
"""Set if the patient's date of birth is estimated
"""
mutator = self.mutator("estimated_birthdate")
return mutator(self, value)
7 changes: 5 additions & 2 deletions src/senaite/patient/subscribers/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def get_patient_fields(instance):
mrn = instance.getMedicalRecordNumberValue()
sex = instance.getField("Sex").get(instance)
gender = instance.getField("Gender").get(instance)
birthdate = instance.getField("DateOfBirth").get(instance)
dob_field = instance.getField("DateOfBirth")
birthdate = dob_field.get_date_of_birth(instance)
estimated = dob_field.get_estimated(instance)
address = instance.getField("PatientAddress").get(instance)
field = instance.getField("PatientFullName")
firstname = field.get_firstname(instance)
Expand All @@ -134,7 +136,8 @@ def get_patient_fields(instance):
"mrn": mrn,
"sex": sex,
"gender": gender,
"birthdate": birthdate[0],
"birthdate": birthdate,
"estimated_birthdate": estimated,
"address": address,
"firstname": api.safe_unicode(firstname),
"middlename": api.safe_unicode(middlename),
Expand Down
Loading