Skip to content

Commit

Permalink
Merge pull request #5 from openimis/bugfix/claim_sampling
Browse files Browse the repository at this point in the history
Improved operations and display of the data
  • Loading branch information
dragos-dobre authored Jun 3, 2024
2 parents e9a6c8b + 5a17c72 commit 08cd8ef
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 20 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Module CI
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- main
- 'release/**'
- develop
- 'feature/**'
workflow_dispatch:
inputs:
comment:
description: Just a simple comment to know the purpose of the manual build
required: false

jobs:
call:
name: Default CI Flow
uses: openimis/openimis-be_py/.github/workflows/ci_module.yml@develop
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
SONAR_PROJECT_KEY: openimis_openimis-be-claim_sampling_py
SONAR_ORGANIZATION: openimis-1
SONAR_PROJECT_NAME: openimis-be-claim_sampling_py
SONAR_PROJECT_VERSION: 1.0
SONAR_SOURCES: claim_sampling
SONAR_EXCLUSIONS: "**/migrations/**,**/static/**,**/media/**,**/tests/**"

38 changes: 38 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: olegtarasov/get-tag@v2.1
id: tagName
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine jq
- name: update setup.py
run: |
echo "tag to use $GIT_TAG_NAME"
sed -i "s/version='.*'/version='$GIT_TAG_NAME'/g" setup.py
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{secrets.PYPI_TOKEN}}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
3 changes: 3 additions & 0 deletions claim_sampling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class ClaimSamplingBatch(HistoryModel):
computed_value = models.JSONField(db_column="ComputedValue", blank=True, null=True)
assigned_value = models.JSONField(db_column="AssignedValue", blank=True, null=True)

def __str__(self):
return f"Claim Sampling - {self.date_created}"


class ClaimSamplingBatchAssignment(HistoryModel):
class Status(models.TextChoices):
Expand Down
28 changes: 17 additions & 11 deletions claim_sampling/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.db import transaction
from django.utils.translation import gettext as _

from claim.services import set_claims_status, update_claims_dedrems
from claim.services import set_claims_status, update_claims_dedrems, validate_and_process_dedrem_claim
from claim_sampling.models import ClaimSamplingBatch, ClaimSamplingBatchAssignment
from core.services import BaseService
from core.signals import register_service_signal
Expand Down Expand Up @@ -70,15 +70,17 @@ def create(self, obj_data, task_group: TaskGroup = None):
batches = []
for next_claim in claim_batch_ids:
claim = Claim.objects.get(uuid=next_claim)
should_be_reviewed = is_selected_for_review.pop()
batches.append(ClaimSamplingBatchAssignment(
uuid=uuid.uuid4(),
claim=claim,
claim_batch=sampling_batch,
status=is_selected_for_review.pop(),
status=should_be_reviewed,
user_created=self.user,
user_updated=self.user
))
if claim.review_status in [Claim.REVIEW_NOT_SELECTED, Claim.REVIEW_BYPASSED]:
if claim.review_status in [Claim.REVIEW_IDLE, Claim.REVIEW_NOT_SELECTED, Claim.REVIEW_BYPASSED] \
and should_be_reviewed == ClaimSamplingBatchAssignment.Status.IDLE:
claim.review_status = Claim.REVIEW_SELECTED
claim.save_history()
claim.save()
Expand Down Expand Up @@ -129,16 +131,20 @@ def extrapolate_results(self, claim_sampling_id):

for approved, assignment in zip(split, claims_awaiting_validation):
if approved == Claim.STATUS_VALUATED:
result['approved'].append(assignment.claim.uuid)
result['approved'].append(assignment.claim)
else:
result['rejected'].append(assignment.claim.uuid)

set_claims_status(result['rejected'], 'status', Claim.STATUS_REJECTED)
errors = update_claims_dedrems(result['approved'], self.user)
errors += update_claims_dedrems(
sample_claim_assignments.filter(status=Claim.STATUS_CHECKED),
self.user
)
errors = []
for claim in result['approved']:
errors += validate_and_process_dedrem_claim(claim, self.user, True)
for claim in sample_claim_assignments.filter(status=Claim.STATUS_CHECKED):
errors += validate_and_process_dedrem_claim(
claim,
self.user,
True
)
return errors

