Skip to content

Commit

Permalink
Revert "Revert "EP Merge: Check to make sure pending claim is still o…
Browse files Browse the repository at this point in the history
……" (#2814)

Revert "Revert "EP Merge: Check to make sure pending claim is still open befo… (#2797)"

This reverts commit 866a4a1.
  • Loading branch information
dfitchett authored Apr 1, 2024
1 parent 210a0fa commit 018f03c
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 97 deletions.
24 changes: 12 additions & 12 deletions domain-ee/ee-ep-merge-app/integration/test_merge_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def test_completed_success(
cancel_claim_endpoint: MqEndpoint,
add_claim_note_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_200])
create_claim_contentions_endpoint.set_responses([response_201])
Expand All @@ -90,7 +90,7 @@ async def test_completed_success_with_duplicate_contention(
cancel_claim_endpoint: MqEndpoint,
add_claim_note_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_duplicate_contentions_200])
put_tsoj_endpoint.set_responses([response_200])
cancel_claim_endpoint.set_responses([response_200])
Expand All @@ -110,7 +110,7 @@ async def test_completed_no_ep400_contentions_on_first_attempt(
cancel_claim_endpoint: MqEndpoint,
add_claim_note_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, response_204, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_200])
create_claim_contentions_endpoint.set_responses([response_201])
Expand Down Expand Up @@ -279,7 +279,7 @@ async def test(
put_tsoj_endpoint: MqEndpoint,
update_claim_contentions_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_500])
update_claim_contentions_endpoint.set_responses([response_200])
Expand All @@ -296,7 +296,7 @@ async def test_error_at_remove_special_issue_fail_to_update_ep400_contentions(
put_tsoj_endpoint: MqEndpoint,
update_claim_contentions_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_500])
update_claim_contentions_endpoint.set_responses([response_500])
Expand All @@ -317,7 +317,7 @@ async def test(
create_claim_contentions_endpoint: MqEndpoint,
update_claim_contentions_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_200, response_200]) # Second response is to revert the tsoj
create_claim_contentions_endpoint.set_responses([response_500])
Expand All @@ -336,7 +336,7 @@ async def test_error_at_remove_special_issue_fail_to_update_ep400_contentions(
create_claim_contentions_endpoint: MqEndpoint,
update_claim_contentions_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_200, response_200])
create_claim_contentions_endpoint.set_responses([response_500])
Expand All @@ -355,7 +355,7 @@ async def test_error_at_revert_tsoj(
create_claim_contentions_endpoint: MqEndpoint,
update_claim_contentions_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_200, response_500]) # Note the 500 on second response
create_claim_contentions_endpoint.set_responses([response_500])
Expand All @@ -377,7 +377,7 @@ async def test(
create_claim_contentions_endpoint: MqEndpoint,
cancel_claim_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_200, response_200]) # Note the 200 to revert tsoj
create_claim_contentions_endpoint.set_responses([response_201])
Expand All @@ -396,7 +396,7 @@ async def test_error_at_revert_tsoj(
create_claim_contentions_endpoint: MqEndpoint,
cancel_claim_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_200, response_500]) # Note the 500 on second response
create_claim_contentions_endpoint.set_responses([response_201])
Expand All @@ -420,7 +420,7 @@ async def test(
add_claim_note_endpoint: MqEndpoint,
update_claim_contentions_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_200])
create_claim_contentions_endpoint.set_responses([response_201])
Expand All @@ -443,7 +443,7 @@ async def test_error_at_remove_special_issue_fail_to_update_ep400_contentions(
add_claim_note_endpoint: MqEndpoint,
update_claim_contentions_endpoint: MqEndpoint,
):
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200])
get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200])
get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200])
put_tsoj_endpoint.set_responses([response_200])
create_claim_contentions_endpoint.set_responses([response_201])
Expand Down
1 change: 1 addition & 0 deletions domain-ee/ee-ep-merge-app/src/python_src/schema/claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ class ClaimDetail(BaseModel):
benefit_claim_type: BenefitClaimType | None = None
end_product_code: str | None = None
temp_station_of_jurisdiction: str | None = None
claim_lifecycle_status: str | None = None
2 changes: 2 additions & 0 deletions domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class JobState(StrEnum):
GET_PENDING_CLAIM_CONTENTIONS = auto()
GET_EP400_CLAIM = auto()
GET_EP400_CLAIM_CONTENTIONS = auto()
CHECK_PENDING_EP_IS_OPEN = auto()
SET_TEMP_STATION_OF_JURISDICTION = auto()
MERGE_CONTENTIONS = auto()
MOVE_CONTENTIONS_TO_PENDING_CLAIM = auto()
Expand All @@ -24,6 +25,7 @@ class JobState(StrEnum):
GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE = auto()
GET_EP400_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE = auto()
GET_PENDING_CLAIM_CONTENTIONS_FAILED_REMOVE_SPECIAL_ISSUE = auto()
CHECK_PENDING_EP_IS_OPEN_FAILED_REMOVE_SPECIAL_ISSUE = auto()
SET_TEMP_STATION_OF_JURISDICTION_FAILED_REMOVE_SPECIAL_ISSUE = auto()
MOVE_CONTENTIONS_FAILED_REMOVE_SPECIAL_ISSUE = auto()
MOVE_CONTENTIONS_FAILED_REVERT_TEMP_STATION_OF_JURISDICTION = auto()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
get_contentions,
update_contentions,
)
from schema.claim import ClaimDetail
from schema import update_temp_station_of_jurisdiction as tsoj
from schema.merge_job import JobState, MergeJob
from schema.request import GeneralRequest
Expand All @@ -40,6 +41,7 @@
JOB_SKIPPED_MERGE_METRIC = 'job.skipped_merge'
JOB_NEW_CONTENTIONS_METRIC = 'job.new_contentions'

