Skip to content

Commit

Permalink
Add claim sub services (#168)
Browse files Browse the repository at this point in the history
* ajout de sous-service claim et sous-item claim

* justement GqlQueries + Models

* ajustement Utils pour calcul montant cote serveur

* correction enregistrement des services simple dans le claim

* ajustement claim utils pour gestion de l'update

* ajustement validations frequency Check

* Ajustement graphQL pour enregistrement review

* Update openmis-module-test.yml

* fix gql_mutations.py remove print

* ajustement utils

* Fix concurrent migrations with OP-1199

* Ajustement prix Claimservice ref#26349

* Check concordance des qte a la validation ref#26249

* Ajustement

* Rajout du check sur les items ref#26249

* Ajsutement

* fix update claim

* Correction vérification ref#26349

* Ajustement migration

* Ajustement migration en rapport au develop

* Ajustement mutation sousservices et sousitems ref#26470

* Ajustement update price_ajusted

* Add tests

* ajustements

* Nouveu test unitaire concernant les produits avec packatype differents ref 26800

* Ajustement nan

* Ajustement

* database config

* Ajustement

* Ajustement config

* Ajustmenet variables

* Ajustement test

* Ajutement

* tweaks

* standard names

* fixing nepal migration

* Update claim/migrations/0030_claimattachmenttype_claimattachment_predefined_type.py

* fix: remove empty line

* fix migrations

* Rename 0030_claimattachmenttype_claimattachment_predefined_type.py to 0028_claimattachmenttype_claimattachment_predefined_type.py

* Update 0030_merge_20240318_1324.py

key error

* Removed self replaces

---------

Co-authored-by: maxime ngoe <maxime.ngoe@gmail.com>
Co-authored-by: Eric Darchis <edarchis@bluesquarehub.com>
Co-authored-by: Eric Darchis <darchis@pobox.com>
Co-authored-by: Tiah Kevel <k.choumene@cloudfacile.com>
Co-authored-by: keveltiah <53906829+kevel-dev@users.noreply.github.com>
Co-authored-by: kevel <keveltiah@gmail.com>
Co-authored-by: olewandowski1 <olewandowski@soldevelo.com>
Co-authored-by: Kamil Malinowski <kmalinowski@soldevelo.com>
  • Loading branch information
9 people authored Mar 26, 2024
1 parent 45bae42 commit af79efe
Show file tree
Hide file tree
Showing 20 changed files with 615 additions and 33 deletions.
4 changes: 3 additions & 1 deletion claim/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"autogenerate_func": 'claim.utils.autogenerate_nepali_claim_code',
"additional_diagnosis_number_allowed": 4,
"claim_max_restore": None,
"allowed_domains_attachments": []
"allowed_domains_attachments": [],
"native_code_for_services": True
}


Expand Down Expand Up @@ -63,6 +64,7 @@ class ClaimConfig(AppConfig):
claim_attachments_root_path = None
claim_uspUpdateClaimFromPhone_intermediate_sets = None
autogenerated_claim_code_config = {}
native_code_for_services = True
# cannot be set in the model, since migration has to be able to handle all implementations
max_claim_length = None
claim_max_restore = None
Expand Down
70 changes: 69 additions & 1 deletion claim/gql_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
from graphene import InputObjectType
from claim.gql_queries import ClaimGQLType
from claim.models import Claim, Feedback, FeedbackPrompt, ClaimDetail, ClaimItem, ClaimService, ClaimAttachment, \
ClaimDedRem, GeneralClaimAttachmentType, ClaimAttachmentType
ClaimDedRem, GeneralClaimAttachmentType, ClaimAttachmentType,ClaimServiceService
from claim.attachment_strategies import *

from product.models import ProductItemOrService
from medical.models import Item, Service

from claim.utils import process_items_relations, process_services_relations
from claim.services import validate_claim_data as service_validate_claim_data, \
Expand Down Expand Up @@ -78,6 +79,26 @@ class ClaimItemInputType(InputObjectType):
exceed_ceiling_amount_category = graphene.Decimal(
max_digits=18, decimal_places=2, required=False)

class ClaimSubServiceInputType(InputObjectType):
id = graphene.Int(required=False)
sub_service_code = graphene.String(required=True)
qty_provided = graphene.Decimal(
max_digits=18, decimal_places=2, required=False)
qty_asked = graphene.Decimal(
max_digits=18, decimal_places=2, required=False)
price_asked = graphene.Decimal(
max_digits=18, decimal_places=2, required=False)


