Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Required patient data can be omitted on save causing errors on re-edit
Browse files Browse the repository at this point in the history
  • Loading branch information
xispa committed Apr 29, 2020
1 parent ff0c562 commit 787d181
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Changelog

**Fixed**

- #184 Required patient data can be omitted on save causing error on re-edit

**Security**


Expand Down
34 changes: 32 additions & 2 deletions bika/health/browser/patient/chronicconditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from bika.lims import PMF as _p
from bika.lims import api
from bika.lims.browser import BrowserView


Expand All @@ -28,6 +29,35 @@ class ChronicConditionsView(BrowserView):

def __call__(self):
if 'submitted' in self.request:
self.context.setChronicConditions(self.request.form.get('ChronicConditions', ()))
self.context.plone_utils.addPortalMessage(_p("Changes saved"))

conditions = self.request.form.get("ChronicConditions")

# Check if all required items have been filled
valid = map(self.validate, conditions)
if all(valid):
# All chronic conditions are correct
self.context.setChronicConditions(conditions)
self.context.plone_utils.addPortalMessage(_p("Changes saved"))

elif valid:
# With at least one item, but not correct
self.context.plone_utils.addPortalMessage(
_p("Please correct the indicated errors"), "error")

return self.template()

def validate(self, condition):
"""Returns True if all required values for the condition are valid
"""
title = condition.get("Title")
title = title and title.strip()
if not title:
# Not a valid title
return False

onset = condition.get("Onset")
if not api.to_date(onset, default=None):
# Not a valid Onset date
return False

return True

0 comments on commit 787d181

Please sign in to comment.