Skip to content

Commit

Permalink
Merge branch 'master' of github.com:senaite/senaite.patient into dyna…
Browse files Browse the repository at this point in the history
…mic-ranges-age-sex
  • Loading branch information
xispa committed Nov 13, 2023
2 parents c69af69 + dadb52a commit e4e21bd
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
1.4.0 (unreleased)
------------------

- #97 Fix birth date is not displayed in patients listing
- #93 Layered listing searchable text adapter
- #92 Allow searches by patient in samples listing
- #91 Allow only 1 Patient per Report
Expand Down
6 changes: 4 additions & 2 deletions src/senaite/patient/browser/patientfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from bika.lims.utils import get_image
from bika.lims.utils import get_link
from senaite.app.listing.view import ListingView
from senaite.core.api import dtime
from senaite.patient import messageFactory as _sp
from senaite.patient.api import to_identifier_type_name
from senaite.patient.api import tuplify_identifiers
Expand Down Expand Up @@ -193,8 +194,9 @@ def folderitem(self, obj, item, index):

# Birthdate
birthdate = obj.getBirthdate()
if birthdate:
item["birthdate"] = self.ulocalized_time(birthdate, long_format=0)
# birthdate is a datetime.date object
birthdate = dtime.to_DT(birthdate)
item["birthdate"] = dtime.to_localized_time(birthdate)

# Folder
parent = api.get_parent(obj)
Expand Down
2 changes: 1 addition & 1 deletion src/senaite/patient/browser/widgets/temporaryidentifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def process_form(self, instance, field, form, empty_marker=None,

value = {
"temporary": temporary,
"value": identifier,
"value": identifier.strip(),
"value_auto": autogenerated,
}
return value, {}
Expand Down
2 changes: 1 addition & 1 deletion src/senaite/patient/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>1415</version>
<version>1416</version>
<dependencies>
<dependency>profile-senaite.lims:default</dependency>
</dependencies>
Expand Down
53 changes: 53 additions & 0 deletions src/senaite/patient/upgrade/v01_04_000.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,56 @@ def allow_searches_by_patient_in_samples(tool):
cat = api.get_tool(SAMPLE_CATALOG)
cat.reindexIndex(["listing_searchable_text"], None, ZLogHandler())
logger.info("Allowing searches by patient in samples [DONE]")


def remove_whitespaces_mrn(tool):
"""Resets the date of birth from samples
"""
logger.info("Removing lead and trailing whitespaces from MRN ...")

uc = api.get_tool("uid_catalog")
brains = uc(portal_type="AnalysisRequest")
total = len(brains)

for num, brain in enumerate(brains):
if num and num % 100 == 0:
logger.info("Migrated {0}/{1} fields".format(num, total))

if num and num % 1000 == 0:
# reduce memory size of the transaction
transaction.savepoint()

try:
obj = api.get_object(brain)
except AttributeError:
uncatalog_brain(brain)
continue

if not obj:
continue

mrn = obj.getField("MedicalRecordNumber").get(obj)
if not mrn:
# Flush the object from memory
obj._p_deactivate()
continue

value = mrn.get("value")
if not value:
# Flush the object from memory
obj._p_deactivate()
continue

stripped = value.strip()
if stripped == value:
obj._p_deactivate()
continue

# Reset the value
mrn["value"] = stripped
obj.getField("MedicalRecordNumber").set(obj, mrn)
# reindex so indexes and columns are updated in accordance
obj.reindexObject()
obj._p_deactivate()

logger.info("Removing lead and trailing whitespaces from MRN [DONE]")
14 changes: 14 additions & 0 deletions src/senaite/patient/upgrade/v01_04_000.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup">

<!-- 1416: Allow searches by patient in samples -->
<genericsetup:upgradeStep
title="Remove lead and trailing whitespaces from MRN"
description="
This upgrade step walks through all samples and removes trailing and
leading whitespaces from Medical Record Number fields. This is
necessary because when creating a Patient object, the MRN is
automatically stripped in setMRN function, although is left without
changes in AnalysisRequest."
source="1415"
destination="1416"
handler=".v01_04_000.remove_whitespaces_mrn"
profile="senaite.patient:default"/>

<!-- 1415: Allow searches by patient in samples -->
<genericsetup:upgradeStep
title="SENAITE PATIENT 1.4.0: Allow patient searches in samples"
Expand Down

0 comments on commit e4e21bd

Please sign in to comment.