using OemrUI class in Fees > Fee Sheet, Billing, Payment, Checkout, Batch Payments...
[openemr.git] / services / InsuranceCompanyService.php
blob5eb3f2ee7591b68959854689a50b8ce37f26e17f
1 <?php
2 /**
3 * InsuranceCompanyService
5 * @package OpenEMR
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,";
47 $sql .= " i.name,";
48 $sql .= " i.attn,";
49 $sql .= " i.cms_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,";
55 $sql .= " a.line1,";
56 $sql .= " a.line2,";
57 $sql .= " a.city,";
58 $sql .= " a.state,";
59 $sql .= " a.zip,";
60 $sql .= " a.country";
61 $sql .= " FROM insurance_companies i";
62 $sql .= " JOIN addresses a ON i.id = a.foreign_id";
64 $statementResults = sqlStatement($sql);
66 $results = array();
67 while ($row = sqlFetchArray($statementResults)) {
68 array_push($results, $row);
71 return $results;
74 public function getInsuranceTypes()
76 return array(
77 1 => xl('Other HCFA'),
78 2 => xl('Medicare Part B'),
79 3 => xl('Medicaid'),
80 4 => xl('ChampUSVA'),
81 5 => xl('ChampUS'),
82 6 => xl('Blue Cross Blue Shield'),
83 7 => xl('FECA'),
84 8 => xl('Self Pay'),
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'),
99 23 => xl('Title V'),
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");
110 return $id['id'];
113 public function insert($data)
115 $freshId = $this->getFreshId();
117 $sql = " INSERT INTO insurance_companies SET";
118 $sql .= " id=?,";
119 $sql .= " name=?,";
120 $sql .= " attn=?,";
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(
128 $sql,
129 array(
130 $freshId,
131 $data["name"],
132 $data["attn"],
133 $data["cms_id"],
134 $data["ins_type_code"],
135 $data["x12_receiver_id"],
136 $data["x12_default_partner_id"],
137 $data["alt_cms_id"]
141 if (!$insuranceResults) {
142 return false;
145 $addressesResults = $this->addressService->insert($data, $freshId);
147 if (!$addressesResults) {
148 return false;
151 return $freshId;
154 public function update($data, $iid)
156 $sql = " UPDATE insurance_companies SET";
157 $sql .= " name=?,";
158 $sql .= " attn=?,";
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(
167 $sql,
168 array(
169 $data["name"],
170 $data["attn"],
171 $data["cms_id"],
172 $data["ins_type_code"],
173 $data["x12_receiver_id"],
174 $data["x12_default_partner_id"],
175 $data["alt_cms_id"],
176 $iid
180 if (!$insuranceResults) {
181 return false;
184 $addressesResults = $this->addressService->update($data, $iid);
186 if (!$addressesResults) {
187 return false;
190 return $iid;