Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FHIR Coverage Resource Added #4164

Merged
merged 30 commits into from
Jan 12, 2021
Merged

FHIR Coverage Resource Added #4164

merged 30 commits into from
Jan 12, 2021

Conversation

vishnuyar
Copy link
Contributor

Fixes #4156

Short description of what this resolves:

FHIR Coverage Resource has been added

Changes proposed in this pull request:

Add Insurance Companies to the FHIR Organization Resources
Add Insurance Companies as Payor Reference in the Coverage FHIR Resource
When Searching for Organizations -- Will check in Both Facilities and Insurance Companies

@vishnuyar
Copy link
Contributor Author

These below alter table statements are required in the upgrade sql
ALTER TABLE insurance_companies ADD uuid binary(16) DEFAULT NULL;
ALTER TABLE insurance_data ADD uuid binary(16) DEFAULT NULL;

@vishnuyar
Copy link
Contributor Author

While Creating the Coverage Resource, the status field is compulsory
I couldn't find a meaningful way to decipher the status of the Insurance based on the data in the table "insurance_data" data. Help on this requested.
One Possible solutions was check if the current date is less than "date" in the table. Is it a correct interpretation ?

@stephenwaite
Copy link
Member

stephenwaite commented Jan 6, 2021

hi @vishnuyar , yes, that's correct, but if the current date is less than the date in the table then the insurance is not yet effective which is not that common in my experience. More common will be a null date since folks add them and often don't enter the effective date.

Easiest solution might be to grab the most recent insurance entered, and just talking about primary right now for simplicity and then use it if passes the current date test.

It might be nice to add a date to check when calling this function.

@vishnuyar
Copy link
Contributor Author

@stephenwaite how will we know if a specific plan has expired

@stephenwaite
Copy link
Member

only definitive is if another ins has been added that has a more recent effective date

@sjpadgett
Copy link
Member

Hi @vishnuyar
I not sure the best way to handle what constitutes a Organization is inside the FHIR service.
Our API design concept is to extend this type of core database arbitration from a standard service. The reason for this is that many other current and future development relies on these types of service. In this case, Institutional development and upcoming HIE feature will rely on similar need for Organization.
So now would be the best time to do this as if we bring this PR into codebase as it is now, i'll have to rewrite.
How can I help you to do this?

@vishnuyar
Copy link
Contributor Author

vishnuyar commented Jan 6, 2021 via email

@sjpadgett
Copy link
Member

It is true we currently don't use Organization per se. However, we have an ongoing project for institutional support where both Organization and Location are important. Since we are now needing this capabilities to support FHIR it has pushed up the timeline on adding these services.
I thought I addressed this on the issue thread on adding the organization table support via Practice UI. And I don't really like stored procedures as they are hard to maintain over time.
Though we can add the new table and I can help with that integration.

@bradymiller
Copy link
Member

hi,
I'd rec just making a standard api organization service to do what you need, which the FHIR service can then call. This organization service will also be useful for the standard api. Since I'm lazy, I would also avoid any heavy lifting or database changes unless new datapoints need to be stored.

@vishnuyar
Copy link
Contributor Author

vishnuyar commented Jan 7, 2021

@sjpadgett @bradymiller Based on both of your views, This is the solution i have implemented.

Create OrganizationService which is being used by FhirOrganizationService
OrganizationService in turn uses InsuranceService and FacilityService (This should mostly act as Read Service )
Any future additions such as lab organizations can also be integrated into the Organization Service

Keeping the unique nature of these organizations Separate API services can be used to write or update these services via API

This solution doesn't require any UI changes nor creating a new table.

Let me know your views. I am open to making further modifications. UI is not my forte, I will probably need help if the solution requires UI change.

@stephenwaite
Copy link
Member

hi @vishnuyar , the new upgrade script is sql/6_0_0-to-6_1_0_upgrade.sql

@vishnuyar
Copy link
Contributor Author

hi @vishnuyar , the new upgrade script is sql/6_0_0-to-6_1_0_upgrade.sql

I thought the Coverage Resoure will be included in version 6.0.0 too.
Should I move it to sql/6_0_0-to-6_1_0_upgrade.sql ?

use Particle\Validator\Validator;
use Particle\Validator\Exception\InvalidValueException;
use OpenEMR\Common\Uuid\UuidRegistry;
use Ramsey\Uuid\Exception\InvalidUuidStringException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alphabetize

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unused statements

*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Vishnu Yarmaneni <vardhanvishnu@gmail.com>

This comment was marked as resolved.

This comment was marked as resolved.

@bradymiller
Copy link
Member

bradymiller commented Jan 8, 2021

Regarding the automated testing. I'll bring in a fix for the 8.1 syntax (#4168). It looks like the other fails are because a code change is breaking one test in PHP 7.4/8 testing environments:

Fhir Organization Rest Controller (OpenEMR\Tests\RestControllers\FHIR\FhirOrganizationRestController)
 ✔ Post
 ✔ Invalid post
 ✔ Patch
 ✔ Invalid patch
 ✘ Get one
   │
   │ Trying to access array offset on value of type bool
   │
   │ /usr/share/nginx/html/openemr/src/Validators/BaseValidator.php:115
   │ /usr/share/nginx/html/openemr/src/Services/InsuranceCompanyService.php:102
   │ /usr/share/nginx/html/openemr/src/Services/OrganizationService.php:36
   │ /usr/share/nginx/html/openemr/src/Services/FHIR/FhirOrganizationService.php:299
   │ /usr/share/nginx/html/openemr/src/RestControllers/FHIR/FhirOrganizationRestController.php:75
   │ /usr/share/nginx/html/openemr/tests/Tests/RestControllers/FHIR/FhirOrganizationRestControllerTest.php:96
   │

