-
Notifications
You must be signed in to change notification settings - Fork 601
added a separately_billable to charge item def #3476
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
Open
praffq
wants to merge
8
commits into
develop
Choose a base branch
from
prafful/feat/added-separately_billable-flag-in-cif
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9ac352c
added a separately_billable to charge item def
praffq 4154e47
added logic to auto populate septratly billable field
praffq 51b13a2
Merge branch 'develop' into prafful/feat/added-separately_billable-fl…
praffq b0e98b1
fix migrations
praffq 2d4594b
typo
praffq e9db10d
Merge branch 'develop' into prafful/feat/added-separately_billable-fl…
praffq 7b6348d
Merge branch 'develop' into prafful/feat/added-separately_billable-fl…
praffq 8f4d27c
fix migrations
praffq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
care/emr/migrations/0061_chargeitemdefinition_separately_billable.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Django 6.0 on 2026-01-22 13:44 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('emr', '0060_chargeitemdefinition_tags_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='chargeitemdefinition', | ||
| name='separately_billable', | ||
| field=models.BooleanField(default=True), | ||
| ), | ||
| ] |
31 changes: 31 additions & 0 deletions
31
care/emr/migrations/0062_sync_seprately_billable_values.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from django.db import migrations | ||
|
|
||
|
|
||
| def sync_separately_billable(apps, schema_editor): | ||
| ChargeItemDefinition = apps.get_model("emr", "ChargeItemDefinition") | ||
| Product = apps.get_model("emr", "Product") | ||
| Schedule = apps.get_model("emr", "Schedule") | ||
| ActivityDefinition = apps.get_model("emr", "ActivityDefinition") | ||
|
|
||
| for charge_item_def in ChargeItemDefinition.objects.all(): | ||
| is_linked = ( | ||
| Product.objects.filter(charge_item_definition_id=charge_item_def.id).exists() | ||
| or Schedule.objects.filter(charge_item_definition_id=charge_item_def.id).exists() | ||
| or Schedule.objects.filter(revisit_charge_item_definition_id=charge_item_def.id).exists() | ||
| or ActivityDefinition.objects.filter(charge_item_definitions__contains=[charge_item_def.id]).exists() | ||
| ) | ||
|
|
||
| if is_linked and charge_item_def.separately_billable: | ||
| charge_item_def.separately_billable = False | ||
| charge_item_def.save(update_fields=["separately_billable"]) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("emr", "0061_chargeitemdefinition_separately_billable"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(sync_separately_billable), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from .charge_item_def import * # noqa F403 | ||
| from .patient import * # noqa F403 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from .activity_definition import * # noqa F403 | ||
| from .product import * # noqa F403 | ||
| from .schedule import * # noqa F403 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| from django.db.models.signals import post_save, pre_save | ||
| from django.dispatch import receiver | ||
|
|
||
| from care.emr.models.activity_definition import ActivityDefinition | ||
| from care.emr.utils.charge_item_definition import ( | ||
| recalculate_separately_billable, | ||
| set_separately_billable_false, | ||
| ) | ||
|
|
||
| _OLD_CHARGE_ITEM_DEFS_IDS = "_old_charge_item_definitions" | ||
| _OLD_DELETED = "_old_deleted" | ||
|
|
||
|
|
||
| @receiver(pre_save, sender=ActivityDefinition) | ||
| def capture_old_charge_item_defs_activity(sender, instance, **kwargs): | ||
| if instance.id: | ||
| old_instance = ActivityDefinition.objects.get(id=instance.id) | ||
| setattr( | ||
| instance, | ||
| _OLD_CHARGE_ITEM_DEFS_IDS, | ||
| list(old_instance.charge_item_definitions or []), | ||
| ) | ||
| setattr(instance, _OLD_DELETED, old_instance.deleted) | ||
| else: | ||
| setattr(instance, _OLD_CHARGE_ITEM_DEFS_IDS, []) | ||
| setattr(instance, _OLD_DELETED, False) | ||
|
|
||
|
|
||
| @receiver(post_save, sender=ActivityDefinition) | ||
| def update_separately_billable_activity(sender, instance, created, **kwargs): | ||
| old_ids = set(getattr(instance, _OLD_CHARGE_ITEM_DEFS_IDS, []) or []) | ||
| new_ids = set(instance.charge_item_definitions or []) | ||
| old_deleted = getattr(instance, _OLD_DELETED, False) | ||
|
|
||
| is_soft_deleted = not old_deleted and instance.deleted | ||
|
|
||
| if is_soft_deleted: | ||
| for charge_item_def_id in new_ids: | ||
| recalculate_separately_billable(charge_item_def_id) | ||
| return | ||
|
|
||
| added_ids = new_ids - old_ids | ||
| for charge_item_def_id in added_ids: | ||
| if not instance.deleted: | ||
| set_separately_billable_false(charge_item_def_id) | ||
|
|
||
| removed_ids = old_ids - new_ids | ||
| for charge_item_def_id in removed_ids: | ||
| recalculate_separately_billable(charge_item_def_id) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from django.db.models.signals import post_save, pre_save | ||
| from django.dispatch import receiver | ||
|
|
||
| from care.emr.models.product import Product | ||
| from care.emr.utils.charge_item_definition import ( | ||
| recalculate_separately_billable, | ||
| set_separately_billable_false, | ||
| ) | ||
|
|
||
| _OLD_CHARGE_ITEM_DEF_ID = "_old_charge_item_definition_id" | ||
| _OLD_DELETED = "_old_deleted" | ||
|
|
||
|
|
||
| @receiver(pre_save, sender=Product) | ||
| def capture_old_charge_item_def_product(sender, instance, **kwargs): | ||
| if instance.id: | ||
| old_instance = Product.objects.get(id=instance.id) | ||
| setattr( | ||
| instance, _OLD_CHARGE_ITEM_DEF_ID, old_instance.charge_item_definition_id | ||
| ) | ||
| setattr(instance, _OLD_DELETED, old_instance.deleted) | ||
| else: | ||
| setattr(instance, _OLD_CHARGE_ITEM_DEF_ID, None) | ||
| setattr(instance, _OLD_DELETED, False) | ||
|
|
||
|
|
||
| @receiver(post_save, sender=Product) | ||
| def update_separately_billable_product(sender, instance, created, **kwargs): | ||
| old_charge_item_def_id = getattr(instance, _OLD_CHARGE_ITEM_DEF_ID, None) | ||
| new_charge_item_def_id = instance.charge_item_definition_id | ||
| old_deleted = getattr(instance, _OLD_DELETED, False) | ||
|
|
||
| is_soft_deleted = not old_deleted and instance.deleted | ||
|
|
||
| if is_soft_deleted and new_charge_item_def_id: | ||
| recalculate_separately_billable(new_charge_item_def_id) | ||
| return | ||
|
|
||
| if old_charge_item_def_id and old_charge_item_def_id != new_charge_item_def_id: | ||
| recalculate_separately_billable(old_charge_item_def_id) | ||
|
|
||
| if new_charge_item_def_id and not instance.deleted: | ||
| set_separately_billable_false(new_charge_item_def_id) | ||
|
praffq marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| from django.db.models.signals import post_save, pre_save | ||
| from django.dispatch import receiver | ||
|
|
||
| from care.emr.models.scheduling.schedule import Schedule | ||
| from care.emr.utils.charge_item_definition import ( | ||
| recalculate_separately_billable, | ||
| set_separately_billable_false, | ||
| ) | ||
|
|
||
| _OLD_CHARGE_ITEM_DEF_ID = "_old_charge_item_definition_id" | ||
| _OLD_REVISIT_CHARGE_ITEM_DEF_ID = "_old_revisit_charge_item_definition_id" | ||
| _OLD_DELETED = "_old_deleted" | ||
|
|
||
|
|
||
| @receiver(pre_save, sender=Schedule) | ||
| def capture_old_charge_item_def_schedule(sender, instance, **kwargs): | ||
| if instance.id: | ||
| old_instance = Schedule.objects.get(id=instance.id) | ||
| setattr( | ||
| instance, _OLD_CHARGE_ITEM_DEF_ID, old_instance.charge_item_definition_id | ||
| ) | ||
| setattr( | ||
| instance, | ||
| _OLD_REVISIT_CHARGE_ITEM_DEF_ID, | ||
| old_instance.revisit_charge_item_definition_id, | ||
| ) | ||
| setattr(instance, _OLD_DELETED, old_instance.deleted) | ||
| else: | ||
| setattr(instance, _OLD_CHARGE_ITEM_DEF_ID, None) | ||
| setattr(instance, _OLD_REVISIT_CHARGE_ITEM_DEF_ID, None) | ||
| setattr(instance, _OLD_DELETED, False) | ||
|
|
||
|
|
||
| @receiver(post_save, sender=Schedule) | ||
| def update_separately_billable_schedule(sender, instance, created, **kwargs): | ||
| old_charge_item_def_id = getattr(instance, _OLD_CHARGE_ITEM_DEF_ID, None) | ||
| new_charge_item_def_id = instance.charge_item_definition_id | ||
| old_revisit_id = getattr(instance, _OLD_REVISIT_CHARGE_ITEM_DEF_ID, None) | ||
| new_revisit_id = instance.revisit_charge_item_definition_id | ||
| old_deleted = getattr(instance, _OLD_DELETED, False) | ||
|
|
||
| is_soft_deleted = not old_deleted and instance.deleted | ||
|
|
||
| if is_soft_deleted: | ||
| if new_charge_item_def_id: | ||
| recalculate_separately_billable(new_charge_item_def_id) | ||
| if new_revisit_id: | ||
| recalculate_separately_billable(new_revisit_id) | ||
| return | ||
|
|
||
| if old_charge_item_def_id and old_charge_item_def_id != new_charge_item_def_id: | ||
| recalculate_separately_billable(old_charge_item_def_id) | ||
|
|
||
| if new_charge_item_def_id and not instance.deleted: | ||
| set_separately_billable_false(new_charge_item_def_id) | ||
|
|
||
| if old_revisit_id and old_revisit_id != new_revisit_id: | ||
| recalculate_separately_billable(old_revisit_id) | ||
|
|
||
| if new_revisit_id and not instance.deleted: | ||
| set_separately_billable_false(new_revisit_id) | ||
|
praffq marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.