Skip to content

Commit

Permalink
Merge pull request #53 from openimis/develop
Browse files Browse the repository at this point in the history
MERGING RELEASE branches
  • Loading branch information
delcroip authored May 16, 2023
2 parents 72a1368 + 33f455a commit bfd3373
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 10 deletions.
1 change: 1 addition & 0 deletions policy/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Meta:
balance = graphene.Float()
validity_from = graphene.Date()
validity_to = graphene.Date()
max_installments = graphene.Int()


class PolicyByFamilyOrInsureeConnection(ExtendedRelayConnection):
Expand Down
69 changes: 69 additions & 0 deletions policy/migrations/0005_add_foreign_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Generated by Django 3.2.18 on 2023-05-12 08:48

import core.fields
import datetime
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

dependencies = [
('insuree', '0013_auto_20211103_1023'),
('core', '0019_extended_field'),
('product', '0006_insert_ceiling_type'),
('policy', '0004_add_medical_oficer_reading_rights'),
]

operations = [
migrations.RemoveField(
model_name='policy',
name='row_id',
),
migrations.AddField(
model_name='policy',
name='family',
field=models.ForeignKey(db_column='FamilyID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='policies', to='insuree.family'),
),
migrations.AddField(
model_name='policy',
name='officer',
field=models.ForeignKey(blank=True, db_column='OfficerID', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='policies', to='core.officer'),
),
migrations.AddField(
model_name='policy',
name='product',
field=models.ForeignKey(db_column='ProdID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='policies', to='product.product'),
),
migrations.AddField(
model_name='policy',
name='uuid',
field=models.CharField(db_column='PolicyUUID', default=uuid.uuid4, max_length=36, unique=True),
),
migrations.AddField(
model_name='policyrenewal',
name='insuree',
field=models.ForeignKey(db_column='InsureeID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='policy_renewals', to='insuree.insuree'),
),
migrations.AddField(
model_name='policyrenewal',
name='new_officer',
field=models.ForeignKey(blank=True, db_column='NewOfficerID', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='policy_renewals', to='core.officer'),
),
migrations.AddField(
model_name='policyrenewal',
name='new_product',
field=models.ForeignKey(db_column='NewProdID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='policy_renewals', to='product.product'),
),
migrations.AddField(
model_name='policyrenewal',
name='policy',
field=models.ForeignKey(db_column='PolicyID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='policy_renewals', to='policy.policy'),
),
migrations.AlterField(
model_name='policy',
name='validity_from',
field=core.fields.DateTimeField(db_column='ValidityFrom', default=datetime.datetime.now),
),
]
21 changes: 21 additions & 0 deletions policy/migrations/0006_set_model_managed_to_true.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.18 on 2023-05-12 11:34

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('policy', '0005_add_foreign_keys'),
]

operations = [
migrations.AlterModelOptions(
name='policy',
options={'managed': True},
),
migrations.AlterModelOptions(
name='policyrenewal',
options={'managed': True},
),
]
13 changes: 10 additions & 3 deletions policy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ class Policy(core_models.VersionedModel):
# row_id = models.BinaryField(db_column='RowID', blank=True, null=True)

def sum_premiums(self, photo=False):
return sum([p.amount for p in self.premiums.filter(is_photo_fee=photo).all()])
return sum(
[
p.amount
for p in self.premiums.filter(
is_photo_fee=photo, validity_to__isnull=True
).all()
]
)

def claim_ded_rems(self):
return self.claim_ded_rems
Expand All @@ -45,7 +52,7 @@ def can_add_insuree(self):
return self.family.members.filter(validity_to__isnull=True).count() < self.product.max_members

class Meta:
managed = False
managed = True
db_table = 'tblPolicy'

STATUS_IDLE = 1
Expand Down Expand Up @@ -99,7 +106,7 @@ class PolicyRenewal(core_models.VersionedModel):
audit_user_id = models.IntegerField(db_column='AuditCreateUser', null=True, blank=True)

class Meta:
managed = False
managed = True
db_table = 'tblPolicyRenewals'


Expand Down
3 changes: 2 additions & 1 deletion policy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def _to_policy_by_family_or_insuree_item(item):
ceiling_out_patient=item.ceiling_out_patient,
balance=item.balance,
validity_from=item.validity_from,
validity_to=item.validity_to
validity_to=item.validity_to,
max_installments=item.max_installments,
)

def resolve_policies_by_insuree(self, info, **kwargs):
Expand Down
16 changes: 10 additions & 6 deletions policy/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def __init__(self,
ceiling_out_patient,
balance,
validity_from,
validity_to
validity_to,
max_installments
):
self.policy_id = policy_id
self.policy_uuid = policy_uuid
Expand All @@ -165,6 +166,7 @@ def __init__(self,
self.balance = balance
self.validity_from = validity_from
self.validity_to = validity_to
self.max_installments = max_installments

def __eq__(self, other):
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
Expand Down Expand Up @@ -255,7 +257,8 @@ def _to_item(row):
ceiling_out_patient=ceiling_op,
balance=balance,
validity_from=row.validity_from,
validity_to=row.validity_to
validity_to=row.validity_to,
max_installments=row.product.max_installments,
)

def build_query(self, req):
Expand Down Expand Up @@ -577,11 +580,12 @@ def get_eligibility(self, insuree, item_or_service, model, req, now):
queryset_item_or_service = InsureePolicy.objects\
.filter(validity_to__isnull=True)\
.filter(policy__validity_to__isnull=True)\
.filter(policy__product__items__validity_to__isnull=True,
.filter(**{f"policy__product__{item_or_service}s__validity_to__isnull": True},
**{f"policy__product__{item_or_service}s__{item_or_service}_id": item_or_service_obj.id}) \
.filter(policy__status=Policy.STATUS_ACTIVE) \
.filter(insuree=insuree) \
.filter(Q(insuree__claim__validity_to__isnull=True)
.filter(Q(insuree__claim__validity_to__isnull=True,
**{f"insuree__claim__{item_or_service}s__{item_or_service}_id": item_or_service_obj.id})
& Q(**{f"insuree__claim__{item_or_service}s__validity_to__isnull": True})
& (Q(**{f"insuree__claim__{item_or_service}s__status": ClaimItem.STATUS_PASSED})
| Q(**{f"insuree__claim__{item_or_service}s__status__isnull": True}))
Expand All @@ -592,10 +596,10 @@ def get_eligibility(self, insuree, item_or_service, model, req, now):
waiting_period=F(waiting_period_field),
limit_no=F(limit_field)) \
.annotate(min_date=MonthsAdd(Coalesce(F(waiting_period_field), 0), "effective_date")) \
.annotate(count=Coalesce(
.annotate(count=Sum(Coalesce(
f"insuree__claim__{item_or_service}s__qty_approved",
f'insuree__claim__{item_or_service}s__qty_provided'
)) \
))) \
.annotate(left=F("limit_no") - F("count"))

min_date_qs = queryset_item_or_service.aggregate(
Expand Down

0 comments on commit bfd3373

Please sign in to comment.