Openemr fix #7108 insurance edit (#7197)
commit8d6dc1cf7e24e791eaea2236c9f7a5c1a4e13e07
authorStephen Nielson <snielson@discoverandchange.com>
Fri, 2 Feb 2024 15:43:09 +0000 (2 10:43 -0500)
committerGitHub <noreply@github.com>
Fri, 2 Feb 2024 15:43:09 +0000 (2 10:43 -0500)
tree26725969c8bac6310fd7c996d286214325375a72
parent5a7dfb8cfe4c072ce37c43cd5fde4880e5527764
Openemr fix #7108 insurance edit (#7197)

* fix: load all insurances for editing

* fix for insurance until date when date end isn't set

* new ins edit script

* WIP #7108, Fixes #7107

This is a work in progress for #7108 refactoring the insurance edit
screen.  This pulls the insurance_edit screen out into twig.

It adds an enhancement to the options.inc.php screen so we can add additional
classes.

Since we now have translations on the client side, it implements a
select2 bootstrap select option that handles translations without having
to mess with the complicated php include statements that breaks twig
functionality.

I currently have the twig file rendering the entire insurance edit form.
I need to set it up so we can switch between Primary / Secondary /
Tertiary forms.

Then I need to implement saving the data as well as creating a new
insurance policy.

At that point we can implement the view functionality in the
demographics_all.php screen.

The next step is being able to add a new insurance policy

* Implemented switching of insurance types

Made it so you can switch between the tabs of the insurance types now
and they load properly.

* Refactored js controllers/service/model for CRUD

Refactored the javascript into edit/new controllers, into a service and
insurance policy model to handle data synchronization / saving in the
new / save mode.  Added initial framework for data validation with error
message displays.

* Edit/New Insurance screen ui edits

Fixed the policy dropdown to work better.

Renamed InsuranceEditController to provide more clarity

Moved DOM updates to single render loop to cleanup rendering logic.

* Fixed more bugs on new/edit screen.

* Changes to insurance REST api, validation, service

Fixed the select style issues on edit screen.  Fixed select tab order.
Fixed the policy_type not populating and the insurance provider field not
populating on edit.  Made several of the dropdowns use the select2 code for
styling / UX consistency.

Changed all insurance policy api endpoints to use patient uuid instead of pid
as that's what the code uses.

Removed the POST and PUT /api/patient/{pid}/insurance/{type} endpoint as it
never worked so we can follow REST endpoint best practices

Implemented PUT /api/patient/{puuid}/insurance/{insuranceUuid} for updating an
insurance policy.

Implemented POST /api/patient/{puuid}/insurance for creating a new insurance policy

Added ACL security checks to the insurance policy creation to match what the
insurance edit in demographics uses. POST must have patients/demo[write|addonly]
and PUT must have patients/demo[write]

Implemented a ListOptionRule that will validate against the list_options table
to make sure that the provided value exists in the list.  Its a primitive
implementation with no caching or performance optimizations and hits the
database on each go.  Wrote unit tests for this and created an
OpenEMRParticleValidator that extends the ParticleValidator in order to use
our own custom rules in the future for API validation.  Used this in an updated
CoverageValidator.

Had to modify the Validator class so we can override the internal validator
that is used.

Added copyright / descriptions everywhere.

Created InsurancePolicyTypes constant for the 837p standard policy types for
insurance policies.

Updated CCDA insurance data import process to utilize the refactored
InsuranceService class.

Changed up the InsuranceService class to validate the data in the update/insert
process to make sure we only are dealing with valid data.

Added to the rest config authorization_check for aclPermission to allow
specific ACL permissions.

* Updating phpunit to show deprecation errors.

* Fix checkstyles

* Fix Address Verification global feature

Made it so the address verification global feature works properly in the
insurance edit screen.

* Implemented insurance edit date pickers

Implemented a javascript translated version of our jquery datepicker.

Introduced language direction, date_display_format, and timezone
settings from globals into the jsGlobals array which makes it so we can
get rid of our php language translation mechanisms when working in
javascript land.

Updated the insurance policy models and saving to handle the date
pickers.  Utilized the new international locale date translation to
handle our initial date formatting settings for the date picker.

* Validation updates, javascript fixes.

Implemented validation error displays on the screen.

Implemented cache busting in the javascript files for the insurance
screen.

Updated the insurance coverage/policy required fields.

Added assetVersion to jsGlobals array.

* Add comprehensive validation on effective dates

Made it so the effective date will check against previous records to
verify that we don't violate the db unique constraint checks.

* REST endpoint for single insurance,browse function

Implemented the browse function for the edit screen policy.