class ClaimSubItemInputType(InputObjectType):
id = graphene.Int(required=False)
sub_item_code = graphene.String(required=True)
qty_provided = graphene.Decimal(
max_digits=18, decimal_places=2, required=False)
qty_asked = graphene.Decimal(
max_digits=18, decimal_places=2, required=False)
price_asked = graphene.Decimal(
max_digits=18, decimal_places=2, required=False)

class ClaimServiceInputType(InputObjectType):
id = graphene.Int(required=False)
Expand Down Expand Up @@ -117,6 +138,8 @@ class ClaimServiceInputType(InputObjectType):
price_origin = graphene.String(max_length=1, required=False)
exceed_ceiling_amount_category = graphene.Decimal(
max_digits=18, decimal_places=2, required=False)
service_item_set = graphene.List(ClaimSubItemInputType, required=False)
service_service_set = graphene.List(ClaimSubServiceInputType, required=False)


class FeedbackInputType(InputObjectType):
Expand Down Expand Up @@ -242,6 +265,7 @@ class ClaimInputType(OpenIMISMutation.Input):
services = graphene.List(ClaimServiceInputType, required=False)



class CreateClaimInputType(ClaimInputType):
attachments = graphene.List(ClaimAttachmentInputType, required=False)

Expand Down Expand Up @@ -816,12 +840,55 @@ def async_mutate(cls, user, **data):
if item['status'] == ClaimItem.STATUS_PASSED:
all_rejected = False
services = data.pop('services') if 'services' in data else []
claimed = 0
claim_service_elements = []
for service in services:
service_id = service.pop('id')
service_linked = service.pop('service_service_set', [])
logger.debug("service_linked ", service_linked)
service_service_set = service.pop('service_service_set', [])
logger.debug("service_service_set ", service_service_set)
claim.services.filter(id=service_id).update(**service)
if ClaimConfig.native_code_for_services == False:
for claim_service_service in service_service_set:
claim_service_code = claim_service_service.pop('subServiceCode')
claim_service = claim.services.filter(id=service_id).first()
if claim_service:
service_element = Service.objects.filter(*filter_validity(), code=claim_service_code).first()
if service_element:
claim_service_to_update = claim_service.services.filter(service=service_element.id)
logger.debug("claim_service_to_update ", claim_service_to_update)
if claim_service_to_update:
qty_asked = claim_service_service.pop('qty_asked', 0)
price_asked = claim_service_service.pop('price_asked', 0)
claim_service_service['qty_displayed'] = qty_asked
price = qty_asked * price_asked
claimed += price
claim_service_to_update.update(**claim_service_service)
claim_service_elements.append(claim_service)
for claim_service_item in service_linked:
claim_item_code = claim_service_item.pop('subItemCode')
claim_service = claim.services.filter(id=service_id).first()
if claim_service:
item_element = Item.objects.filter(*filter_validity(), code=claim_item_code).first()
if item_element:
claim_item_to_update = claim_service.items.filter(item=item_element.id)
logger.debug("claim_item_to_update ", claim_item_to_update)
if claim_item_to_update:
qty_asked = claim_service_item.pop('qty_asked', 0)
price_asked = claim_service_item.pop('price_asked', 0)
claim_service_item['qty_displayed'] = qty_asked
price = qty_asked * price_asked
claimed += price
claim_item_to_update.update(**claim_service_item)

if service['status'] == ClaimService.STATUS_PASSED:
all_rejected = False
claim.approved = approved_amount(claim)
if ClaimConfig.native_code_for_services == False:
claim.claimed = claimed
for claimservice in claim_service_elements:
setattr(claimservice, 'price_adjusted', claimed)
claim.audit_user_id_review = user.id_for_audit
if all_rejected:
claim.status = Claim.STATUS_REJECTED
Expand Down Expand Up @@ -869,6 +936,7 @@ def async_mutate(cls, user, **data):
for claim in claims:
remaining_uuid.remove(claim.uuid.upper())


logger.debug("ProcessClaimsMutation: processing %s", claim.uuid)
c_errors = []

