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

Change provider child relationship to many-to-many #224

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

omeradeel26
Copy link
Contributor

@omeradeel26 omeradeel26 commented Nov 20, 2023

Notion ticket link

Make Providers Children a Many to Many Relationship

Implementation description

  • Changed child model to have many-to-many relationship with providers (Provider has 'children' attribute and Child has 'providers' attribute
  • Provider now has intake_id used as foreign key, removing previous child_id foreign key
  • get_children_by_provider and get_providers_by_child services created

Steps to test

  1. Once Kevin 'intake' ticket is merged to main, verify that providers are being created and can be viewed under children in the case overview section

What should reviewers focus on?

  • Database migration is working
  • A bit confused how to approach DB seeding with 'many-to-many' relationship for providers and children, for now providers are removed from seeding process

Checklist

  • My PR name is descriptive and in imperative tense
  • My commit messages are descriptive and in imperative tense. My commits are atomic and trivial commits are squashed or fixup'd into non-trivial commits
  • I have run the appropriate linter(s)
  • I have requested a review from the PL, as well as other devs who have background knowledge on this PR or who will be building on top of this PR

@omeradeel26 omeradeel26 changed the title Omer/provider child relationship Change provider child relationship to many-to-many Nov 20, 2023
Copy link

github-actions bot commented Nov 20, 2023

Visit the preview URL for this PR (updated for commit 557f41f):

https://childrens-aid-society--pr224-omer-provider-child-a1qmosjy.web.app

(expires Tue, 12 Dec 2023 02:51:55 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 93f6cb7bff946a1edd29d684408e6d31442cf0b1

undos.append((provider_service, "delete_provider", provider_response.id))
except Exception as error:
run_undos()
return jsonify(error), 400

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.
@omeradeel26 omeradeel26 requested a review from a team November 20, 2023 19:45
Copy link
Collaborator

@Ezzhingy Ezzhingy left a comment

Choose a reason for hiding this comment

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

nice job! the GET request works nicely :))

in terms of seeding ur db, u can fill out the provider fields as follows:

# Providers
values = [(1, "Karen Namen", "123123", "primary phone", "secondary phone", "[email protected]", "address", "FOSTER CAREGIVER")]

for value in values:
       insert_values(db, "providers", ("intake_id", "name", "file_number", "primary_phone_number", "secondary_phone_number", "email", "address", "relationship_to_child", "additional_contact_notes"), value)

Then,

docker exec -it cas_db /bin/bash -c "psql -U postgres -d cas"
INSERT INTO child_providers (child_id, providers_id) VALUES (1,1);

return jsonify(error), 400
providers_by_child = child["provider"]
for provider in providers_by_child:
if provider.providerId in children_providers:
Copy link
Collaborator

Choose a reason for hiding this comment

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

i c wat ur going for here, but when the user POSTs the intake obj, the provider obj within it has no field providerId (see intake frontend<>backend for more info)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While working on the changes, I added a providerId which is now included in the provider interface apart of ProviderDetails, so it should work. It's present in this file: .\frontend\src\components\intake\NewProviderModal.tsx and is defined across all components working with ProviderDetails

@@ -53,13 +59,22 @@ def delete_provider(self, provider_id):
db.session.rollback()
raise error

def get_providers_by_child_id(self, child_id):
def get_children_by_provider(self, provider_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think it makes more sense to have this function within child_service.py

@omeradeel26 omeradeel26 requested a review from Ezzhingy December 7, 2023 01:22
Copy link
Collaborator

@Ezzhingy Ezzhingy left a comment

Choose a reason for hiding this comment

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

small changes w POST

else:
children_providers[provider["providerId"]] = [child_response.id]

if not any(x.providerId == provider.providerId for x in all_providers):
Copy link
Collaborator

Choose a reason for hiding this comment

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

provider["providerId"]

return jsonify(error), 400
providers_by_child = child["provider"]
for provider in providers_by_child:
if provider.providerId in children_providers:
Copy link
Collaborator

Choose a reason for hiding this comment

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

provider["providerId"]

Comment on lines +422 to +424
provider_response = provider_service.create_new_provider(
CreateProviderDTO(**provider_obj),
children_providers[provider["providerId"]],
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, just looked into this—it seems like the create_new_provider function doesn't work when it takes in children_ids as a param..
for now (until we fix this), keep the arg for create_new_provider as

provider_response = provider_service.create_new_provider(
    CreateProviderDTO(**provider_obj)
)

you're going to have to change some of your providers_by_child logic, since atm the POST request doesn't save providers properly

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

Successfully merging this pull request may close these issues.

3 participants