From 2c7a58fef9ab44d67164d35c84c1ed3ee250055b Mon Sep 17 00:00:00 2001 From: Facundo Dartayete Date: Wed, 28 Aug 2024 15:38:07 -0300 Subject: [PATCH 1/2] feature: advances --- .env.example | 4 + config/services.php | 3 + ...3658_create_pverify_access_token_table.php | 26 ++++++ routes/api.php | 3 + .../MbiLookupRequestDto.php | 16 ++++ .../Controllers/RunEligibilityController.php | 24 ++++++ .../App/Request/EligibilityCheckRequest.php | 79 +++++++++++++++++++ .../Actions/GetPVerifyAccessTokenAction.php | 37 +++++++++ .../Domain/Actions/RunEligibilityAction.php | 28 +++++++ .../Domain/Actions/RunMbiLookupAction.php | 31 ++++++++ .../RunPVerifyEligibilitySummaryAction.php | 39 +++++++++ .../EligibilityCheckDto.php | 26 ++++++ src/Shared/Domain/Models/PVerifyToken.php | 24 ++++++ .../Integrations/PVerify/PVerifyConnector.php | 8 ++ ...mary.php => EligibilitySummaryRequest.php} | 8 +- .../EligibilitySummaryResultsRequest.php | 22 ++++++ .../{GetToken.php => GetTokenRequest.php} | 2 +- .../PVerify/Requests/MbiLookupRequest.php | 35 ++++++++ .../Requests/MbiLookupRequestResults.php | 22 ++++++ 19 files changed, 433 insertions(+), 4 deletions(-) create mode 100644 database/migrations/2024_08_28_183658_create_pverify_access_token_table.php create mode 100644 src/Backoffice/Users/Domain/DataTransferObjects/MbiLookupRequestDto.php create mode 100644 src/Insurance/App/Controllers/RunEligibilityController.php create mode 100644 src/Insurance/App/Request/EligibilityCheckRequest.php create mode 100644 src/Insurance/Domain/Actions/GetPVerifyAccessTokenAction.php create mode 100644 src/Insurance/Domain/Actions/RunEligibilityAction.php create mode 100644 src/Insurance/Domain/Actions/RunMbiLookupAction.php create mode 100644 src/Insurance/Domain/Actions/RunPVerifyEligibilitySummaryAction.php create mode 100644 src/Insurance/Domain/DataTransferObjects/EligibilityCheckDto.php create mode 100644 src/Shared/Domain/Models/PVerifyToken.php rename src/Shared/Integrations/Integrations/PVerify/Requests/{EligibilitySummary.php => EligibilitySummaryRequest.php} (80%) create mode 100644 src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryResultsRequest.php rename src/Shared/Integrations/Integrations/PVerify/Requests/{GetToken.php => GetTokenRequest.php} (95%) create mode 100644 src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequest.php create mode 100644 src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequestResults.php diff --git a/.env.example b/.env.example index 6ebd2b2291f..42477d56293 100644 --- a/.env.example +++ b/.env.example @@ -92,3 +92,7 @@ VITE_SENTRY_PROJECT= # String regex without the "/". Example: # ^https:\/\/yourserver\.io\/api VITE_SENTRY_TRACE_PROPAGATION_TARGET_REGEX= + +PVERIFY_BASE_URL=https://api.pverify.com/API +PVERIFY_CLIENT_API_ID= +PVERIFY_CLIENT_SECRET= \ No newline at end of file diff --git a/config/services.php b/config/services.php index dbbb7080a6d..1f00055313f 100644 --- a/config/services.php +++ b/config/services.php @@ -39,6 +39,9 @@ 'base_url' => env('PVERIFY_BASE_URL'), 'client_api_id' => env('PVERIFY_CLIENT_API_ID'), 'client_secret' => env('PVERIFY_CLIENT_SECRET'), + 'sleep_seconds' => env('PVERIFY_SLEEP_SECONDS'), + 'provider_pcn' => env('PVERIFY_PROVIDER_PCN'), + 'provider_last_name' => env('PVERIFY_PROVIDER_LAST_NAME'), ], 'dosespot' => [ diff --git a/database/migrations/2024_08_28_183658_create_pverify_access_token_table.php b/database/migrations/2024_08_28_183658_create_pverify_access_token_table.php new file mode 100644 index 00000000000..b46e92ba187 --- /dev/null +++ b/database/migrations/2024_08_28_183658_create_pverify_access_token_table.php @@ -0,0 +1,26 @@ +id(); + $table->string('access_token', 1024); + $table->timestamp('expires_at'); + $table->text('raw_response'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('pverify_access_tokens'); + } +}; diff --git a/routes/api.php b/routes/api.php index 93a56623460..96e2856b893 100644 --- a/routes/api.php +++ b/routes/api.php @@ -9,6 +9,7 @@ use Lightit\Insurance\App\Controllers\GetAvailableDMEProvidersController; use Lightit\Insurance\App\Controllers\MedicareAdvantageEligibilityCheckController; use Lightit\Insurance\App\Controllers\MedicareEligibilityCheckController; +use Lightit\Insurance\App\Controllers\RunEligibilityController; /* |-------------------------------------------------------------------------- @@ -43,3 +44,5 @@ Route::post('/medicare-advantage/eligibility-check', MedicareAdvantageEligibilityCheckController::class); Route::get('/dme/providers', GetAvailableDMEProvidersController::class); + +Route::post('/eligibility', RunEligibilityController::class); diff --git a/src/Backoffice/Users/Domain/DataTransferObjects/MbiLookupRequestDto.php b/src/Backoffice/Users/Domain/DataTransferObjects/MbiLookupRequestDto.php new file mode 100644 index 00000000000..003db045c53 --- /dev/null +++ b/src/Backoffice/Users/Domain/DataTransferObjects/MbiLookupRequestDto.php @@ -0,0 +1,16 @@ +toDto(); + + $result = $runEligibilityAction->execute($eligibilityData); + return responder() + ->success() + ->respond(); + } +} diff --git a/src/Insurance/App/Request/EligibilityCheckRequest.php b/src/Insurance/App/Request/EligibilityCheckRequest.php new file mode 100644 index 00000000000..c1b6f9492fa --- /dev/null +++ b/src/Insurance/App/Request/EligibilityCheckRequest.php @@ -0,0 +1,79 @@ + + */ + public function rules(): array + { + return [ + self::MEMBER_ID => ['required', 'string'], + self::FIRST_NAME => ['required', 'string'], + self::LAST_NAME => ['required', 'string'], + self::DOB => ['required', 'date'], + + self::STREET => ['required', 'string'], + self::CITY => ['required', 'string'], + self::STATE => ['required', new Enum(USState::class)], + self::ZIP => ['required', 'string'], + + self::PLAN_TYPE => ['required', 'string'], + self::DIABETES_TYPE => ['required', 'string'], + ]; + } + + protected function prepareForValidation() + { + if ($this->has('state') && is_string($this->state)) { + $this->merge([ + 'state' => strtoupper($this->state), + ]); + } + } + + public function toDto(): EligibilityCheckDto + { + /** @var Carbon $dob */ + $dob = $this->date(self::DOB); + + return new EligibilityCheckDto( + member_id: $this->string(self::MEMBER_ID)->toString(), + first_name: $this->string(self::FIRST_NAME)->toString(), + last_name: $this->string(self::LAST_NAME)->toString(), + dob: $dob, + street: $this->string(self::STREET)->toString(), + city: $this->string(self::CITY)->toString(), + state: USState::from($this->string(self::STATE)->toString()), + zip: $this->string(self::ZIP)->toString(), + plan_type: $this->string(self::PLAN_TYPE)->toString(), + diabetes_type: $this->string(self::DIABETES_TYPE)->toString(), + diabetes_management: $this->string(self::DIABETES_MANAGEMENT)->toString(), + ); + } +} diff --git a/src/Insurance/Domain/Actions/GetPVerifyAccessTokenAction.php b/src/Insurance/Domain/Actions/GetPVerifyAccessTokenAction.php new file mode 100644 index 00000000000..432c81a2e8c --- /dev/null +++ b/src/Insurance/Domain/Actions/GetPVerifyAccessTokenAction.php @@ -0,0 +1,37 @@ +', now())->first(); + if ($validToken) { + return $validToken->token; + } + + $request = new GetTokenRequest(); + $response = $this->connector->send($request); + + $getTokenResponse = $response->json(); + + $token = PVerifyToken::create([ + 'token' => $getTokenResponse['access_token'], + 'expires_at' => now()->addSeconds($getTokenResponse['expires_in']), + 'raw_response' => json_encode($getTokenResponse), + ]); + + return $token->access_token; + } +} diff --git a/src/Insurance/Domain/Actions/RunEligibilityAction.php b/src/Insurance/Domain/Actions/RunEligibilityAction.php new file mode 100644 index 00000000000..7ebdd01dbcb --- /dev/null +++ b/src/Insurance/Domain/Actions/RunEligibilityAction.php @@ -0,0 +1,28 @@ +isMedicare($eligibilityCheckData) || $this->isMedicareAdvantage($eligibilityCheckData)) { + } + } + + private function isMedicare(EligibilityCheckDto $eligibilityCheckData): bool + { + return $eligibilityCheckData->dob->diffInYears(now()) >= 65 && $eligibilityCheckData->plan_type === 'medicare'; + } + + private function isMedicareAdvantage(EligibilityCheckDto $eligibilityCheckData): bool + { + return $eligibilityCheckData->dob->diffInYears(now()) >= 65 && $eligibilityCheckData->plan_type === 'medicare_advantage'; + } +} diff --git a/src/Insurance/Domain/Actions/RunMbiLookupAction.php b/src/Insurance/Domain/Actions/RunMbiLookupAction.php new file mode 100644 index 00000000000..0fdf5233b8a --- /dev/null +++ b/src/Insurance/Domain/Actions/RunMbiLookupAction.php @@ -0,0 +1,31 @@ +first_name, + lastName: $eligibilityCheckDto->last_name, + dob: $eligibilityCheckDto->dob, + )); + $response = $this->connector->send($request); + + $mbiLookupResponseBody = $response->json(); + + return $mbiLookupResponseBody; + } +} diff --git a/src/Insurance/Domain/Actions/RunPVerifyEligibilitySummaryAction.php b/src/Insurance/Domain/Actions/RunPVerifyEligibilitySummaryAction.php new file mode 100644 index 00000000000..11b6d72720d --- /dev/null +++ b/src/Insurance/Domain/Actions/RunPVerifyEligibilitySummaryAction.php @@ -0,0 +1,39 @@ +connector->send($request); + + $eligibilitySummaryResponse = $response->json(); + + sleep((int)config('services.pverify.sleep_seconds')); + + $getResultsRequest = new EligibilitySummaryResultsRequest($eligibilitySummaryResponse['requestId']); + + $getResultResponse = $this->connector->send($getResultsRequest); + + return $getResultResponse->json(); + } +} diff --git a/src/Insurance/Domain/DataTransferObjects/EligibilityCheckDto.php b/src/Insurance/Domain/DataTransferObjects/EligibilityCheckDto.php new file mode 100644 index 00000000000..b5f4e9c3ee6 --- /dev/null +++ b/src/Insurance/Domain/DataTransferObjects/EligibilityCheckDto.php @@ -0,0 +1,26 @@ + 'application/json', 'Accept' => 'application/json', + 'Authorization' => 'Bearer ' . $this->getPVerifyTokenAction->execute(), ]; } diff --git a/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummary.php b/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryRequest.php similarity index 80% rename from src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummary.php rename to src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryRequest.php index df1ec76b647..45ce52fc41d 100644 --- a/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummary.php +++ b/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryRequest.php @@ -6,13 +6,15 @@ use Lightit\Backoffice\Users\Domain\DataTransferObjects\PVerifyEligibilitySummaryRequestDTO; use Saloon\Http\Request; +use Saloon\Enums\Method; -class EligibilitySummary extends Request +class EligibilitySummaryRequest extends Request { + protected Method $method = Method::POST; + public function __construct( protected PVerifyEligibilitySummaryRequestDTO $pVerifyEligibilitySummary, - ) { - } + ) {} public function resolveEndpoint(): string { diff --git a/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryResultsRequest.php b/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryResultsRequest.php new file mode 100644 index 00000000000..5df563104b1 --- /dev/null +++ b/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryResultsRequest.php @@ -0,0 +1,22 @@ +requestId}"; + } +} diff --git a/src/Shared/Integrations/Integrations/PVerify/Requests/GetToken.php b/src/Shared/Integrations/Integrations/PVerify/Requests/GetTokenRequest.php similarity index 95% rename from src/Shared/Integrations/Integrations/PVerify/Requests/GetToken.php rename to src/Shared/Integrations/Integrations/PVerify/Requests/GetTokenRequest.php index 27871de2cba..0732b74ab3c 100644 --- a/src/Shared/Integrations/Integrations/PVerify/Requests/GetToken.php +++ b/src/Shared/Integrations/Integrations/PVerify/Requests/GetTokenRequest.php @@ -9,7 +9,7 @@ use Saloon\Http\Request; use Saloon\Traits\Request\HasConnector; -class GetToken extends Request +class GetTokenRequest extends Request { use HasConnector; diff --git a/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequest.php b/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequest.php new file mode 100644 index 00000000000..9a48ef8d3a6 --- /dev/null +++ b/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequest.php @@ -0,0 +1,35 @@ + (string) config('services.pverify.provider_last_name'), + "ProviderNPI" => (string) config('services.pverify.provider_npi'), + "PatientFirstName" => $this->mbiLookupRequestDto->firstName, + "PatientLastName" => $this->mbiLookupRequestDto->lastName, + "PatientDOB" => $this->mbiLookupRequestDto->dob->format('MM-dd-YYYY'), + ]; + } +} diff --git a/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequestResults.php b/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequestResults.php new file mode 100644 index 00000000000..1a04530cdd2 --- /dev/null +++ b/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequestResults.php @@ -0,0 +1,22 @@ +requestId}"; + } +} From fb00034af2ad7284fb21b713647050c74c11c01f Mon Sep 17 00:00:00 2001 From: Facundo Dartayete Date: Wed, 28 Aug 2024 18:41:09 -0300 Subject: [PATCH 2/2] feature: medicare flow --- config/services.php | 2 +- cspell.json | 1 + src/Backoffice/Payers/Domain/Models/Payer.php | 2 + .../Controllers/RunEligibilityController.php | 4 +- .../App/Exceptions/NotEligibleException.php | 24 ++++++++++++ .../App/Request/EligibilityCheckRequest.php | 3 -- .../Domain/Actions/RunEligibilityAction.php | 39 +++++++++++++------ .../Domain/Actions/RunMbiLookupAction.php | 17 ++++---- .../RunPVerifyEligibilitySummaryAction.php | 21 +++++++++- .../EligibilityCheckDto.php | 1 - .../MbiLookupRequestDto.php | 2 +- .../EligibilitySummaryResultsRequest.php | 23 ----------- .../PVerify/Requests/BaseRequest.php | 1 + .../Requests/EligibilitySummaryRequest.php | 8 ++-- .../GetEligibilitySummaryResultsRequest.php | 3 +- .../PVerify/Requests/MbiLookupRequest.php | 18 +++++---- .../Requests/MbiLookupRequestResults.php | 8 ++-- 17 files changed, 110 insertions(+), 67 deletions(-) create mode 100644 src/Insurance/App/Exceptions/NotEligibleException.php delete mode 100644 src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryResultsRequest.php rename src/Shared/Integrations/{Integrations => }/PVerify/Requests/MbiLookupRequest.php (67%) rename src/Shared/Integrations/{Integrations => }/PVerify/Requests/MbiLookupRequestResults.php (56%) diff --git a/config/services.php b/config/services.php index 1f00055313f..fb227dbf3e1 100644 --- a/config/services.php +++ b/config/services.php @@ -40,7 +40,7 @@ 'client_api_id' => env('PVERIFY_CLIENT_API_ID'), 'client_secret' => env('PVERIFY_CLIENT_SECRET'), 'sleep_seconds' => env('PVERIFY_SLEEP_SECONDS'), - 'provider_pcn' => env('PVERIFY_PROVIDER_PCN'), + 'provider_npi' => env('PVERIFY_PROVIDER_NPI'), 'provider_last_name' => env('PVERIFY_PROVIDER_LAST_NAME'), ], diff --git a/cspell.json b/cspell.json index 5382e8613f0..5ecae48620c 100644 --- a/cspell.json +++ b/cspell.json @@ -32,6 +32,7 @@ "Debugbar", "Dispatchable", "docblocks", + "doespots", "dosespot", "EHLO", "Encrypter", diff --git a/src/Backoffice/Payers/Domain/Models/Payer.php b/src/Backoffice/Payers/Domain/Models/Payer.php index 4c3dc472027..6ab408221bc 100644 --- a/src/Backoffice/Payers/Domain/Models/Payer.php +++ b/src/Backoffice/Payers/Domain/Models/Payer.php @@ -33,6 +33,8 @@ * @method static \Illuminate\Database\Eloquent\Builder|Payer whereDataSyncId($value) * * @property-read Datasync|null $dataSync + * @property-read \Illuminate\Database\Eloquent\Collection $payerDMEProviders + * @property-read int|null $payer_d_m_e_providers_count * * @mixin \Eloquent */ diff --git a/src/Insurance/App/Controllers/RunEligibilityController.php b/src/Insurance/App/Controllers/RunEligibilityController.php index 672937c1268..16b267b794e 100644 --- a/src/Insurance/App/Controllers/RunEligibilityController.php +++ b/src/Insurance/App/Controllers/RunEligibilityController.php @@ -16,9 +16,9 @@ public function __invoke( ): JsonResponse { $eligibilityData = $request->toDto(); - $runEligibilityAction->execute($eligibilityData); + $response = $runEligibilityAction->execute($eligibilityData); return responder() - ->success() + ->success($response) ->respond(); } } diff --git a/src/Insurance/App/Exceptions/NotEligibleException.php b/src/Insurance/App/Exceptions/NotEligibleException.php new file mode 100644 index 00000000000..fc68bed6c1c --- /dev/null +++ b/src/Insurance/App/Exceptions/NotEligibleException.php @@ -0,0 +1,24 @@ + ['required', 'string'], self::FIRST_NAME => ['required', 'string'], self::LAST_NAME => ['required', 'string'], self::DOB => ['required', 'date'], @@ -62,7 +60,6 @@ public function toDto(): EligibilityCheckDto $dob = $this->date(self::DOB); return new EligibilityCheckDto( - member_id: $this->string(self::MEMBER_ID)->toString(), first_name: $this->string(self::FIRST_NAME)->toString(), last_name: $this->string(self::LAST_NAME)->toString(), dob: $dob, diff --git a/src/Insurance/Domain/Actions/RunEligibilityAction.php b/src/Insurance/Domain/Actions/RunEligibilityAction.php index 9f8a1da2723..bafa25e09f3 100644 --- a/src/Insurance/Domain/Actions/RunEligibilityAction.php +++ b/src/Insurance/Domain/Actions/RunEligibilityAction.php @@ -4,37 +4,52 @@ namespace Lightit\Insurance\Domain\Actions; +use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; use Lightit\Insurance\Domain\DataTransferObjects\EligibilityCheckDto; +use Lightit\Insurance\Domain\DataTransferObjects\GetAvailableDMEProvidersDto; +use Lightit\Shared\Domain\Models\PayersDMEProvider; class RunEligibilityAction { public function __construct( private readonly RunMbiLookupAction $mbiLookupAction, private readonly RunPVerifyEligibilitySummaryAction $pVerifyEligibilitySummaryAction, + private readonly GetAvailableDMEProvidersAction $getAvailableDMEProvidersAction, ) { } - public function execute(EligibilityCheckDto $eligibilityCheckData): array + /** + * @return Collection + */ + public function execute(EligibilityCheckDto $eligibilityCheckData): Collection { - if ($this->isMedicare($eligibilityCheckData) || $this->isMedicareAdvantage($eligibilityCheckData)) { + if ($this->isMedicare($eligibilityCheckData)) { $mbiLookupResponse = $this->mbiLookupAction->execute($eligibilityCheckData); - return $this->pVerifyEligibilitySummaryAction->execute($eligibilityCheckData, $mbiLookupResponse); + $eligibilityResponse = $this->pVerifyEligibilitySummaryAction->execute( + $eligibilityCheckData, + $mbiLookupResponse + ); + + Log::info('Medicare eligible', ['response' => $eligibilityResponse]); + + return $this->getAvailableDMEProvidersAction->execute( + new GetAvailableDMEProvidersDto( + payer: $eligibilityResponse['PayerName'], + state: $eligibilityCheckData->state + ) + ); } - + //medicare advantage flow - return []; + //doespots flow + + return collect([]); } private function isMedicare(EligibilityCheckDto $eligibilityCheckData): bool { return $eligibilityCheckData->dob->diffInYears(now()) >= 65 && $eligibilityCheckData->plan_type === 'medicare'; } - - private function isMedicareAdvantage(EligibilityCheckDto $eligibilityCheckData): bool - { - return $eligibilityCheckData->dob->diffInYears( - now() - ) >= 65 && $eligibilityCheckData->plan_type === 'medicare_advantage'; - } } diff --git a/src/Insurance/Domain/Actions/RunMbiLookupAction.php b/src/Insurance/Domain/Actions/RunMbiLookupAction.php index 5f15f29c0d3..6e30e6a77f3 100644 --- a/src/Insurance/Domain/Actions/RunMbiLookupAction.php +++ b/src/Insurance/Domain/Actions/RunMbiLookupAction.php @@ -4,10 +4,10 @@ namespace Lightit\Insurance\Domain\Actions; -use Lightit\Backoffice\Users\Domain\DataTransferObjects\MbiLookupRequestDto; use Lightit\Insurance\Domain\DataTransferObjects\EligibilityCheckDto; -use Lightit\Shared\Integrations\Integrations\PVerify\Requests\MbiLookupRequest; +use Lightit\Insurance\Domain\DataTransferObjects\MbiLookupRequestDto; use Lightit\Shared\Integrations\PVerify\PVerifyConnector; +use Lightit\Shared\Integrations\PVerify\Requests\MbiLookupRequest; class RunMbiLookupAction { @@ -18,11 +18,14 @@ public function __construct( public function execute(EligibilityCheckDto $eligibilityCheckDto): array { - $request = new MbiLookupRequest(new MbiLookupRequestDto( - firstName: $eligibilityCheckDto->first_name, - lastName: $eligibilityCheckDto->last_name, - dob: $eligibilityCheckDto->dob, - )); + $request = new MbiLookupRequest( + new MbiLookupRequestDto( + firstName: $eligibilityCheckDto->first_name, + lastName: $eligibilityCheckDto->last_name, + dob: $eligibilityCheckDto->dob, + ) + ); + $response = $this->connector->send($request); return $response->json(); diff --git a/src/Insurance/Domain/Actions/RunPVerifyEligibilitySummaryAction.php b/src/Insurance/Domain/Actions/RunPVerifyEligibilitySummaryAction.php index 43309d9024e..04558b66573 100644 --- a/src/Insurance/Domain/Actions/RunPVerifyEligibilitySummaryAction.php +++ b/src/Insurance/Domain/Actions/RunPVerifyEligibilitySummaryAction.php @@ -4,6 +4,8 @@ namespace Lightit\Insurance\Domain\Actions; +use Illuminate\Support\Facades\Log; +use Lightit\Insurance\App\Exceptions\NotEligibleException; use Lightit\Insurance\Domain\DataTransferObjects\EligibilityCheckDto; use Lightit\Shared\Integrations\PVerify\DataTransferObjects\EligibilitySummaryRequestDTO; use Lightit\Shared\Integrations\PVerify\PVerifyConnector; @@ -38,10 +40,27 @@ public function execute(EligibilityCheckDto $eligibilityCheckDto, array $mbiLook sleep((int) config('services.pverify.sleep_seconds')); - $getResultsRequest = new GetEligibilitySummaryResultsRequest((string) $eligibilitySummaryResponse['RequestId']); + $getResultsRequest = new GetEligibilitySummaryResultsRequest((string) $eligibilitySummaryResponse['RequestID']); $getResultResponse = $this->connector->send($getResultsRequest); + if ( + ! $getResultResponse->ok() + || ! $getResultResponse->body() + || $this->notEligible($getResultResponse->json()) + ) { + Log::error( + 'Failed to check Medicare eligibility', + ['requestID' => $eligibilitySummaryResponse['RequestID'], 'response' => $getResultResponse->json(), ] + ); + throw new NotEligibleException(); + } + return $getResultResponse->json(); } + + private function notEligible(array $response): bool + { + return ! $response['PayerName']; + } } diff --git a/src/Insurance/Domain/DataTransferObjects/EligibilityCheckDto.php b/src/Insurance/Domain/DataTransferObjects/EligibilityCheckDto.php index b5f4e9c3ee6..fde1290c4b5 100644 --- a/src/Insurance/Domain/DataTransferObjects/EligibilityCheckDto.php +++ b/src/Insurance/Domain/DataTransferObjects/EligibilityCheckDto.php @@ -10,7 +10,6 @@ readonly class EligibilityCheckDto { public function __construct( - public string $member_id, public string $first_name, public string $last_name, public Carbon $dob, diff --git a/src/Insurance/Domain/DataTransferObjects/MbiLookupRequestDto.php b/src/Insurance/Domain/DataTransferObjects/MbiLookupRequestDto.php index 383af2ffcae..b8b035d8951 100644 --- a/src/Insurance/Domain/DataTransferObjects/MbiLookupRequestDto.php +++ b/src/Insurance/Domain/DataTransferObjects/MbiLookupRequestDto.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Lightit\Backoffice\Users\Domain\DataTransferObjects; +namespace Lightit\Insurance\Domain\DataTransferObjects; use Carbon\Carbon; diff --git a/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryResultsRequest.php b/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryResultsRequest.php deleted file mode 100644 index 2debee0e70e..00000000000 --- a/src/Shared/Integrations/Integrations/PVerify/Requests/EligibilitySummaryResultsRequest.php +++ /dev/null @@ -1,23 +0,0 @@ -requestId}"; - } -} diff --git a/src/Shared/Integrations/PVerify/Requests/BaseRequest.php b/src/Shared/Integrations/PVerify/Requests/BaseRequest.php index 362a3bf5f88..98a11d149ab 100644 --- a/src/Shared/Integrations/PVerify/Requests/BaseRequest.php +++ b/src/Shared/Integrations/PVerify/Requests/BaseRequest.php @@ -16,6 +16,7 @@ abstract class BaseRequest extends Request use HasConnector; protected string $connector = PVerifyConnector::class; + private string $token; public function __construct() diff --git a/src/Shared/Integrations/PVerify/Requests/EligibilitySummaryRequest.php b/src/Shared/Integrations/PVerify/Requests/EligibilitySummaryRequest.php index 66546443782..c8c6ed40296 100644 --- a/src/Shared/Integrations/PVerify/Requests/EligibilitySummaryRequest.php +++ b/src/Shared/Integrations/PVerify/Requests/EligibilitySummaryRequest.php @@ -27,7 +27,7 @@ public function __construct( public function resolveEndpoint(): string { - return 'api/EligibilitySummary'; + return 'API/EligibilitySummary'; } protected function defaultBody(): array @@ -41,12 +41,12 @@ protected function defaultBody(): array "subscriber" => [ "firstName" => $this->data->firstName, "lastName" => $this->data->lastName, - "dob" => $this->data->dob, + "dob" => $this->data->dob->format('m/d/Y'), "memberID" => $this->data->memberID, ], "isSubscriberPatient" => "True", - "doS_StartDate" => Carbon::now()->subDay()->format('MM/dd/YYYY'), - "doS_EndDate" => Carbon::now()->addDay()->format('MM/dd/YYYY'), + "doS_StartDate" => Carbon::now()->subDay()->format('m/d/Y'), + "doS_EndDate" => Carbon::now()->addDay()->format('m/d/Y'), ]; } } diff --git a/src/Shared/Integrations/PVerify/Requests/GetEligibilitySummaryResultsRequest.php b/src/Shared/Integrations/PVerify/Requests/GetEligibilitySummaryResultsRequest.php index 8f249aba10b..71a9b66c225 100644 --- a/src/Shared/Integrations/PVerify/Requests/GetEligibilitySummaryResultsRequest.php +++ b/src/Shared/Integrations/PVerify/Requests/GetEligibilitySummaryResultsRequest.php @@ -12,10 +12,11 @@ class GetEligibilitySummaryResultsRequest extends BaseRequest public function __construct(public string $requestId) { + parent::__construct(); } public function resolveEndpoint(): string { - return 'api/GetEligibilitySummary/' . $this->requestId; + return 'API/GetEligibilitySummary/' . $this->requestId; } } diff --git a/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequest.php b/src/Shared/Integrations/PVerify/Requests/MbiLookupRequest.php similarity index 67% rename from src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequest.php rename to src/Shared/Integrations/PVerify/Requests/MbiLookupRequest.php index 0dc418a67d9..10a32f141ee 100644 --- a/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequest.php +++ b/src/Shared/Integrations/PVerify/Requests/MbiLookupRequest.php @@ -2,15 +2,18 @@ declare(strict_types=1); -namespace Lightit\Shared\Integrations\Integrations\PVerify\Requests; +namespace Lightit\Shared\Integrations\PVerify\Requests; -use Lightit\Backoffice\Users\Domain\DataTransferObjects\MbiLookupRequestDto; +use Lightit\Insurance\Domain\DataTransferObjects\MbiLookupRequestDto; use Lightit\Shared\Integrations\PVerify\DataTransferObjects\PVerifyProviderDTO; +use Saloon\Contracts\Body\HasBody; use Saloon\Enums\Method; -use Saloon\Http\Request; +use Saloon\Traits\Body\HasJsonBody; -class MbiLookupRequest extends Request +class MbiLookupRequest extends BaseRequest implements HasBody { + use HasJsonBody; + protected Method $method = Method::POST; private readonly PVerifyProviderDTO $provider; @@ -18,22 +21,23 @@ class MbiLookupRequest extends Request public function __construct( protected MbiLookupRequestDto $mbiLookupRequestDto, ) { + parent::__construct(); $this->provider = new PVerifyProviderDTO(); } public function resolveEndpoint(): string { - return '/MBIInquiry'; + return '/API/MBIInquiry'; } - public function body(): array + protected function defaultBody(): array { return [ "ProviderLastName" => $this->provider->lastName, "ProviderNPI" => $this->provider->npi, "PatientFirstName" => $this->mbiLookupRequestDto->firstName, "PatientLastName" => $this->mbiLookupRequestDto->lastName, - "PatientDOB" => $this->mbiLookupRequestDto->dob->format('MM-dd-YYYY'), + "PatientDOB" => $this->mbiLookupRequestDto->dob->format('m/d/Y'), ]; } } diff --git a/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequestResults.php b/src/Shared/Integrations/PVerify/Requests/MbiLookupRequestResults.php similarity index 56% rename from src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequestResults.php rename to src/Shared/Integrations/PVerify/Requests/MbiLookupRequestResults.php index ecf0c75e057..e5e1ae9c65b 100644 --- a/src/Shared/Integrations/Integrations/PVerify/Requests/MbiLookupRequestResults.php +++ b/src/Shared/Integrations/PVerify/Requests/MbiLookupRequestResults.php @@ -2,22 +2,22 @@ declare(strict_types=1); -namespace Lightit\Shared\Integrations\Integrations\PVerify\Requests; +namespace Lightit\Shared\Integrations\PVerify\Requests; use Saloon\Enums\Method; -use Saloon\Http\Request; -class MbiLookupRequestResults extends Request +class MbiLookupRequestResults extends BaseRequest { protected Method $method = Method::GET; public function __construct( protected string $requestId, ) { + parent::__construct(); } public function resolveEndpoint(): string { - return "/GetMBIResponse/{$this->requestId}"; + return "/API/GetMBIResponse/{$this->requestId}"; } }