Expand Down
18 changes: 17 additions & 1 deletion claim/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from claim_batch.schema import BatchRunGQLType
from .apps import ClaimConfig
from claim.models import (ClaimDedRem, Claim, ClaimAdmin, Feedback, ClaimItem, ClaimService, ClaimAttachment,
ClaimAttachmentType)
ClaimAttachmentType, ClaimServiceService, ClaimServiceItem)
from django.utils.translation import gettext as _
from django.core.exceptions import PermissionDenied

Expand Down Expand Up @@ -190,3 +190,19 @@ class ClaimServiceGQLType(DjangoObjectType):

class Meta:
model = ClaimService

class ClaimServiceServiceGQLType(DjangoObjectType):
"""
Contains the Claim services within a specific Claim
"""

class Meta:
model = ClaimServiceService

class ClaimServiceItemGQLType(DjangoObjectType):
"""
Contains the Claim services within a specific Claim
"""

class Meta:
model = ClaimServiceItem
3 changes: 2 additions & 1 deletion claim/management/commands/generateclaimadmins.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def handle(self, *args, **options):
"phone": "+" + fake.msisdn(),
"health_facility_id": hf})
if verbose:
print(admin_num, "created claim admin", claim_admin, "for HF", hf, "with code", claim_admin.code)
logger.debug(f"{admin_num} created claim admin {claim_admin} for HF {hf} \
with code {claim_admin.code}")

def get_random_hf(self):
if not self.hfs:
Expand Down
6 changes: 3 additions & 3 deletions claim/management/commands/generateclaims.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def handle(self, *args, **options):
"admin_id": claim_admin,
"health_facility_id": hf})
if verbose:
print(claim_num, "created claim", claim, "for insuree", insuree, "with code", claim.code)
logger.debug(f"{claim_num} created claim {claim} for insuree {insuree} with code {claim.code}")
for svc_num in range(1, nb_services + 1):
service = self.get_random_service()
claim_service = create_test_claimservice(claim, custom_props={
Expand All @@ -51,7 +51,7 @@ def handle(self, *args, **options):
"price_asked": random.randint(1, 1000),
})
if verbose:
print(claim_num, svc_num, "Created claim service", claim_service, "for service", service)
logger.debug(f"{claim_num} {svc_num} Created claim service {claim_service} for service {service}")
for item_num in range(1, nb_items + 1):
item = self.get_random_item()
claim_item = create_test_claimitem(claim, "D", custom_props=
Expand All @@ -61,7 +61,7 @@ def handle(self, *args, **options):
"price_asked": random.randint(1, 1000),
})
if verbose:
print(claim_num, item_num, "Created claim item", claim_item, "for item", item)
logger.debug(f"{claim_num} {item_num} Created claim item {claim_item} for item {item}")

def get_random_insuree(self):
if not self.insurees:
Expand Down
5 changes: 3 additions & 2 deletions claim/migrations/0019_auto_20230615_1055.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.db import migrations, models
import django.db.models.deletion
from claim.models import Claim


class Migration(migrations.Migration):
Expand All @@ -13,15 +14,15 @@ class Migration(migrations.Migration):