def prepare_sampling_summary(self, claim_sampling_id):
Expand Down Expand Up @@ -183,8 +189,8 @@ def __choose_random_claims_for_review(self, total_elements: int, percentage: int
return result_list

def __choose_random_claims_for_deductible(self, total_elements: int, percentage: int):
valid = int((percentage/100.0) * total_elements)
rejected = total_elements - valid
rejected = int((percentage/100.0) * total_elements)
valid = total_elements - rejected

# Create the matching number of claims
result_list = [Claim.STATUS_VALUATED] * valid + \
Expand Down
2 changes: 1 addition & 1 deletion claim_sampling/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _resolve_task_any(_task: Task, _user: User):
claim_sampling_id = _task.data['data']['uuid']
claim_sampling_service = ClaimSamplingService(user=_user)

rejected_from_review, reviewed_delivered, total = claim_sampling_service\
rejected_from_review = claim_sampling_service\
.extrapolate_results(claim_sampling_id)


Expand Down
21 changes: 13 additions & 8 deletions claim_sampling/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_mutation_create_claim(
input: {
clientMutationId: "fdcc211f-7225-4f0e-8a66-11223344667d"
clientMutationLabel: "Create Claim Sampling Batch"
percentage: 20
percentage: 30
filters: "{\\"status\\":4, \\"dateFrom\\": \\"2024-01-13\\"}"
}
) {
Expand All @@ -173,13 +173,14 @@ def test_mutation_create_claim(
skip = list(attachments.filter(status=ClaimSamplingBatchAssignment.Status.SKIPPED))

# Creation
self.assertEqual(len(idle), 2)
self.assertEqual(len(skip), 8)
self.assertEqual(len(idle), 3)
self.assertEqual(len(skip), 7)
self.assertEqual(idle[0].claim.review_status, Claim.REVIEW_SELECTED)
self.assertEqual(idle[1].claim.review_status, Claim.REVIEW_SELECTED)
self.assertEqual(idle[2].claim.review_status, Claim.REVIEW_SELECTED)

# Summary
claim_1, claim_2 = idle[0].claim, idle[1].claim
claim_1, claim_2, claim_3 = idle[0].claim, idle[1].claim, idle[2].claim
claim_1.review_status = Claim.REVIEW_DELIVERED
claim_1.status = Claim.STATUS_PROCESSED
claim_1.save()
Expand All @@ -188,11 +189,15 @@ def test_mutation_create_claim(
claim_2.status = Claim.STATUS_REJECTED
claim_2.save()

claim_3.review_status = Claim.REVIEW_DELIVERED
claim_3.status = Claim.STATUS_REJECTED
claim_3.save()

service = ClaimSamplingService(self.admin_user)
rejected_from_review, reviewed_delivered, total = service.prepare_sampling_summary(claim_sampling.id)
self.assertEqual(rejected_from_review.count(), 1)
self.assertEqual(reviewed_delivered.count(), 2)
self.assertEqual(total, 2)
self.assertEqual(rejected_from_review.count(), 2)
self.assertEqual(reviewed_delivered.count(), 3)
self.assertEqual(total, 3)

# Extrapolation
service.extrapolate_results(claim_sampling.id)
Expand All @@ -201,7 +206,7 @@ def test_mutation_create_claim(
skip = [x.claim for x in attachments.filter(status=ClaimSamplingBatchAssignment.Status.SKIPPED)]
accepted = [x for x in skip if x.status in [Claim.STATUS_PROCESSED, Claim.STATUS_VALUATED]]
rejected = [x for x in skip if x.status in [Claim.STATUS_REJECTED]]
self.assertEqual(len(accepted), 4)
self.assertEqual(len(accepted), 3)
self.assertEqual(len(rejected), 4)

def _get_test_dict(self, code=None):
Expand Down

0 comments on commit 08cd8ef

Please sign in to comment.