Created
October 20, 2012 07:42
-
-
Save tareko/3922543 to your computer and use it in GitHub Desktop.
Creating the array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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[$i] = $this->parseFields($row, 'HEB'); | |
| } | |
| if (substr($row, 0, 3) == 'HEH') { | |
| $j = $j + 1; | |
| $data[$i][$j] = $this->parseFields($row, 'HEH'); | |
| } | |
| if (substr($row, 0, 3) == 'HER') { | |
| $data[$i][$j]['Items'][] = $this->parseFields($row, 'HER'); | |
| } | |
| if (substr($row, 0, 3) == 'HET') { | |
| $data[$i][$j]['BillingsItems'][] = $this->parseFields($row, 'HET'); | |
| if (substr($row, 41, 1) != ' ') { | |
| $data[$i][$j]['BillingsItems'][] = $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']); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment