public
Created

Billing model

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
<?php
App::uses('AppModel', 'Model');
/**
* Billing Model
*
* @property BillingsItem $BillingsItem
*/
class Billing extends AppModel {
 
/**
* Associations
* @var unknown_type
*/
public $hasMany = array(
'BillingsItem' => array(
'className' => 'BillingsItem',
'foreignKey' => 'billing_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'patient_birthdate' => array(
'date' => array(
'rule' => array('date'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
 
'payment_program' => array(
'notempty' => array(
'rule' => array('notempty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => true,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'payee' => array(
'notempty' => array(
'rule' => array('notempty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => true,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
/*
'referring' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
'allowEmpty' => true,
'required' => false,
//'last' => true, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
*/
);
public function beforeValidate($options = array()) {
if (!empty($this->data['Billing']['patient_birthdate'])) {
$this->data['Billing']['patient_birthdate'] = $this->dateFormatBeforeSave($this->data['Billing']['patient_birthdate']);
}
return true;
}
public function dateFormatBeforeSave($dateString) {
return date('Y-m-d', strtotime($dateString));
}
/**
* Imports MOHLTC file into DB
* See MOHLTC Technical specifications: Interface to Health Care Systems
* http://health.gov.on.ca/english/providers/pub/ohip/tech_specific/tech_specific_mn.html
*
* Special thanks to Tigrang for some amazing help!
*
* @param string $filename
*/
function import ($filename) {
// Set the filename to read from
$filename = $filename;
// Open the file
if (!$file = fopen($filename, 'r')) {
return false;
}
// Start parsing for health encounters
$data = array();
$i = 0;
$j = 0;
while($row = fgets($file)) {
if (substr($row, 0, 3) == 'HEB') {
$i = $i + 1;
$data_provider[$i] = $this->parseFields($row, 'HEB');
}
if (substr($row, 0, 3) == 'HEH') {
$j = $j + 1;
$data[$j]['Billing'] = $this->parseFields($row, 'HEH');
$data[$j]['Billing']['healthcare_provider'] = $data_provider[$i]['healthcare_provider'];
}
if (substr($row, 0, 3) == 'HER') {
$data[$j]['BillingsItem'][] = $this->parseFields($row, 'HER');
}
if (substr($row, 0, 3) == 'HET') {
$data[$j]['BillingsItem'][] = $this->parseFields($row, 'HET');
if (substr($row, 41, 1) != ' ') {
$data[$j]['BillingsItem'][] = $this->parseFields(substr($row, 38), 'HET');
}
}
}
return $data;
}
function parseFields($row, $section) {
$schema = array(
'HEB' => array(
'healthcare_provider' => array(
'start' => 29,
'length' => 6)
),
'HEH' => array(
'patient_birthdate' => array(
'start' => 15,
'length' => 8),
'payment_program' => array(
'start' => 31,
'length' => 3),
'payee' => array(
'start' => 34,
'length' => 1),
'referring' => array(
'start' => 35,
'length' => 6),
),
'HER' => array(
'field_name' => array(
'start' => 1,
'length' => 2,)
),
'HET' => array(
'service_code' => array(
'start' => 3,
'length' => 5),
'fee_submitted' => array(
'start' => 10,
'length' => 6),
'number_of_services' => array(
'start' => 16,
'length' => 2),
'service_date' => array(
'start' => 18,
'length' => 8)
),
);
$fields = array();
foreach($schema[$section] as $field => $opts) {
$fields[$field] = substr($row, $opts['start'], $opts['length']);
}
return $fields;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.