-
Notifications
You must be signed in to change notification settings - Fork 1
Change provider child relationship to many-to-many #224
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
aa19f7c
8f5e468
1a573a7
2ea3053
dd33066
cd11985
4f3c71b
68c981b
5b13d27
9b68601
557f41f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from . import db | ||
|
|
||
| child_providers = db.Table( | ||
| "child_providers", | ||
| db.metadata, | ||
| db.Column("child_id", db.ForeignKey("children.id")), | ||
| db.Column("providers_id", db.ForeignKey("providers.id")), | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ def get_all_intakes(): | |
| just_children = child_service.get_children_by_intake_id(intake.id) | ||
| new_children = [] | ||
| for child in just_children: | ||
| providers = provider_service.get_providers_by_child_id(child.id) | ||
| providers = provider_service.get_providers_by_child(child.id) | ||
| child_info = { | ||
| "name": f"{child.first_name} {child.last_name}", | ||
| "dateOfBirth": child.date_of_birth, | ||
|
|
@@ -325,7 +325,10 @@ def run_undos(): | |
| run_undos() | ||
| return jsonify(error), 400 | ||
|
|
||
| children_providers = {} | ||
| all_providers = [] | ||
| children = request.json["children"] | ||
| # children | ||
| for child in children: | ||
| # daytime contact | ||
| daytimeContact = child["daytimeContact"] | ||
|
|
@@ -369,29 +372,15 @@ def run_undos(): | |
| return jsonify(error), 400 | ||
|
|
||
| # provider | ||
| providers = child["provider"] | ||
| for provider in providers: | ||
| provider_obj = { | ||
| "name": provider["name"], | ||
| "file_number": provider["fileNumber"], | ||
| "primary_phone_number": provider["primaryPhoneNumber"], | ||
| "secondary_phone_number": provider["secondaryPhoneNumber"], | ||
| "email": provider["email"], | ||
| "address": provider["address"], | ||
| "relationship_to_child": provider["relationshipToChild"], | ||
| "additional_contact_notes": provider["additionalContactNotes"], | ||
| "child_id": child_response.id, | ||
| } | ||
| try: | ||
| provider_response = provider_service.create_new_provider( | ||
| CreateProviderDTO(**provider_obj) | ||
| ) | ||
| undos.append( | ||
| (provider_service, "delete_provider", provider_response.id) | ||
| ) | ||
| except Exception as error: | ||
| run_undos() | ||
| return jsonify(error), 400 | ||
| providers_by_child = child["provider"] | ||
| for provider in providers_by_child: | ||
| if provider.providerId in children_providers: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| children_providers[provider["providerId"]].append(child_response.id) | ||
| else: | ||
| children_providers[provider["providerId"]] = [child_response.id] | ||
|
|
||
| if not any(x.providerId == provider.providerId for x in all_providers): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| all_providers.append(provider) | ||
|
|
||
| # concerns | ||
| concerns = child["childInfo"]["concerns"] | ||
|
|
@@ -415,6 +404,30 @@ def run_undos(): | |
| run_undos() | ||
| return jsonify(error), 400 | ||
|
|
||
| # create providers | ||
| for provider in all_providers: | ||
| provider_obj = { | ||
| "name": provider["name"], | ||
| "intake_id": new_intake.id, | ||
| "file_number": provider["fileNumber"], | ||
| "primary_phone_number": provider["primaryPhoneNumber"], | ||
| "secondary_phone_number": provider["secondaryPhoneNumber"], | ||
| "email": provider["email"], | ||
| "address": provider["address"], | ||
| "relationship_to_child": provider["relationshipToChild"], | ||
| "additional_contact_notes": provider["additionalContactNotes"], | ||
| } | ||
|
|
||
| try: | ||
| provider_response = provider_service.create_new_provider( | ||
| CreateProviderDTO(**provider_obj), | ||
| children_providers[provider["providerId"]], | ||
|
Comment on lines
+422
to
+424
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, just looked into this—it seems like the provider_response = provider_service.create_new_provider(
CreateProviderDTO(**provider_obj)
)you're going to have to change some of your |
||
| ) | ||
| undos.append((provider_service, "delete_provider", provider_response.id)) | ||
| except Exception as error: | ||
| run_undos() | ||
| return jsonify(error), 400 | ||
Check warningCode scanning / CodeQL Information exposure through an exception
[Stack trace information](1) flows to this location and may be exposed to an external user.
|
||
|
|
||
| return jsonify(new_intake.__dict__), 201 | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from ...models import db | ||
| from ...models.child import Child | ||
| from ...models.provider import Provider | ||
| from ...resources.child_dto import ChildDTO | ||
| from ...resources.provider_dto import CreateProviderDTO, ProviderDTO | ||
| from ..interfaces.provider_service import IProviderService | ||
|
|
||
|
|
@@ -20,7 +21,7 @@ def get_all_providers(self): | |
| self.logger.error(str(error)) | ||
| raise error | ||
|
|
||
| def create_new_provider(self, provider): | ||
| def create_new_provider(self, provider, children_ids=[]): | ||
| try: | ||
| if not provider: | ||
| raise Exception( | ||
|
|
@@ -33,6 +34,11 @@ def create_new_provider(self, provider): | |
| raise Exception(error_list) | ||
|
|
||
| new_provider_entry = Provider(**provider.__dict__) | ||
|
|
||
| for child_id in children_ids: | ||
| child = Child.query.filter_by(id=child_id) | ||
| new_provider_entry.children.append(child) | ||
|
|
||
| db.session.add(new_provider_entry) | ||
| db.session.commit() | ||
|
|
||
|
|
@@ -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): | ||
|
||
| try: | ||
| providers = Provider.query.filter_by(child_id=child_id) | ||
| providers_dto = [ | ||
| ProviderDTO(**provider.to_dict()) for provider in providers | ||
| provider = Provider.query.filter_by(id=provider_id).first() | ||
| children_dto = [ChildDTO(**child.to_dict()) for child in provider.children] | ||
| return children_dto | ||
| except Exception as error: | ||
| self.logger.error(str(error)) | ||
| raise error | ||
|
|
||
| def get_providers_by_child(self, child_id): | ||
| try: | ||
| child = Child.query.filter_by(id=child_id).first() | ||
| provider_dto = [ | ||
| ProviderDTO(**provider.to_dict()) for provider in child.providers | ||
| ] | ||
| return providers_dto | ||
| return provider_dto | ||
| except Exception as error: | ||
| self.logger.error(str(error)) | ||
| raise error | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """change child-provider relationship | ||
|
|
||
| Revision ID: 05393a9f6f23 | ||
| Revises: 2e3a95429cdf | ||
| Create Date: 2023-11-11 18:52:37.274933 | ||
|
|
||
| """ | ||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "05393a9f6f23" | ||
| down_revision = "2e3a95429cdf" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table( | ||
| "child_providers", | ||
| sa.Column("child_id", sa.Integer(), nullable=True), | ||
| sa.Column("providers_id", sa.Integer(), nullable=True), | ||
| sa.ForeignKeyConstraint( | ||
| ["child_id"], | ||
| ["children.id"], | ||
| ), | ||
| sa.ForeignKeyConstraint( | ||
| ["providers_id"], | ||
| ["providers.id"], | ||
| ), | ||
| ) | ||
| op.add_column("providers", sa.Column("intake_id", sa.Integer(), nullable=True)) | ||
| op.drop_constraint("providers_child_id_fkey", "providers", type_="foreignkey") | ||
| op.create_foreign_key(None, "providers", "intakes", ["intake_id"], ["id"]) | ||
| op.drop_column("providers", "child_id") | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.add_column( | ||
| "providers", | ||
| sa.Column("child_id", sa.INTEGER(), autoincrement=False, nullable=False), | ||
| ) | ||
| op.drop_constraint(None, "providers", type_="foreignkey") | ||
| op.create_foreign_key( | ||
| "providers_child_id_fkey", "providers", "children", ["child_id"], ["id"] | ||
| ) | ||
| op.drop_column("providers", "intake_id") | ||
| op.drop_table("child_providers") | ||
| # ### end Alembic commands ### |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,15 +111,6 @@ def insert_test_data(): | |
| insert_values(db, "other_permitted_individuals", ("name", "phone_number", "relationship_to_child", "notes", "intake_id"), value) | ||
|
|
||
|
|
||
| # Providers | ||
| values = [ | ||
| ('Provider One', '111', '555-555-5555', '777-777-7777', '[email protected]', 'address', 'KINSHIP_PROVIDER', 'NULL', 1), | ||
| ('Provider Two', '222', '777-777-7777', '555-555-5555', '[email protected]', 'address', 'KINSHIP_PROVIDER', 'NULL', 1) | ||
| ] | ||
|
|
||
| for value in values: | ||
| insert_values(db, "providers", ("name", "file_number", "primary_phone_number", "secondary_phone_number", "email", "address", "relationship_to_child", "additional_contact_notes", "child_id"), value) | ||
|
|
||
| # fmt: on | ||
|
|
||
| # fmt: off | ||
|
|
||
There was a problem hiding this comment.
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
providerobj within it has no fieldproviderId(see intake frontend<>backend for more info)There was a problem hiding this comment.
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.tsxand is defined across all components working with ProviderDetails