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

Fix jsonapi returns None for sample's DateOfBirth field #114

Merged
merged 3 commits into from
Oct 26, 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)
------------------

- #114 Fix jsonapi returns None for sample's DateOfBirth field
- #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
Expand Down
1 change: 1 addition & 0 deletions src/senaite/patient/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<include package=".browser" />
<include package=".catalog" />
<include package=".content" />
<include package=".jsonapi" />
<include package=".monkeys" />
<include package=".subscribers" />
<include package=".upgrade" />
Expand Down
4 changes: 4 additions & 0 deletions src/senaite/patient/content/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Some rights reserved, see README and LICENSE.

import six

from AccessControl import ClassSecurityInfo
from archetypes.schemaextender.field import ExtensionField
from Products.Archetypes.Field import ObjectField
Expand All @@ -29,6 +30,8 @@
from senaite.patient.browser.widgets import TemporaryIdentifierWidget
from senaite.patient.config import AUTO_ID_MARKER
from senaite.patient.config import PATIENT_CATALOG
from senaite.patient.interfaces import IAgeDateOfBirthField
from zope.interface import implementer


class TemporaryIdentifierField(ExtensionField, ObjectField):
Expand Down Expand Up @@ -122,6 +125,7 @@ def get_fullname(self, instance):
return " ".join(filter(None, [firstname, middlename, lastname]))


@implementer(IAgeDateOfBirthField)
class AgeDateOfBirthField(ExtensionField, ObjectField):
"""ObjectField extender that stores a tuple (dob, from_age, estimated)
"""
Expand Down
7 changes: 7 additions & 0 deletions src/senaite/patient/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ class IRoutineAnalysis(interface.Interface):
"""Marker interface for routine analyses, that is required for the
patient's dynamic result range adapter to work properly
"""


class IAgeDateOfBirthField(interface.Interface):
"""Marker interface for AT-custom AgeDateOfBirthField. This interface is
necessary for AgeDateOfBirthFieldManager, required by senaite.jsonapi to
properly retrieve and jsonify the value
"""
1 change: 1 addition & 0 deletions src/senaite/patient/jsonapi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
8 changes: 8 additions & 0 deletions src/senaite/patient/jsonapi/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<configure xmlns="http://namespaces.zope.org/zope">

<!-- Adapter for senaite.patient's AT AgeDateOfBirthField -->
<adapter
for="senaite.patient.interfaces.IAgeDateOfBirthField"
factory=".fieldmanagers.AgeDateOfBirthFieldManager"/>

</configure>
21 changes: 21 additions & 0 deletions src/senaite/patient/jsonapi/fieldmanagers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-

from senaite.jsonapi import api
from senaite.jsonapi.fieldmanagers import ATFieldManager
from senaite.jsonapi.interfaces import IFieldManager
from zope import interface


class AgeDateOfBirthFieldManager(ATFieldManager):
"""Adapter to get/set the value of AT's AgeDateOfBirthField
"""
interface.implements(IFieldManager)

def json_data(self, instance, default=None):
"""Get a JSON compatible value
"""
dob = self.field.get_date_of_birth(instance)
from_age = self.field.get_from_age(instance)
estimated = self.field.get_estimated(instance)

return [api.to_iso_date(dob), from_age, estimated]
Loading