diff --git a/controllers/C_InsuranceCompany.class.php b/controllers/C_InsuranceCompany.class.php
index bd0a3da9224..6c08923fddb 100644
--- a/controllers/C_InsuranceCompany.class.php
+++ b/controllers/C_InsuranceCompany.class.php
@@ -1,5 +1,8 @@
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);
}
diff --git a/library/classes/InsuranceCompany.class.php b/library/classes/InsuranceCompany.class.php
index 0545e9ac895..3ceb475015a 100644
--- a/library/classes/InsuranceCompany.class.php
+++ b/library/classes/InsuranceCompany.class.php
@@ -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 = "";
@@ -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 = "")
@@ -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 . "
";
- $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;
}
diff --git a/src/Services/InsuranceCompanyService.php b/src/Services/InsuranceCompanyService.php
index 484c45006d7..037f26aa7ca 100644
--- a/src/Services/InsuranceCompanyService.php
+++ b/src/Services/InsuranceCompanyService.php
@@ -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.
@@ -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(
@@ -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 {
@@ -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 = [];
@@ -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 = [];
@@ -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(
@@ -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=?,";
diff --git a/templates/insurance_companies/general_list.html.twig b/templates/insurance_companies/general_list.html.twig
new file mode 100644
index 00000000000..89fb34ca928
--- /dev/null
+++ b/templates/insurance_companies/general_list.html.twig
@@ -0,0 +1,62 @@
+
+
{{ 'Name'|xlt}} | +{{ 'Address'|xlt}} | +{{ 'City, State, ZIP'|xlt}} | +{{ 'Phone'|xlt}} | +{{ 'Fax'|xlt}} | +{{ 'Payer ID'|xlt}} | +{{ 'Default X12 Partner'|xlt}} | +{{ 'Deactivated'|xlt}} | +
---|---|---|---|---|---|---|---|
+ + {{insurancecompany.name|text}} + + | +{{insurancecompany.line1|text}} {{insurancecompany.line2|text}} | +{{insurancecompany.city|text}} {{insurancecompany.state|upper|text}} {{insurancecompany.zip|text}} | +{{insurancecompany.phone|text}} | +{{insurancecompany.fax|text}} | +{{insurancecompany.cms_id|text}} | +{{insurancecompany.x12_default_partner_name|text}} | +{% if insurancecompany.inactive == 1%}{{ 'Yes'|xlt}}{% endif %} | +
{{ 'No Insurance Companies Found'|xlt}} | + ++ | + | + | + | + | + | + |