REST endpoint implementation for grabbing insurance data for a single
insurance coverage policy for a patient.

* Fixed #7164, Insurance Add/Edit/Search

Made the add edit search work properly when updating an insurance
policy, creating a new one, etc.  It all funnels through the same
javascript mechanism now and populates the provider correctly.

Fixed a bug where the display name wasn't populating properly when you
enter in an insurance company as it didn't respect the globals settings
for insurance company display.

Also fixed issue #7164 by fixing up the phone number update statements.

Also includes style fixes.

* Demographics refactoring, insurance UX changes

Refactored the billing, demographics, and insurance card sections into
individual classes that we can isolate / silo for single responsibility
concerns.

Implemented a preliminary prototype of showing previous insurance
coverages that will cover patients who have lots of previous insurance
cards / insurances.

Fixed a coverage validation bug that stopped you from saving if
effective end date was empty.

Fixed an EDI270 rendering bug on the eligibility as it was returning
broken html.

Added methods to the insurance service to grab a sorted list of
insurance policies that has the current policy and the most recent
policies ordered.

* Fixed code that was commented out.

* Typo ouch

* Fix date orders of insurance history

* Insurance pagination on demographics view screen.

* Hide empty self-pay policies on demographics page

If a policy has no provider it is unassigned ie Self-Pay.  We want to
hide the policies that are self-pay for secondary/tertiary since the
primary is self-pay.

* Fix I18N date exception with value of 0000-00-00

The demographics_comprehensive_save.php will save a DOB of 0000-00-00
for the value if no insurance is provided which is a mess.  Since we
have to deal with existing data we check for the error in the formatter
and just return null if there is an invalid date.

We also catch any exceptions on the selected insurance render and output
it to the screen so at least people know something is broken.

* Make validation errors for select2 display

The error highlights were not showing on the select2 dropdown lists.  We
needed to add custom styles on those since it uses a different element
for all of that.

* Validator fix relationship checks. API docs.

Updated the API docs for the insurance endpoints to include the
validation checks / constraints.

Saw that the original insurance edit screen had validation checks on the
subscriber relationship.  Added checks to make sure if the relationship
is self that the patient name and SSN are correct.  Also if the
relationship is not self that the subscriber does not have the same SSN
as the patient.

* Implemented $swap-insurance operation

Reimplemented the swap insurance functionality in the UX and fixed a
number of validation problems and edge cases that would blow up the
insurance save if the effective date for the policy was not set up
properly.

Built an API rest endpoint for $swap-insurance in order to handle the
insurance piece.  Was going to do a FHIR operation here but our FHIR
coverage implementation is woefully inadequate and will need to be
bumped to another PR.

Added some additional helper methods to processing result also.

* Fix PSR problems

* New Policy curr insurance save effective date

Made it so the new policy saves the current insurance effective date if
it was selected.  Apparently missed that piece.

Also added in the datepicker selector for the effective end date to
set the current policy.

* clean up todos

* Remove old insurance code, fix styles.

Removed the old insurance code and fixed the styles on the insurance
page.

* Remove insurance from demographics page

Since insurance editing is now its own section we can safely remove it
from the full demographics edit page.

* Unsaved changes check, fix jquery events

The jquery select2 and jquery datepicker were breaking because they were
not being cleaned up everytime the dom re-rendered on the page. Added
cleanup process that cleans up the events everytime the render()
function is called.

Implemented the unsaved changes check if the user attempts to leave the
screen and the selected policy has changed it will ask the user to
confirm they want to cancel the changes.

* Fix populating insurance search screen

The search screen for the insurance company popup would not actually
open up the correct provider when selected.  Fixed that bug.

* Implemented tabbing for insurance policy edit

The tab order was not working when the screen would render.  This was
because we blow away all of the DOM elements and re-render them.  We
needed to track which element was last focused and handle the tab order
on the render.

* Remove unused code.

* Fix middle name length validation

* Remove autofill for date values.

We don't want to show previous values on the date pickers as it messes
up the UX.

* Populate Subscriber Self Rel., Fixes #7188

Made it so that selecting 'Self' for the Insurance Policy Subscriber Relation
will now populate the insurance policy fields with the current patient
as well as the current patient's employer information.

Added a REST API endpoint for /api/patient/{puuid}/employer to grab the
employer data.  This includes corresponding REST controllers, services,
routes, etc.

Fixes #7188 base service join clause fix.

* Fix self relationship country code population.

The patient country code was not populating because its called
country_code in patient_data instead of country.  Fixing this issue.

* Fix insurance policy search order.

