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

Users unable to enter new patients on the Platform #1190

Closed
SAbdin93 opened this issue Jan 28, 2025 · 4 comments · Fixed by #1191 or #1196
Closed

Users unable to enter new patients on the Platform #1190

SAbdin93 opened this issue Jan 28, 2025 · 4 comments · Fixed by #1191 or #1196
Assignees
Labels
bug Something isn't working priority: highest Highest Priority Work - Max 1 Item

Comments

@SAbdin93
Copy link

Hiya,

I’ve received two separate queries from users who are unable to add new patients, encountering a message that reads: "Unique reference number (URN) already exists."

For the first query, I’ve checked, and there is no record of the patient in the system, nor has the patient been uploaded by any other user/trust. Therefore, they should be able to create a new entry...but they can't.

For the second query, the user has confirmed that the patients are newly diagnosed and would not have been added to the platform previously by them or any other trust.

Could you please look into this?

Let me know if there is anything you need from me.

Saleema

@SAbdin93 SAbdin93 added the bug Something isn't working label Jan 28, 2025
@mbarton mbarton self-assigned this Jan 28, 2025
@mbarton
Copy link
Member

mbarton commented Jan 28, 2025

Thanks @SAbdin93. From the look of the error message I would guess this has happened after we merged in support for Jersey (#1105).

I will look into this now as a priority

@mbarton mbarton added the priority: highest Highest Priority Work - Max 1 Item label Jan 28, 2025
@mbarton
Copy link
Member

mbarton commented Jan 28, 2025

I can reproduce in staging - I was able to add one patient but then the second failed

It was not possible to save the case: unique_reference_number: Patient with this Unique Reference Number (URN) already exists.

It seems like our uniqueness constraint does not handle URN being null

@mbarton
Copy link
Member

mbarton commented Jan 28, 2025

I think unique_reference_number may end up as the empty string in the database rather than NULL. This is from a patient I added locally:

>>> from epilepsy12.models import *
>>> Case.objects.get(pk=6)
<Case: Bob Dylan>
>>> Case.objects.get(pk=6).nhs_number
'2900743109'
>>> Case.objects.get(pk=6).unique_reference_number
''
>>> Case.objects.get(pk=6).unique_reference_number is None
False
>>> Case.objects.get(pk=6).unique_reference_number == ''
True
>>> 

Confirmed in psql:

epilepsy12db=# select id, unique_reference_number from epilepsy12_case where id = 6;
 id | unique_reference_number 
----+-------------------------
  6 | 
(1 row)

epilepsy12db=# select id, unique_reference_number is null from epilepsy12_case where id = 6;
 id | ?column? 
----+----------
  6 | f
(1 row)

epilepsy12db=# select id, unique_reference_number = '' from epilepsy12_case where id = 6;
 id | ?column? 
----+----------
  6 | t
(1 row)

I suspect blank=True in the Case model is the culprit here. unique_reference_number is not sent in the POST when creating the patient:

Image

@mbarton
Copy link
Member

mbarton commented Jan 28, 2025

I was confused why I didn't get emails about this error but because it was a form validation error (I think) it wasn't logged at error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: highest Highest Priority Work - Max 1 Item
Projects
None yet
2 participants