Skip to content

Commit

Permalink
Fixes openemr#7224, openemr#7217 insurance company changes (openemr#7225
Browse files Browse the repository at this point in the history
)

* Fixes openemr#7224, openemr#7217 insurance company changes

Fixed the list loading taking forever on the insurance company list.
This fixes openemr#7224.

Had a bug in the fix for openemr#7217 so this fixes that as well. Wasn't
actually replacing the insurance id.

* Remove about title tag

* Change escaping function on webroot
  • Loading branch information
adunsulag authored Feb 14, 2024
1 parent 47596c6 commit b4fdaef
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 18 deletions.
36 changes: 34 additions & 2 deletions controllers/C_InsuranceCompany.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

use OpenEMR\Common\Twig\TwigContainer;
use OpenEMR\Services\InsuranceCompanyService;

class C_InsuranceCompany extends Controller
{
var $template_mod;
Expand Down Expand Up @@ -42,10 +45,39 @@ public function edit_action($id = "", $patient_id = "", $p_obj = null)

public function list_action()
{
$twig = new TwigContainer(null, $GLOBALS['kernel']);

$this->assign("icompanies", $this->InsuranceCompany->insurance_companies_factory());
$insuranceCompanyService = new InsuranceCompanyService();
$results = $insuranceCompanyService->search([]);
$iCompanies = [];
if ($results->hasData()) {
foreach ($results->getData() as $record) {
$company = [
'id' => $record['id'],
'name' => $record['name'],
'line1' => $record['line1'],
'line2' => $record['line2'],
'city' => $record['city'],
'state' => $record['state'],
'zip' => $record['zip'],
'phone' => $record['work_number'],
'fax' => $record['fax_number'],
'cms_id' => $record['cms_id'],
'x12_default_partner_name' => $record['x12_default_partner_name'],
'inactive' => $record['inactive']
];
$iCompanies[] = $company;
}
usort($iCompanies, function ($a, $b) {
return strcasecmp($a['name'], $b['name']);
});
}
$templateVars = [
'CURRENT_ACTION' => $GLOBALS['webroot'] . "/controller.php?" . "practice_settings&insurance_company&"
,'icompanies' => $iCompanies
];

return $this->fetch($GLOBALS['template_dir'] . "insurance_companies/" . $this->template_mod . "_list.html");
return $twig->getTwig()->render('insurance_companies/general_list.html.twig', $templateVars);
}


Expand Down
44 changes: 29 additions & 15 deletions library/classes/InsuranceCompany.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class InsuranceCompany extends ORDataObject
/**
* Constructor sets all Insurance Company attributes to their default value
*/
public function __construct($id = "", $prefix = "")
public function __construct($id = "", $prefix = "", InsuranceCompanyService $insuranceCompanyService = null)
{
$this->id = $id;
$this->name = "";
Expand All @@ -86,15 +86,19 @@ public function __construct($id = "", $prefix = "")
$fax->set_type(TYPE_FAX);
$this->address = new Address();
$this->phone_numbers = array($phone, $fax);
$this->InsuranceCompany = new InsuranceCompanyService();
$this->ins_type_code_array = $this->InsuranceCompany->getInsuranceTypes();
if ($insuranceCompanyService === null) {
$this->InsuranceCompany = new InsuranceCompanyService();
} else {
$this->InsuranceCompany = $insuranceCompanyService;
}
$this->ins_type_code_array = $this->InsuranceCompany->getInsuranceTypesCached();
$this->ins_claim_type_array = $this->InsuranceCompany->getInsuranceClaimTypes();
if ($id != "") {
$this->populate();
}

$this->X12Partner = new X12Partner();
$this->cqm_sop_array = $this->InsuranceCompany->getInsuranceCqmSop();
$this->cqm_sop_array = $this->InsuranceCompany->getInsuranceCqmSopCached();
}

public function set_id($id = "")
Expand Down Expand Up @@ -330,19 +334,29 @@ public function persist()

public function insurance_companies_factory()
{
$p = new InsuranceCompany();
$insuranceCompanyService = new InsuranceCompanyService();
$icompanies = array();
$sql = "SELECT p.id, a.city " .
"FROM " . escape_table_name($p->_table) . " AS p " .
"INNER JOIN addresses as a on p.id = a.foreign_id ORDER BY name, id";

//echo $sql . "<bR />";
$results = sqlQ($sql);
//echo "sql: $sql";
//print_r($results);
while ($row = sqlFetchArray($results)) {
$icompanies[] = new InsuranceCompany($row['id']);

$listAll = $insuranceCompanyService->search([]);
if ($listAll->hasData()) {
$data = $listAll->getData();
foreach ($data as $record) {
// we pass in the service array so we don't recreate it each time
$company = new InsuranceCompany("", "", $insuranceCompanyService);
$company->populate_array($record);
if (!empty($record['work_id'])) {
$company->set_phone($record['work_number']);
}
if (!empty($record['fax_id'])) {
$company->set_fax($record['fax_number']);
}
$icompanies[] = $company;
}
}
// sort by name since we don't know that the sql query will return them in the correct order
usort($icompanies, function ($a, $b) {
return strcasecmp($a->name, $b->name);
});

return $icompanies;
}
Expand Down
50 changes: 49 additions & 1 deletion src/Services/InsuranceCompanyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ class InsuranceCompanyService extends BaseService
public const TYPE_FAX = 5;
public const TYPE_WORK = 2;

/**
* @var null | array $cqm_sops cached CQM SOPS
*/
private $cqm_sops = null;

/**
* @var null | array $types cached insurance types
*/
private $types = null;

/**
* @var null | array $claim_types cached claim types
*/
private $claim_types = null;


/**
* Default constructor.
Expand Down Expand Up @@ -115,6 +130,7 @@ public function search($search, $isAndCondition = true)
$sql .= " i.ins_type_code,";
$sql .= " i.x12_receiver_id,";
$sql .= " i.x12_default_partner_id,";
$sql .= " x12.x12_default_partner_name,";
$sql .= " i.alt_cms_id,";
$sql .= " i.inactive,work_number.work_id,fax_number.fax_id,";
$sql .= " CONCAT(
Expand Down Expand Up @@ -151,6 +167,10 @@ public function search($search, $isAndCondition = true)
SELECT id AS fax_id,foreign_id,country_code, area_code, prefix, number
FROM phone_numbers WHERE number IS NOT NULL AND type = " . self::TYPE_FAX . "
) fax_number ON i.id = fax_number.foreign_id";
$sql .= " LEFT JOIN (
SELECT id AS x12_default_partner_id, name AS x12_default_partner_name
FROM x12_partners
) x12 ON i.x12_default_partner_id = x12.x12_default_partner_id";

$processingResult = new ProcessingResult();
try {
Expand Down Expand Up @@ -250,6 +270,16 @@ public function getOne($uuid): ProcessingResult
return $this->getAll(['uuid' => $uuid]);
}


public function getInsuranceTypesCached()
{
if ($this->types !== null) {
return $this->types;
}
$this->types = $this->getInsuranceTypes();
return $this->types;
}

public function getInsuranceTypes()
{
$types = [];
Expand All @@ -262,6 +292,15 @@ public function getInsuranceTypes()
return $types;
}

public function getInsuranceClaimTypesCached()
{
if ($this->claim_types !== null) {
return $this->claim_types;
}
$this->claim_types = $this->getInsuranceClaimTypes();
return $this->claim_types;
}

public function getInsuranceClaimTypes()
{
$claim_types = [];
Expand All @@ -274,6 +313,15 @@ public function getInsuranceClaimTypes()
return $claim_types;
}

public function getInsuranceCqmSopCached()
{
if ($this->cqm_sops !== null) {
return $this->cqm_sops;
}
$this->cqm_sops = $this->getInsuranceCqmSop();
return $this->cqm_sops;
}

public function getInsuranceCqmSop()
{
$cqm_sop = sqlStatement(
Expand All @@ -296,7 +344,7 @@ public function insert($data)
if (empty($data["id"])) {
$data["id"] = generate_id();
}
$freshId = generate_id();
$freshId = $data['id'];

$sql = " INSERT INTO insurance_companies SET";
$sql .= " id=?,";
Expand Down
62 changes: 62 additions & 0 deletions templates/insurance_companies/general_list.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<html>
<head>
{{ setupHeader(['common','datatables','datatables-colreorder','datatables-dt','datatables-bs']) }}
<title>{{ "Insurance Companies"|xlt }} {{ applicationTitle|text }}</title>
</head>
<body>
<a href="{{webroot|attr}}/controller.php?practice_settings&insurance_company&action=edit" onclick="top.restoreSession()" class="btn btn-secondary btn-add">{{'Add a Company'|xlt}}</a>
<div class="table-responsive pt-3">
<table class="table table-striped" id="insurance">
<thead>
<tr>
<th>{{ 'Name'|xlt}}</th>
<th>{{ 'Address'|xlt}}</th>
<th>{{ 'City, State, ZIP'|xlt}}</th>
<th>{{ 'Phone'|xlt}}</th>
<th>{{ 'Fax'|xlt}}</th>
<th>{{ 'Payer ID'|xlt}}</th>
<th>{{ 'Default X12 Partner'|xlt}}</th>
<th>{{ 'Deactivated'|xlt}}</th>
</tr>
</thead>
<tbody>
{% if icompanies|length > 0 %}
{% for insurancecompany in icompanies %}
<tr>
<td>
<a href="{{webroot|attr_url}}/controller.php?practice_settings&insurance_company&action=edit&id={{insurancecompany.id|attr_url}}" onclick="top.restoreSession()">
{{insurancecompany.name|text}}
</a>
</td>
<td>{{insurancecompany.line1|text}} {{insurancecompany.line2|text}}&nbsp;</td>
<td>{{insurancecompany.city|text}} {{insurancecompany.state|upper|text}} {{insurancecompany.zip|text}}&nbsp;</td>
<td>{{insurancecompany.phone|text}}&nbsp;</td>
<td>{{insurancecompany.fax|text}}&nbsp;</td>
<td>{{insurancecompany.cms_id|text}}&nbsp;</td>
<td>{{insurancecompany.x12_default_partner_name|text}}&nbsp;</td>
<td>{% if insurancecompany.inactive == 1%}{{ 'Yes'|xlt}}{% endif %}&nbsp;</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td>{{ 'No Insurance Companies Found'|xlt}}</td>
<!-- DataTables requires the number of cols in the table header match the table body,
https://datatables.net/manual/tech-notes/18 -->
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
{% endif %}
</tbody>
</table>
</div>
<script>
$(document).ready(function () {
$('#insurance').DataTable();
});
</script>
</body></html>

0 comments on commit b4fdaef

Please sign in to comment.