<?php include 'settings.php'?>
<?php
  switch ($fn)
    {
    case "submit":
      echo "<!DOCTYPE html>\n";
      echo "<html>\n";
      echo "<head>\n";
      echo "  <meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\">\n";
      echo "  <title>FileMan API Tester</title>\n";
      echo "  <meta charset=\"utf-8\">\n";
      echo "  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
      echo "  <style>\n";
      echo "    body { font-size:15px; }\n";
      echo "    textarea { font-size:15px; }\n";
      echo "  </style>\n";
      echo "</head>\n";
      echo "<body>\n";
      echo "<pre>\n";
      $REQUEST = $_POST['REQUEST'];
      $REQUEST = rawurlencode($REQUEST);
      $url="http://localhost:8090/HL7FHIRAI/do";
      $command = "curl -X POST -H \"Content-Type: text/plain\" -d '$REQUEST' '$url'";
      system($command);
      echo "</pre>\n";
      echo "</body>\n";
      echo "</html>\n";
      break;

    default:
      ?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=9">
  <title>HL7 to FHIR Converter</title>
  <link rel="icon" type="image/png" href="favicon.png">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    body { font-size:15px; }
    textarea { font-size:15px; }
  </style>
  <script type="text/javascript">
    function resizeIframes()
      {
      document.getElementById("RESPVIEW").height=(window.innerHeight-320)*.98;
      document.getElementById("RESPVIEW").width=window.innerWidth*.95;
      document.getElementById("REQUEST").rows=10;
      document.getElementById("REQUEST").cols=window.innerWidth*.101;
      }
  </script>
 </head>
<body onresize="resizeIframes()">
  <form action="HL7FHIRAI.php?fn=submit" method="post" enctype="application/x-www-form-urlencoded" target="RESPVIEW">
    <textarea id="REQUEST" name="REQUEST">MSH|^~\&|LABSYS|LAB|EHR|HOSP|202501011200||ADT^A01|123456|P|2.3
PID|1||12345^^^HOSP^MR||Doe^Jane||19851105|F|||123 Main St^^Metropolis^NY^10001||555-1234
PV1|1|I|2000^2012^01||||1234^Smith^John|||||||||||98765
OBX|1|NM|GLUCOSE^GLU||120|mg/dL|70-110|H|||F</textarea><br><br>
    <input type="submit" value="Submit"><br><br>
  </form>
  <iframe src="" name="RESPVIEW" id="RESPVIEW"></iframe>
</body>
<script type="text/javascript"> resizeIframes(); </script>
</html>
      <?php
      break;
    }
?>