<?php include 'settings.php';
  $fn = $_GET['fn']; $fn = htmlspecialchars($fn);
  $search = $_GET['search']; $search = rawurlencode($search);
  switch ($fn) {
    case "list"getit("localhost:8090/surg/list"); break;
    case "patient"getit("localhost:8090/surg/patient/" . $search); break;
    case "provider"getit("localhost:8090/surg/provider/" . $search); break;
    case "procedure"getit("localhost:8090/surg/procedure/" . $search); break;
    case "doit":
      logit("app_surgerysubmit");   
      $REQUEST = $_POST['REQUEST'];
      $REQUEST = rawurlencode($REQUEST);
      $url="http://localhost:8090/surg/do";
      $command = "curl -X POST -H \"Content-Type: text/plain\" -d '$REQUEST' '$url'";
      system($command);
      break;    
    default:
      logit("app_surgery"); ?>
<!DOCTYPE html>
<head>
  <title>Surgery File Demo</title>
  <link rel="icon" type="image/png" href="favicon.png">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
<script language=JavaScript>
 // Retrieve Static List data and Load into Select Options
function RetrieveStaticList()
  {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function()
    {
    if (this.readyState == 4 && this.status == 200)
      {
      var txt = this.responseText;
      var obj = JSON.parse(txt);
      LoadStaticOptions(obj.F130FP09"F130FP09");
      LoadStaticOptions(obj.F130FP04"F130FP04");
      LoadStaticOptions(obj.F130F638"F130F638");
      LoadStaticOptions(obj.F130FP013"F130FP013");
      LoadStaticOptions(obj.F130FP011"F130FP011");
      LoadStaticOptions(obj.F130FP03"F130FP03");
      LoadStaticOptions(obj.F130FP035"F130FP035");
      LoadStaticOptions(obj.F130F661"F130F661");
      LoadStaticOptions(obj.F130FP43"F130FP43");
      LoadStaticOptions(obj.F130F1P01"F130F1P01");
      LoadStaticOptions(obj.F130F1P035"F130F1P035");
      }
    }
  xhttp.open("GET""surgery.php?fn=list");
  xhttp.send();
  }
function LoadStaticOptions(FieldObjectFieldName)
  {
  var x = document.getElementById(FieldName); for (var key in FieldObject)
    { var option = document.createElement("option"); option.text = FieldObject[key].EXToption.value = FieldObject[key].INTx.add(option); }
  }

// Search for List data and Load results into the Select Options
function DynamicLoad(searchFieldNamefnb)
  {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function()
    {
    if (this.readyState == 4 && this.status == 200)
      {
      var txt = this.responseText;
      var obj = JSON.parse(txt);
      var x = document.getElementById(FieldName + "LIST");
      while (x.length > 0) { x.remove(0); }
      var option = document.createElement("option"); option.text = ''option.value=''x.add(option);
      if (FieldName == 'F130F999')
        { for (var key in obj) { var option = document.createElement("option"); option.text = key + " - " + obj[key].EXToption.value = obj[key].INTx.add(option); } }
      else
        { for (var key in obj) { var option = document.createElement("option"); option.text = obj[key].EXToption.value = obj[key].INTx.add(option); } }
      x.style.display='block';
}
}
  xhttp.open("GET""surgery.php?fn=" + fnb + "&search=" + search);
  xhttp.send();
  }
function REHIDE(selTagFieldName)
  {
  document.getElementById(FieldName + "LIST").style.display='none';
  document.getElementById(FieldName).value = selTag.options[selTag.selectedIndex].text;
  document.getElementById(FieldName + "IEN").value = selTag.options[selTag.selectedIndex].value;
  }

// Keep the JSON example iframe up-to-date.
function updatejson()
  {
  requesttmp='{' + "\n";
  requesttmp=requesttmp + '"F130-F.01":"' + document.getElementById("F130FP01IEN").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F.09":"' + document.getElementById("F130FP09").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F.14":"' + document.getElementById("F130FP14IEN").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F.164":"' + document.getElementById("F130FP164IEN").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F.04":"' + document.getElementById("F130FP04").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F26":"' + document.getElementById("F130F26").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F33":"' + document.getElementById("F130F33").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F638":"' + document.getElementById("F130F638").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F.013":"' + document.getElementById("F130FP013").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F27":"' + document.getElementById("F130F27").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F999":"' + document.getElementById("F130F999IEN").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F.011":"' + document.getElementById("F130FP011").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F.03":"' + document.getElementById("F130FP03").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F.035":"' + document.getElementById("F130FP035").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F661":"' + document.getElementById("F130F661").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F.43":"' + document.getElementById("F130FP43").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F1.01":"' + document.getElementById("F130F1P01").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F1.035":"' + document.getElementById("F130F1P035").value + '",' + "\n";
  requesttmp=requesttmp + '"F130-F23":"' + document.getElementById("F130F23").value + '"' + "\n";
  requesttmp=requesttmp + '}'
  document.getElementById("REQUEST").value=requesttmp;
  }

// Resize iFrames to fit the browser window.
function resizeIframes()
  {
  document.getElementById("RESPVIEW").height=275;
  document.getElementById("RESPVIEW").width=window.innerWidth*.95;
  document.getElementById("REQUEST").rows=18;
  document.getElementById("REQUEST").cols=20;
  }
</script>
 <style>
    body { font-size:15px; }
    textarea { width100%height400pxfont-size:15px; }
    input[type=text], select { width100%padding2px 2pxmargin1px 0displayinline-blockborder1px solid #cccborder-radius4pxbox-sizingborder-box; }
  </style>
 </head>
 
<body onresize="resizeIframes()" onload="RetrieveStaticList()">
  <table width=100%>
    <tr><td>
  <form>
    <table width=100%>

      <!-- Patient: (130,.01) Pointer to Patient File #2 -->
        <tr><td width="230px"><label for="F130FP01">Patient: </label>
            <input type="hidden" id="F130FP01IEN" name="F130FP01IEN"></td>
        <td><input type="text" id="F130FP01" name="F130FP01" onkeyup="DynamicLoad(this.value, 'F130FP01', 'patient')"></td></tr>
      <tr><td colspan=2><select style="display:none" name="F130FP01LIST" id="F130FP01LIST" title="Patient List" size="10" onchange="REHIDE(this, 'F130FP01'); updatejson()"></select></td></tr>

      <!-- DATE OF OPERATION: (130,.09) DATE (Required) -->
      <tr><td><label for="F130FP09">Date of Operation: </label></td>
      <td><select id="F130FP09" name="F130FP09" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Primary Surgeon: (130,.14) Pointer to New Person File #200 -->
        <tr><td><label for="F130FP14">Primary Surgeon: </label>
            <input type="hidden" id="F130FP14IEN" name="F130FP14IEN"></td>
        <td><input type="text" id="F130FP14" name="F130FP14" onkeyup="DynamicLoad(this.value, 'F130FP14', 'provider')"></td></tr>
      <tr><td colspan=2><select style="display:none" name="F130FP14LIST" id="F130FP14LIST" title="Surgeon List" size="10" onchange="REHIDE(this, 'F130FP14'); updatejson()"></select></td></tr>

      <!-- Attending Surgeon: (130,.164) Pointer to New Person File #200 -->
        <tr><td><label for="F130FP164">Attending Surgeon: </label>
            <input type="hidden" id="F130FP164IEN" name="F130FP164IEN"></td>
        <td><input type="text" id="F130FP164" name="F130FP164" onkeyup="DynamicLoad(this.value, 'F130FP164', 'provider')"></td></tr>
      <tr><td colspan=2><select style="display:none" name="F130FP164LIST" id="F130FP164LIST" title="Attending List" size="10" onchange="REHIDE(this, 'F130FP164'); updatejson()"></select></td></tr>

      <!-- Surgical Specialty: (130,.04) Pointer to local Surgical Specialty File #137.45 -->
      <tr><td><label for="F130FP04">Surgical Specialty: </label></td>
      <td><select id="F130FP04" name="F130FP04" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Principal Operative Procedure: (130,26) Free Text -->
      <tr><td><label for="F130F26">Principal Operative Procedure: </label></td>
      <td><input type="text" id="F130F26" name="F130F26" onkeyup="updatejson()"></td></tr>

      <!-- Principal Preoperative Diagnosis: (130,33) Free Text -->
      <tr><td><label for="F130F33">Principal Preoperative Diagnosis: </label></td>
      <td><input type="text" id="F130F33" name="F130F33" onkeyup="updatejson()"></td></tr>

      <!-- Laterality Of Procedure: (130,638) Set of Codes: 1-NA, 2-LEFT, 3-RIGHT, 4-BILATERAL -->
      <tr><td><label for="F130F638">Laterality Of Procedure: </label></td>
      <td><select id="F130F638" name="F130F638" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Planned Admission Status: (130,.013) Set of Codes: 1-SAME DAY, 2-ADMITTED, 3-HOSPITALIZED -->
      <tr><td><label for="F130FP013">Planned Admission Status: </label></td>
      <td><select id="F130FP013" name="F130FP013" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Planned Principal Procedure Code: (103,27) Pointer to CPT File #81 -->
      <tr><td><label for="F130F27">Planned Principal Procedure Code: </label></td>
      <td><input type="text" id="F130F27" name="F130F27" onkeyup="updatejson()"></td></tr>

      <!-- Demo ICD-10 Procedure Code: (130,999) Pointer to CPT File #80.1 ICD OPERATION/PROCEDURE FILE-->
        <tr><td><label for="F130F999">Demo ICD-10 Procedure Code: </label>
            <input type="hidden" id="F130F999IEN" name="F130F999IEN"></td>
        <td><input type="text" id="F130F999" name="F130F999" onkeyup="DynamicLoad(this.value, 'F130F999', 'procedure')"></td></tr>
      <tr><td colspan=2><select style="display:none" name="F130F999LIST" id="F130F999LIST" title="ICD-10 List" size="10" onchange="REHIDE(this, 'F130F999'); updatejson()"></select></td></tr>

      <!-- Hospital Admission Status: (130,.011) Set of Codes: I-INPATIENT, O-OUTPATIENT, 1-SAME DAY, 2-ADMISSION, 3-HOSPITALIZED -->
      <tr><td><label for="F130FP011">Hospital Admission Status: </label></td>
      <td><select id="F130FP011" name="F130FP011" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Major or Minor: (130,.03) Set of Codes: J-MAJOR, N-MINOR -->
      <tr><td><label for="F130FP03">Major or Minor: </label></td>
      <td><select id="F130FP03" name="F130FP03" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Case Schedule Type: (130,.035) Set of Codes: EM-EMERGENCY, EL-ELECTIVE, A-ADD ON (NON-EMERGENT, S-STANDBY, U-URGENT -->
      <tr><td><label for="F130FP035">Case Schedule Type: </label></td>
      <td><select id="F130FP035" name="F130FP035" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Palliation: (130,661) Set of Codes: Y-YES, N-NO -->
      <tr><td><label for="F130F661">Palliation: </label></td>
      <td><select id="F130F661" name="F130F661" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Planned Postop Care: (130,.43) Pointer to SURGERY DISPOSITION FILE #131.6 -->
      <tr><td><label for="F130FP43">Planned Postop Care: </label></td>
      <td><select id="F130FP43" name="F130FP43" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Requested Anesthesia Technique: (130,1.01) Set of Codes: L-LOCAL, S-SPINAL, B-BLOCK, G-GENERAL, C-CHOICE, MAC-MONITORED ANESTHESIA CARE, E-EPIDURAL -->
      <tr><td><label for="F130F1P01">Requested Anesthesia Technique: </label></td>
      <td><select id="F130F1P01" name="F130F1P01" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Intraoperative X-Rays (Y/N/C): (130,1.035) Set of Codes: Y-YES, N-NO, C-C-ARM -->
      <tr><td><label for="F130F1P035">Intraoperative X-Rays (Y/N/C): </label></td>
      <td><select id="F130F1P035" name="F130F1P035" onchange="updatejson()">
        <option selected value=""></option>
      </select></td></tr>

      <!-- Select REFERRING PHYSICIAN: (130,23) Multiple (Add New Entry without Asking) Includes additional fields including a pointer field to the NEW PERSON FILE #200 -->
      <tr><td><label for="F130F23">REFERRING PHYSICIAN: </label></td>
      <td><input type="text" id="F130F23" name="F130F23" onkeyup="updatejson()"></td></tr>

    </table>
  </form>
</td><td>
  <form action="surgery.php?fn=doit" method="post" target="RESPVIEW">
    <textarea id="REQUEST" name="REQUEST" title="Request" placeholder=""></textarea><br><br>
    <input type="submit" value="Submit"><br><br>
  </form>
</td></tr>
</table>

<iframe src="" name="RESPVIEW" id="RESPVIEW" title="Response Viewer"></iframe>
</body>
<script type="text/javascript">
    resizeIframes(); updatejson();
</script>
</html>
<?php break; } ?>