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

Adds the non zero prefixed MRN database constraint #1439

Open
wants to merge 2 commits into
base: v0.108
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions elcid/migrations/0069_auto_20230323_1653.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.2.16 on 2023-03-23 16:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('elcid', '0068_remove_mergedmrn_upstream_merge_datetime'),
]

operations = [
migrations.AddConstraint(
model_name='demographics',
constraint=models.CheckConstraint(check=models.Q(_negated=True, hospital_number__startswith=0), name='No initial zeros'),
),
]
12 changes: 9 additions & 3 deletions elcid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class MergedMRN(models.Model):

class PreviousMRN(models.Model):
"""
A mixin for subrecords to maintain an audit trail for occasions
A mixin for subrecords to maintain an audit trail for occasions
when an upstream MRN merge occurs and the merged MRN has elCID entries.

`previous_mrn` is the MRN in use at the time that this subrecord instance
was last created/edited with if that MRN is different from the current
was last created/edited with if that MRN is different from the current
value of `Demographics.hospital_number` attached to this instance.
"""
previous_mrn = models.CharField(blank=True, null=True, max_length=256)
Expand Down Expand Up @@ -75,6 +75,12 @@ def age(self):

class Meta:
verbose_name_plural = "Demographics"
constraints = [
models.CheckConstraint(
check = ~models.Q(hospital_number__startswith=0),
Copy link
Member

Choose a reason for hiding this comment

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

I think I landed at either a different spelling or a comment explaining how bitwise not works here...

name = 'No initial zeros',
),
]


class ContactInformation(PatientSubrecord, ExternallySourcedModel):
Expand Down