Patient code unique within an organisation: Organization on Patient and a database constraint
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start by reading the Patient model and its visibility logic, then trace Patient.match and the patient form, sample/cohort dialog, API serializer, and CSV import. First run the provided duplicate-code query on deployments; the issue leaves unresolved how to assign an organization when a patient is shared across organizations. Done means organization-scoped matching and uniqueness work across every create path, with existing data handled.
Written by the indexing model from the issue text.
Description
🤖 Written by Claude
Follows #2518, where the form, create-patient dialog and API refuse a patient code another visible patient already has. That is a visibility-scoped check in Python, not a database constraint, so a race, a superuser or a direct write can still create a duplicate.
Problem
Patient has no lab or organisation column: visibility is Guardian permissions on users and groups (labs and organisations are groups), so there is nothing to scope a UniqueConstraint on. Patient.match and the CSV import already treat a code as the sole identity and raise "Matched multiple patients" on a duplicate.
A global unique index on patient_code is not right: on a shared server, unrelated labs' short de-identified codes ("P001") would collide. Within one organisation (SA Path) a patient legitimately moves between labs, so the organisation is the scope.
Proposed fix
Patient.organizationFK, with a partialUniqueConstrainton(organization, patient_code)where the code is non-blank.- Backfill from the group object permissions (lab group -> lab -> organisation); decide what to do when a patient is shared with several organisations' groups.
- Every create path sets it: the patient form, the sample/cohort create-patient dialog, the API serializer and the CSV import. A user in several organisations needs a chooser; a user in one gets it set.
Patient.matchscopes by organisation as well as visibility.
Before building it: count duplicate codes on each deployment to see whether any exist.
SELECT patient_code, count(*) FROM patients_patient
WHERE coalesce(btrim(patient_code), '') <> ''
GROUP BY patient_code HAVING count(*) > 1;
- Dominant language
- Python
- Stars
- 31
- Forks
- 4
- Avg merge
- 4h 52m
- Merged PRs (30d)
- 183
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SACGF/variantgrid
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
SACGF/variantgrid#2964 · 1 comment ·
Maintainers usually reply within 1 day
-
Genome build now duplicated in "imported as" on allele pagePossibly taken @TheMadBug claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
SACGF/variantgrid#2950 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
SACGF/variantgrid#2865 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
SACGF/variantgrid#2647 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
SACGF/variantgrid#2341 · 3 comments ·
Maintainers usually reply within 1 day
All issues in SACGF/variantgrid
Similar issues
-
Test: to_hijri() accepts datetime.datetime and uses only the date partPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 · 3 comments ·
Maintainers usually reply within 1 day
-
polish
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scoresPossibly taken @AshutoshSingh840 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
UKGovernmentBEIS/control-arena#992 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
mvalentsev/awesome-free-ai-coding#70 ·
Maintainers usually reply within 1 day