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

Check bed name before making new multiple beds with same name #1530

Closed
wants to merge 1 commit into from

Conversation

Pranshu1902
Copy link
Contributor

Proposed Changes

  • Instead of straight away adding the number 1 behind each bed name, we first check the number from which the bed names are available and then start adding the beds. For example if the user is adding 2 beds with name Bed and there is already a bed with name Bed 1, then the new beds created will be Bed 2 & Bed 3 instead of Bed 1 & Bed 2.

Associated Issue

Fixes #1529

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete
  • Any other necessary step

Only PR's with test cases included and passing lint and test pipelines will be reviewed

@coronasafe/care-backend-maintainers @coronasafe/care-backend-admins

Comment on lines +69 to +77
start = 1
while True:
if not Bed.objects.filter(
name=f"{serializer.validated_data['name']} {start}",
facility=serializer.validated_data['facility'],
location=serializer.validated_data["location"]
).exists():
break
start += 1
Copy link
Member

Choose a reason for hiding this comment

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

you can achieve this with a single query, search and reverse sort by name

@Pranshu1902
Copy link
Contributor Author

Pranshu1902 commented Oct 20, 2023

@sainak any update regarding whether this check is needed at all?

@sainak
Copy link
Member

sainak commented Oct 20, 2023

The solution would be to index the bed names and before creating beds do a lookup of any existing beds with names

but creating unique index can cause conflict, so this is a blocker

@vigneshhari what are your thoughts?

@Pranshu1902
Copy link
Contributor Author

Resolved in #1783

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple beds can be created with the same name
3 participants