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 addition of snapshots in PatientFolder on Patient creation #89

Merged
merged 2 commits into from
Oct 3, 2023
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 @@ -5,6 +5,7 @@ Changelog
1.4.0 (unreleased)
------------------

- #89 Fix addition of snapshots in PatientFolder on Patient creation
- #88 Display all samples by default in Patient context
- #86 Fix non-unique MRNs are permitted when "Require MRN" setting is enabled
- #84 Display "Not defined" in listing for patients without MRN set
Expand Down
5 changes: 2 additions & 3 deletions src/senaite/patient/content/patientfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
# Copyright 2020-2022 by it's authors.
# Some rights reserved, see README and LICENSE.

from bika.lims.interfaces import IDoNotSupportSnapshots
from plone.supermodel import model
from senaite.core.content.base import Container

from senaite.core.interfaces import IHideActionsMenu

from zope.interface import implementer


Expand All @@ -32,7 +31,7 @@ class IPatientFolder(model.Schema):
pass


@implementer(IPatientFolder, IHideActionsMenu)
@implementer(IPatientFolder, IDoNotSupportSnapshots, IHideActionsMenu)
class PatientFolder(Container):
"""Patient Folder
"""
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>1413</version>
<version>1414</version>
<dependencies>
<dependency>profile-senaite.lims:default</dependency>
</dependencies>
Expand Down
30 changes: 30 additions & 0 deletions src/senaite/patient/upgrade/v01_04_000.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

import transaction
from bika.lims import api
from bika.lims.api import snapshot
from bika.lims.interfaces import IAuditable
from bika.lims.interfaces import IDoNotSupportSnapshots
from bika.lims.workflow import isTransitionAllowed
from persistent.list import PersistentList
from plone import api as ploneapi
from senaite.core.api import dtime
from senaite.core.api.catalog import del_column
Expand All @@ -35,6 +39,9 @@
from senaite.patient.catalog import PATIENT_CATALOG
from senaite.patient.config import PRODUCT_NAME
from senaite.patient.setuphandlers import setup_catalogs
from zope.annotation.interfaces import IAnnotations
from zope.interface import alsoProvides
from zope.interface import noLongerProvides

version = "1.4.0"
profile = "profile-{0}:default".format(PRODUCT_NAME)
Expand Down Expand Up @@ -511,3 +518,26 @@ def sort_func(a, b):
if isTransitionAllowed(patient, action_id):
api.do_transition_for(patient, "deactivate")
patient.reindexObject()


def remove_patientfolder_snapshots(tool):
"""Removes the auditlog snapshots of Patient Folder and removes the
IAuditable marker interface
"""
logger.info("Removing snapshots from Patient Folder ...")
portal = tool.aq_inner.aq_parent
patients = portal.patients

# do not take more snapshots
alsoProvides(patients, IDoNotSupportSnapshots)

# do not display audit log
noLongerProvides(patients, IAuditable)

# remove all snapshots except the first one (created)
annotation = IAnnotations(patients)
storage = annotation.get(snapshot.SNAPSHOT_STORAGE)
if annotation and len(storage) > 0:
annotation[snapshot.SNAPSHOT_STORAGE] = PersistentList([storage[0]])

logger.info("Removing snapshots from Patient Folder [DONE]")
11 changes: 10 additions & 1 deletion src/senaite/patient/upgrade/v01_04_000.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup">

<!-- 1413: Dix duplicate MRNs -->
<!-- 1414: Fix Auditlog for Patient folder -->
<genericsetup:upgradeStep
title="SENAITE PATIENT 1.4.0: Remove snapshots from Patient folder"
description="Remove snapshots and auditlog from Patient folder"
source="1413"
destination="1414"
handler=".v01_04_000.remove_patientfolder_snapshots"
profile="senaite.patient:default"/>

<!-- 1413: Fix duplicate MRNs -->
<genericsetup:upgradeStep
title="SENAITE PATIENT 1.4.0: Fix MRN duplicates"
description="Fix MRN duplicates"
Expand Down