diff --git a/docs/changelog.rst b/docs/changelog.rst index 68389617..9f233b7d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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 diff --git a/src/senaite/patient/content/patientfolder.py b/src/senaite/patient/content/patientfolder.py index f0fe2d94..f7c51183 100644 --- a/src/senaite/patient/content/patientfolder.py +++ b/src/senaite/patient/content/patientfolder.py @@ -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 @@ -32,7 +31,7 @@ class IPatientFolder(model.Schema): pass -@implementer(IPatientFolder, IHideActionsMenu) +@implementer(IPatientFolder, IDoNotSupportSnapshots, IHideActionsMenu) class PatientFolder(Container): """Patient Folder """ diff --git a/src/senaite/patient/profiles/default/metadata.xml b/src/senaite/patient/profiles/default/metadata.xml index c1f9d12c..999485d0 100644 --- a/src/senaite/patient/profiles/default/metadata.xml +++ b/src/senaite/patient/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 1413 + 1414 profile-senaite.lims:default diff --git a/src/senaite/patient/upgrade/v01_04_000.py b/src/senaite/patient/upgrade/v01_04_000.py index 29b51a54..c5d6dc45 100644 --- a/src/senaite/patient/upgrade/v01_04_000.py +++ b/src/senaite/patient/upgrade/v01_04_000.py @@ -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 @@ -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) @@ -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]") diff --git a/src/senaite/patient/upgrade/v01_04_000.zcml b/src/senaite/patient/upgrade/v01_04_000.zcml index 9b6a845c..0c0ca9b2 100644 --- a/src/senaite/patient/upgrade/v01_04_000.zcml +++ b/src/senaite/patient/upgrade/v01_04_000.zcml @@ -2,7 +2,16 @@ xmlns="http://namespaces.zope.org/zope" xmlns:genericsetup="http://namespaces.zope.org/genericsetup"> - + + + +