@@ -353,12 +353,10 @@ public function getOne($uuid)
"limit" => 1
));

if ($sqlResult) {
Copy link
Member

@bradymiller bradymiller Jan 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just checking that sqlResult is always populated with something? (or was this causing issues otherwise?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was the reason PHP7.4 and PHP8.0 were breaking.
Got it from here.
https://stackoverflow.com/questions/59674903/trying-to-access-array-offset-on-value-of-type-bool-in-php-7-4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case, would revert your changes here and do the following for the if:

if (!empty($sqlResult)) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vishnuyar , still need to address this issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

public function getOne($id)
public function getOne($uuid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migrate the old getOne function to getOneById (and change where it is called in the codebase; it is used 1 time in the codebase in receipts_by_method_report.php).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new function getOneById() , changed the same in codebase in receipts_by_method_report.php and InsuranceCompanyRestController.php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also used in
interface/billing/sl_eob_process.php
I think everywhere else is covered but i'd search code base to double check me...

@@ -60,25 +79,116 @@ public function validate($data)
return $validator->validate($data);
}

public function getOne($pid, $type)
public function getOne($uuid, $type = 'primary')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above strategy, migrate old getOne() function to getOneByPid() and change accordingly where it is called in the codebase. then you do not need to have hybrid functions that are doing very different things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the function getOneByPid(), made the change in codebase receipts_by_method_report.php and InsuranceRestController.php

}

public function getAll($pid)
public function getAll($search = array(), $isAndCondition = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note this function is not used in core codebase, so it does not need to support pid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

RestConfig::authorization_check("admin", "super");
$return = (new FhirCoverageRestController())->getOne($uuid);
RestConfig::apiLog($return);
return $return;

This comment was marked as resolved.

This comment was marked as resolved.

@bradymiller
Copy link
Member

review complete

@@ -111,8 +111,11 @@ public static function validateId($field, $table, $lookupId, $isUuid = false)
"SELECT $field FROM $table WHERE $field = ?",
array($lookupId)
);

return $result[$field] ? true : $validationResult;
if ($result) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guessing this had to be changed for php8 issues. would change this if to:

if (!empty($result[$field])) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -35,7 +35,7 @@ public function getAll()

public function getOne($iid)
{
$serviceResult = $this->insuranceCompanyService->getOne($iid);
$serviceResult = $this->insuranceCompanyService->getOneById($iid);
Copy link
Member

@bradymiller bradymiller Jan 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest controllers should not be changed (the rest endpoints will use uuid then)
Just need to ensure all the other placed in codebase that use the service are changed
(grep insuranceCompanyService and change the getOne to getOneById where used outside fhir/rest)

Copy link
Member

@bradymiller bradymiller Jan 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just checked and otherwise looks good in codebase (just need to change this back to getOne() )
And then need to update lines 1479 and 1484 in API_README.md to show use of uuid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, that is a put. agree best thing to do here is to keep as is (changing to uuid for this restcontroller will require a bunch more more). so keep the getOneById call :)

@@ -32,7 +32,7 @@ public function getAll($pid)

public function getOne($pid, $type)
{
$serviceResult = $this->insuranceService->getOne($pid, $type);
$serviceResult = $this->insuranceService->getOneByPid($pid, $type);
Copy link
Member

@bradymiller bradymiller Jan 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest controllers should not be changed (the rest endpoints will use uuid then)
Just need to ensure all the other placed in codebase that use the service are changed
(grep insuranceService and change the getOne to getOneByPid where used outside fhir/rest)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, this is more complicated since the endpoint takes in pid and type. let me look into that to see best strategy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO for me: see above

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, lets also keep this as is (getOneByPid). And just need to change one more instance of getOne (to getOneByPid) use in the interface/billing/sl_eob_process.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the functionname in interface/billing/sl_eob_process.php

@@ -44,6 +44,7 @@ Database Result -> Service Component -> FHIR Service Component -> Parse OpenEMR
- [FHIR API Endpoints](FHIR_README.md#fhir-endpoints)
- [Capability Statement](FHIR_README.md#capability-statement)
- [Patient](FHIR_README.md#patient-resource)
- [Coverage](FHIR_README.md#coverage-resource)

This comment was marked as resolved.

This comment was marked as resolved.

@bradymiller
Copy link
Member

review complete. just some minor things to fix.

API_README.md Outdated
@@ -162,6 +163,7 @@ This is a listing of scopes:
- `api:fhir` (user fhir which are the /fhir/ endpoints)
- `user/AllergyIntolerance.read`
- `user/CareTeam.read`
- `user/Coverage.read`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd usually let this go, but since there's another minor change to do, might as well alphabetize (place below Condition) this as well :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hoping that my next PR will have less of these kind of mistakes :)

@bradymiller
Copy link
Member

2 more very minor things to address and then this PR is ready :)

@bradymiller
Copy link
Member

hi @vishnuyar , Code looks great and bringing in. Thanks for the improvements! -brady

@bradymiller bradymiller merged commit bc97754 into openemr:master Jan 12, 2021
@vishnuyar vishnuyar deleted the coverage branch January 14, 2021 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FHIR Coverage Resource
4 participants