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 non-unique MRNs are permitted when "Require MRN" setting is enabled #86

Merged
merged 13 commits into from
Sep 21, 2023

Conversation

xispa
Copy link
Member

@xispa xispa commented Sep 20, 2023

Description of the issue/feature this PR addresses

This Pull Request purges duplicates and ensures uniqueness of MRNs, except when empty

Current behavior before PR

When the setting "Require MRN" is enabled, user can set non-unique MRNs on patient creation

Desired behavior after PR is merged

User can never set non-unique MRNs on patient creation

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@xispa xispa requested a review from ramonski September 20, 2023 11:30
Copy link
Contributor

@ramonski ramonski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor changes required

if not patient_api.is_patient_required():
# MRN is not a required field
return
empty = not data.mrn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a better test here: len(data.mrn) == 0
But the above seems to be also ok, even if "0" as MRN comes in.

if not data.mrn:
raise Invalid(_("Patient Medical Record is missing or empty"))
if empty and required:
# empty and required. It cannot be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be or not to be – it cannot be ...

patient = patient_api.get_patient_by_mrn(
data.mrn, full_object=False, include_inactive=True)
elif empty:
# empty and non required
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo in non, but ignorable

if not patient_api.is_mrn_unique(data.mrn):
raise Invalid(
_("invalid_patient_mrn_non_unique",
default="Patient Medical Record # must be unique"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather write "Patient Medical Record Number must be unique" and above "Patient Medical Record Number is required"

@@ -430,8 +436,7 @@ def setMRN(self, value):
return

# Check if a patient with this same MRN already exists
if patient_api.get_patient_by_mrn(value, full_object=False,
include_inactive=True):
if not patient_api.is_mrn_unique(value):
raise ValueError("Value is not unique: {}".format(value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use the same message pattern here: "Patient Medical Record Number in not unique"

for="senaite.patient.content.patient.IPatient
Products.DCWorkflow.interfaces.IBeforeTransitionEvent"
handler=".patient.on_before_transition"
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time of writing, I thought this subscriber was kind of smart. But I agree to remove it to avoid unneccessary brain twists and that it is probably just confusing instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since mrn must be unique regardless of patient status, this subscriber is no longer needed

@ramonski ramonski merged commit c48aa8b into master Sep 21, 2023
@ramonski ramonski deleted the duplicates-mrn branch September 21, 2023 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants