3 * InsuranceCompanyService
6 * @link http://www.open-emr.org
7 * @author Matthew Vita <matthewvita48@gmail.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
10 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 namespace OpenEMR\Services
;
17 use Particle\Validator\Validator
;
18 use OpenEMR\Services\AddressService
;
20 class InsuranceCompanyService
22 private $addressService = null;
24 public function __construct()
26 $this->addressService
= new AddressService();
29 public function validate($insuranceCompany)
31 $validator = new Validator();
33 $validator->required('name')->lengthBetween(2, 255);
34 $validator->optional('attn')->lengthBetween(2, 255);
35 $validator->optional('cms_id')->lengthBetween(2, 15);
36 $validator->optional('alt_cms_id')->lengthBetween(2, 15);
37 $validator->optional('ins_type_code')->numeric();
38 $validator->optional('x12_receiver_id')->lengthBetween(2, 25);
39 $validator->optional('x12_default_partner_id')->numeric();
41 return $validator->validate($insuranceCompany);
44 public function getAll()
46 $sql = " SELECT i.id,";
50 $sql .= " i.ins_type_code,";
51 $sql .= " i.x12_receiver_id,";
52 $sql .= " i.x12_default_partner_id,";
53 $sql .= " i.alt_cms_id,";
54 $sql .= " i.inactive,";
61 $sql .= " FROM insurance_companies i";
62 $sql .= " JOIN addresses a ON i.id = a.foreign_id";
64 $statementResults = sqlStatement($sql);
67 while ($row = sqlFetchArray($statementResults)) {
68 array_push($results, $row);
74 public function getInsuranceTypes()
77 1 => xl('Other HCFA'),
78 2 => xl('Medicare Part B'),
82 6 => xl('Blue Cross Blue Shield'),
85 9 => xl('Central Certification'),
86 10 => xl('Other Non-Federal Programs'),
87 11 => xl('Preferred Provider Organization (PPO)'),
88 12 => xl('Point of Service (POS)'),
89 13 => xl('Exclusive Provider Organization (EPO)'),
90 14 => xl('Indemnity Insurance'),
91 15 => xl('Health Maintenance Organization (HMO) Medicare Risk'),
92 16 => xl('Automobile Medical'),
93 17 => xl('Commercial Insurance Co.'),
94 18 => xl('Disability'),
95 19 => xl('Health Maintenance Organization'),
96 20 => xl('Liability'),
97 21 => xl('Liability Medical'),
98 22 => xl('Other Federal Program'),
100 24 => xl('Veterans Administration Plan'),
101 25 => xl('Workers Compensation Health Plan'),
102 26 => xl('Mutually Defined')
106 public function getFreshId()
108 $id = sqlQuery("SELECT MAX(id)+1 AS id FROM insurance_companies");
113 public function insert($data)
115 $freshId = $this->getFreshId();
117 $sql = " INSERT INTO insurance_companies SET";
121 $sql .= " cms_id=?,";
122 $sql .= " ins_type_code=?,";
123 $sql .= " x12_receiver_id=?,";
124 $sql .= " x12_default_partner_id=?,";
125 $sql .= " alt_cms_id=?";
127 $insuranceResults = sqlInsert(
134 $data["ins_type_code"],
135 $data["x12_receiver_id"],
136 $data["x12_default_partner_id"],
141 if (!$insuranceResults) {
145 $addressesResults = $this->addressService
->insert($data, $freshId);
147 if (!$addressesResults) {
154 public function update($data, $iid)
156 $sql = " UPDATE insurance_companies SET";
159 $sql .= " cms_id=?,";
160 $sql .= " ins_type_code=?,";
161 $sql .= " x12_receiver_id=?,";
162 $sql .= " x12_default_partner_id=?,";
163 $sql .= " alt_cms_id=?";
164 $sql .= " WHERE id = ?";
166 $insuranceResults = sqlStatement(
172 $data["ins_type_code"],
173 $data["x12_receiver_id"],
174 $data["x12_default_partner_id"],
180 if (!$insuranceResults) {
184 $addressesResults = $this->addressService
->update($data, $iid);
186 if (!$addressesResults) {