ELIGIBLE_CLAIM_LIFECYCLE_STATUSES = frozenset(['open'])
EP400_PRODUCT_CODES = frozenset([str(i) for i in range(400, 410)])
EP400_BENEFIT_CLAIM_TYPE_CODES = frozenset(['400SUPP'])

Expand All @@ -55,6 +57,13 @@ def ep400_has_no_contentions(response: get_contentions.Response):
return not response.contentions


def is_claim_open(claim: ClaimDetail):
"""
Check if the claim's lifecycle status is in the list of ELIGIBLE_CLAIM_LIFECYCLE_STATUSES
"""
return claim and claim.claim_lifecycle_status and claim.claim_lifecycle_status.lower() in ELIGIBLE_CLAIM_LIFECYCLE_STATUSES


class Workflow(str, Enum):
PROCESS = 'process'
RESTART = ('resume_restart',)
Expand All @@ -79,6 +88,8 @@ class EpMergeMachine(StateMachine):
running_get_ep400_claim = State(value=JobState.GET_EP400_CLAIM)
running_get_ep400_claim_failed_remove_special_issue = State(value=JobState.GET_EP400_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE)
running_get_ep400_contentions = State(value=JobState.GET_EP400_CLAIM_CONTENTIONS)
running_check_pending_is_open = State(value=JobState.CHECK_PENDING_EP_IS_OPEN)
running_check_pending_is_open_failed_remove_special_issue = State(value=JobState.CHECK_PENDING_EP_IS_OPEN_FAILED_REMOVE_SPECIAL_ISSUE)
running_set_temp_station_of_jurisdiction = State(value=JobState.SET_TEMP_STATION_OF_JURISDICTION)
running_set_temp_station_of_jurisdiction_failed_remove_special_issue = State(value=JobState.SET_TEMP_STATION_OF_JURISDICTION_FAILED_REMOVE_SPECIAL_ISSUE)
running_merge_contentions = State(value=JobState.MERGE_CONTENTIONS)
Expand All @@ -102,8 +113,11 @@ class EpMergeMachine(StateMachine):
| running_get_pending_contentions.to(running_get_ep400_contentions, unless="has_error")
| running_get_pending_contentions.to(running_get_pending_contentions_failed_remove_special_issue, cond="has_error")
| running_get_pending_contentions_failed_remove_special_issue.to(completed_error)
| running_get_ep400_contentions.to(running_set_temp_station_of_jurisdiction, unless="has_error")
| running_get_ep400_contentions.to(running_check_pending_is_open, unless="has_error")
| running_get_ep400_contentions.to(completed_error, cond="has_error")
| running_check_pending_is_open.to(running_set_temp_station_of_jurisdiction, unless="has_error")
| running_check_pending_is_open.to(running_check_pending_is_open_failed_remove_special_issue, cond="has_error")
| running_check_pending_is_open_failed_remove_special_issue.to(completed_error)
| running_set_temp_station_of_jurisdiction.to(running_merge_contentions, cond="has_new_contentions", unless="has_error")
| running_set_temp_station_of_jurisdiction.to(running_cancel_ep400_claim, unless=["has_new_contentions", "has_error"])
| running_set_temp_station_of_jurisdiction.to(running_set_temp_station_of_jurisdiction_failed_remove_special_issue, cond="has_error")
Expand Down Expand Up @@ -169,6 +183,11 @@ def on_get_pending_claim(self, event):
if response is not None and response.status_code == 200:
if response.claim is None or response.claim.end_product_code is None:
self.add_job_error(f"Pending claim #{self.job.pending_claim_id} does not have an end product code")
if not is_claim_open(response.claim):
self.add_job_error(
f"Pending claim #{self.job.pending_claim_id} does not have an eligible lifecycle status of: "
f"{', '.join(list(ELIGIBLE_CLAIM_LIFECYCLE_STATUSES))}"
)
else:
self.cancellation_reason = CANCELLATION_REASON_FORMAT.format(ep_code=response.claim.end_product_code, claim_id=self.job.pending_claim_id)
self.original_tsoj = response.claim.temp_station_of_jurisdiction
Expand Down Expand Up @@ -217,6 +236,20 @@ def on_get_ep400_contentions(self, event, pending_contentions_response=None):