operations = []
try:
Claim.objects.filter(pk<10).aggregate(sum=models.Count('refer_from'))
Claim.objects.filter(pk__lt=10).aggregate(sum=models.Count('refer_from'))
except:
operations.append(migrations.AddField(
model_name='claim',
name='refer_from',
field=models.ForeignKey(blank=True, db_column='ReferFrom', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='referFromHF', to='location.healthfacility'),
))
try:
Claim.objects.filter(pk<10).aggregate(sum=models.Count('refer_to'))
Claim.objects.filter(pk__lt=10).aggregate(sum=models.Count('refer_to'))
except:
operations.append(migrations.AddField(
model_name='claim',
Expand Down
4 changes: 2 additions & 2 deletions claim/migrations/0021_auto_20230818_0914.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 3.2.16 on 2023-08-18 09:14

from django.db import migrations, models

from claim.models import Claim

class Migration(migrations.Migration):

Expand All @@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations = []

try:
Claim.objects.filter(pk<10).aggregate(sum=models.Count('care_type'))
Claim.objects.filter(pk__lt=10).aggregate(sum=models.Count('care_type'))
except:
operations = [
migrations.AddField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def insert_default_type(apps, schema_editor):
class Migration(migrations.Migration):

dependencies = [
('claim', '0027_auto_20240203_2339'),
('claim', '0029_rename_pcpdate_claimserviceitem_created_date_and_more'),
]

operations = [
Expand Down
47 changes: 47 additions & 0 deletions claim/migrations/0028_claimserviceitem_claimserviceservice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 3.0.14 on 2022-08-22 18:48

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('claim', '0027_auto_20240203_2339'),
]

operations = [
migrations.CreateModel(
name='ClaimServiceService',
fields=[
('idCss', models.AutoField(db_column='idCss', primary_key=True, serialize=False)),
('qty_provided', models.IntegerField(blank=True, db_column='qty_provided', null=True)),
('qty_displayed', models.IntegerField(blank=True, db_column='qty_displayed', null=True)),
('pcpDate', models.DateTimeField(blank=True, db_column='created_date', default=django.utils.timezone.now, null=True)),
('price_asked', models.DecimalField(blank=True, db_column='price', decimal_places=2, max_digits=18, null=True)),
('claimlinkedService', models.ForeignKey(db_column='claimlinkedService', on_delete=django.db.models.deletion.DO_NOTHING, related_name='claimlinkedService', to='claim.ClaimService')),
('service', models.ForeignKey(db_column='ServiceId', on_delete=django.db.models.deletion.DO_NOTHING, related_name='claimServices', to='medical.Service')),
],
options={
'db_table': 'tblClaimServicesService',
'managed': True,
},
),
migrations.CreateModel(
name='ClaimServiceItem',
fields=[
('idCsi', models.AutoField(db_column='idCsi', primary_key=True, serialize=False)),
('qty_provided', models.IntegerField(blank=True, db_column='qty_provided', null=True)),
('qty_displayed', models.IntegerField(blank=True, db_column='qty_displayed', null=True)),
('pcpDate', models.DateTimeField(blank=True, db_column='created_date', default=django.utils.timezone.now, null=True)),
('price_asked', models.DecimalField(blank=True, db_column='price', decimal_places=2, max_digits=18, null=True)),
('claimlinkedItem', models.ForeignKey(db_column='ClaimServiceID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='claimlinkedItem', to='claim.ClaimService')),
('item', models.ForeignKey(db_column='ItemID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='claimItems', to='medical.Item')),
],
options={
'db_table': 'tblClaimServicesItems',
'managed': True,
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Generated by Django 4.2.10 on 2024-03-01 08:43

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('claim', '0028_claimserviceitem_claimserviceservice'),
]

operations = [
migrations.RenameField(
model_name='claimserviceitem',
old_name='pcpDate',
new_name='created_date',
),
migrations.RenameField(
model_name='claimserviceitem',
old_name='idCsi',
new_name='id',
),
migrations.RenameField(
model_name='claimserviceservice',
old_name='pcpDate',
new_name='created_date',
),
migrations.RenameField(
model_name='claimserviceservice',
old_name='idCss',
new_name='id',
),

migrations.RenameField(
model_name='claimserviceservice',
old_name='claimlinkedService',
new_name='claim_service',
),
migrations.RenameField(
model_name='claimserviceitem',
old_name='claimlinkedItem',
new_name='claim_service',
),

migrations.AlterField(
model_name='claimserviceitem',
name='claim_service',
field=models.ForeignKey(db_column='ClaimServiceID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='items', to='claim.claimservice'),
),
migrations.AlterField(
model_name='claimserviceservice',
name='claim_service',
field=models.ForeignKey(db_column='claimServiceID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='services', to='claim.claimservice'),
),

migrations.AlterField(
model_name='claimserviceitem',
name='item',
field=models.ForeignKey(db_column='ItemID', on_delete=django.db.models.deletion.DO_NOTHING, related_name='service_items', to='medical.item'),
),
migrations.AlterField(
model_name='claimserviceservice',
name='service',
field=models.ForeignKey(db_column='ServiceId', on_delete=django.db.models.deletion.DO_NOTHING, related_name='service_services', to='medical.service'),
),
]
14 changes: 14 additions & 0 deletions claim/migrations/0030_merge_20240318_1324.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 4.2.10 on 2024-03-18 13:24

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('claim', '0028_claimattachmenttype_claimattachment_predefined_type'),
('claim', '0029_rename_pcpdate_claimserviceitem_created_date_and_more'),
]

operations = [
]
Loading

0 comments on commit af79efe

Please sign in to comment.