We want policies that are still active but set to terminate in the
future (longer than today) to show up first, even if there is a policy
that is current (IE has no termination date).

We changed the sort order to be the following
- We sort by policies with an end date in the future or no end
date(NULL)
- THEN we sort by policies that have an end date that is NOT null and
the end date is in the future
- THEN we sort by the policies effective date with newer dates in front (NULL being at the front)
- THEN we sort by the policies effective end date with newer dates in
front (NULL being at the front)
- THEN we sort by the policy number with a case sensitive ordering.

* Prevent double event firings on new policy setup.

If you go to the new policy screen and switch back to the regular screen
it sets up the events for the save button, window messages, etc again.
Fixed it so the events clear when we switch screens and put back when we
come back to the edit screen.

* Fix update copy policy id for new screen.

Was not updating the copy policy id for the new screen. This meant only
the first policy chosen was used as the copy.

* Update copyright notices.

Work was commissioned by Care Management Solutions, Inc.  Needed to
update the copyright messages to have the correct copyright notice.

* Fix insurance sort order (again...)

Had the historical insurance not working because the order was being
reversed.

* Fix javascript style errors.

* Fix translation errors

* Fix php style issues.

* More JS fixes... urgh

* Fix escaping, translations.

* Remove todo as testing passed.

---------

Co-authored-by: stephen waite <stephen.waite@cmsvt.com>
57 files changed:
_rest_config.php
_rest_routes.inc.php
config/config.yaml
interface/main/tabs/main.php
interface/patient_file/summary/browse.php
interface/patient_file/summary/demographics.php
interface/patient_file/summary/demographics_full.php
interface/patient_file/summary/demographics_save.php
interface/patient_file/summary/insurance_edit.php [new file with mode: 0644]
interface/practice/ins_list.php
interface/practice/ins_search.php
library/classes/InsuranceCompany.class.php
library/formatting.inc.php
library/js/oeUI/Error/ValidationError.js [new file with mode: 0644]
library/js/oeUI/insurance/EditPolicyScreenController.js [new file with mode: 0644]
library/js/oeUI/insurance/InsuranceEditMainController.js [new file with mode: 0644]
library/js/oeUI/insurance/InsurancePolicyModel.js [new file with mode: 0644]
library/js/oeUI/insurance/InsurancePolicyService.js [new file with mode: 0644]
library/js/oeUI/insurance/NewPolicyScreenController.js [new file with mode: 0644]
library/js/vendors/validate/validate_modified.js
library/js/xl/formatting.js [new file with mode: 0644]
library/js/xl/jquery-datetimepicker-2-5-4-translated.js [new file with mode: 0644]
library/js/xl/select2-translated.js [new file with mode: 0644]
library/options.inc.php
library/patient.inc.php
phpunit.xml
src/Billing/EDI270.php
src/Billing/InsurancePolicyTypes.php [new file with mode: 0644]
src/Common/Database/QueryUtils.php
src/Common/Http/HttpRestRequest.php
src/Common/Twig/TwigExtension.php
src/Common/Utils/CacheUtils.php
src/Events/Patient/Summary/Card/CardModel.php
src/Patient/Cards/BillingViewCard.php [new file with mode: 0644]
src/Patient/Cards/DemographicsViewCard.php [new file with mode: 0644]
src/Patient/Cards/InsuranceViewCard.php [new file with mode: 0644]
src/RestControllers/EmployerRestController.php [new file with mode: 0644]
src/RestControllers/InsuranceRestController.php
src/Services/BaseService.php
src/Services/Cda/CdaTemplateImportDispose.php
src/Services/EmployerService.php [new file with mode: 0644]
src/Services/InsuranceCompanyService.php
src/Services/InsuranceService.php
src/Services/PhoneNumberService.php
src/Validators/BaseValidator.php
src/Validators/CoverageValidator.php
src/Validators/OpenEMRChain.php [new file with mode: 0644]
src/Validators/OpenEMRParticleValidator.php [new file with mode: 0644]
src/Validators/ProcessingResult.php
src/Validators/Rules/ListOptionRule.php [new file with mode: 0644]
swagger/openemr-api.yaml
templates/patient/card/insurance.html.twig
templates/patient/insurance/_insurance_edit_screen_edit.html.twig [new file with mode: 0644]
templates/patient/insurance/_insurance_edit_screen_new.html.twig [new file with mode: 0644]
templates/patient/insurance/_insurance_validation_errors.html.twig [new file with mode: 0644]
templates/patient/insurance/insurance_edit.html.twig [new file with mode: 0644]
tests/Tests/Validators/Rules/ListOptionRuleTest.php [new file with mode: 0644]