Fixed errors in two regular expressions due to the lack of the /s modifier.
[openemr.git] / interface / forms / CAMOS / content_parser.php
blobcbbb0269e7704415dbcb4c400eb2462296773007
1 <?
2 include_once("../../globals.php");
3 include_once("../../../library/sql.inc");
5 //This function was copied from billing.inc and altered to support 'justify'
6 function addBilling2($encounter, $code_type, $code, $code_text, $modifier="",$units="",$fee="0.00",$justify)
8 $justify_string = '';
9 if ($justify)
11 $justify_string = implode(":",$justify).":";
13 $sql = "insert into billing (date, encounter, code_type, code, code_text, pid, authorized, user, groupname,activity,billed,provider_id,modifier,units,fee,justify) values (NOW(), '".$_SESSION['encounter']."', '$code_type', '$code', '$code_text', '".$_SESSION['pid']."', '$authorized', '" . $_SESSION['authId'] . "', '" . $_SESSION['authProvider'] . "',1,0,".$_SESSION['authUserID'].",'$modifier','$units','$fee','$justify_string')";
15 return sqlInsert($sql);
19 function content_parser($input) {
21 // parse content field
22 $content = $input;
24 // comments should really be removed in save.php
25 // $content = remove_comments($content);
27 //reduce more than two empty lines to no more than two.
28 $content = preg_replace("/([^\n]\r[^\n]){2,}/","\r\r",$content);
29 $content = preg_replace("/([^\r]\n[^\r]){2,}/","\n\n",$content);
30 $content = preg_replace("/(\r\n){2,}/","\r\n\r\n",$content);
33 return $content;
36 // implement C style comments ie remove anything between /* and */
37 function remove_comments($string_to_process) {
38 return preg_replace("/\/\*.*?\*\//s","",$string_to_process);
41 //process commands embedded in C style comments where function name is first
42 //followed by args separated by :: delimiter and nothing else
44 function process_commands(&$string_to_process, &$camos_return_data) {
46 //First, handle replace function as special case. full depth of inserts should be evaluated prior
47 //to evaluating other functions in final string assembly.
48 $replace_finished = FALSE;
49 while (!$replace_finished) {
50 if (preg_match_all("/\/\*\s*replace\s*::.*?\*\//",$string_to_process, $matches)) {
51 foreach($matches[0] as $val) {
52 $comm = preg_replace("/(\/\*)|(\*\/)/","",$val);
53 $comm_array = split('::', $comm); //array where first element is command and rest are args
54 $replacement_item = trim($comm_array[1]); //this is the item name to search for in the database. easy.
55 $replacement_text = '';
56 $query = "SELECT content FROM form_CAMOS_item WHERE item like '".$replacement_item."'";
57 $statement = sqlStatement($query);
58 if ($result = sqlFetchArray($statement)) {$replacement_text = $result['content'];}
59 $string_to_process = str_replace($val,$replacement_text,$string_to_process);
62 else {$replace_finished = TRUE;}
66 //end of special case of replace function
67 $return_value = 0;
68 $camos_return_data = array(); // to be filled with additional camos form submissions if any embedded
69 $command_array = array(); //to be filled with potential commands
70 $matches= array(); //to be filled with potential commands
71 if (!preg_match_all("/\/\*.*?\*\//s",$string_to_process, $matches)) {return $return_value;}
72 $command_array = $matches[0];
73 foreach($command_array as $val) {
74 //process each command
75 $comm = preg_replace("/(\/\*)|(\*\/)/","",$val);
76 $comm_array = split('::', $comm); //array where first element is command and rest are args
77 //Here is where we process particular commands
78 if (trim($comm_array[0])== 'billing') {
79 array_shift($comm_array); //couldn't do it in 'if' or would lose element 0 for next if
80 //insert data into the billing table, see, easy!
81 $type = trim(array_shift($comm_array));
82 $code = trim(array_shift($comm_array));
83 $text = trim(array_shift($comm_array));
84 $modifier = trim(array_shift($comm_array));
85 $units = trim(array_shift($comm_array));
86 $fee = sprintf("%01.2f",trim(array_shift($comm_array)));
87 //in function call 'addBilling' note last param is the remainder of the array. we will look for justifications here...
88 addBilling2($encounter, $type, $code, $text, $modifier,$units,$fee,$comm_array);
90 $command_count = 0;
91 if (trim($comm_array[0]) == 'camos') {
92 $command_count++;
93 //data to be submitted as separate camos forms
94 //this is for embedded prescriptions, test orders etc... usually within a soap note or something
95 //data collected here will be returned so that save.php can give it special treatment and insert
96 //into the database after the main form data is submitted so it will be in a sensible order
97 array_push($camos_return_data,
98 array("category" => trim($comm_array[1]),
99 "subcategory" => trim($comm_array[2]),
100 "item" => trim($comm_array[3]),
101 "content" => trim($comm_array[4])));
104 $string_to_process = remove_comments($string_to_process);
105 return $return_value;
107 // I was using this for debugging. touch logging, chmod 777 logging, then can use.
108 //file_put_contents('./logging',$string_to_process."\n\n*************\n\n",FILE_APPEND);//DEBUG