self.send(event=event, pending_contentions_response=pending_contentions_response, ep400_contentions_response=response)

@running_check_pending_is_open.enter
def on_check_pending_claim_is_open(self, event, pending_contentions_response, ep400_contentions_response):
request = get_claim.Request(claim_id=self.job.pending_claim_id)
response = self.make_request(request=request, hoppy_client=HOPPY.get_client(ClientName.GET_CLAIM), response_type=get_claim.Response)

if response is not None and response.status_code == 200:
if not is_claim_open(response.claim):
self.add_job_error(
f"Pending claim #{self.job.pending_claim_id} does not have an eligible lifecycle status of: "
f"{', '.join(list(ELIGIBLE_CLAIM_LIFECYCLE_STATUSES))}"
)

self.send(event=event, pending_contentions_response=pending_contentions_response, ep400_contentions_response=ep400_contentions_response)

@running_set_temp_station_of_jurisdiction.enter
def on_set_temp_station_of_jurisdiction(self, event, pending_contentions_response=None, ep400_contentions_response=None):
request = tsoj.Request(temp_station_of_jurisdiction="398", claim_id=self.job.ep400_claim_id)
Expand Down Expand Up @@ -257,6 +290,7 @@ def on_add_claim_note_to_ep400(self, event):
@running_get_pending_claim_failed_remove_special_issue.enter
@running_get_pending_contentions_failed_remove_special_issue.enter
@running_get_ep400_claim_failed_remove_special_issue.enter
@running_check_pending_is_open_failed_remove_special_issue.enter
@running_set_temp_station_of_jurisdiction_failed_remove_special_issue.enter
@running_move_contentions_failed_remove_special_issue.enter
def on_pre_cancel_step_failed_remove_special_issue_code(self, event, ep400_contentions_response=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"claim": {
"claimId": 1,
"endProductCode": "010",
"tempStationOfJurisdiction": "111"
"tempStationOfJurisdiction": "111",
"claimLifecycleStatus": "Open"
}
}
7 changes: 7 additions & 0 deletions domain-ee/ee-ep-merge-app/tests/service/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ def process_and_assert(machine, expected_state: JobState, expected_error_state:
assert len(machine.job.messages) == num_errors


def assert_hoppy_requests(mock_hoppy_async_client, calls):
# Number of expected calls should be equal number of actual calls
assert len(calls) == len(mock_hoppy_async_client.make_request.call_args_list)
# Assert calls are made in expected order
mock_hoppy_async_client.make_request.assert_has_calls(calls)


def assert_metrics_called(
metric_logger_distribution,
metric_logger_increment,
Expand Down
Loading

0 comments on commit 018f03c

Please sign in to comment.