File size: 2,786 Bytes
854b6ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Health Reports Processor</title>
  <style>

    body {

      font-family: Arial, sans-serif;

      margin: 2rem;

      max-width: 800px;

    }

    label {

      display: block;

      margin-top: 1rem;

      font-weight: bold;

    }

    input, textarea, button {

      width: 100%;

      padding: 0.5rem;

      margin-top: 0.25rem;

      box-sizing: border-box;

      font-size: 1rem;

    }

    button {

      margin-top: 1rem;

      cursor: pointer;

    }

    pre {

      background: #f4f4f4;

      padding: 1rem;

      overflow-x: auto;

      white-space: pre-wrap;

      word-wrap: break-word;

      border: 1px solid #ccc;

      margin-top: 1rem;

    }

    .error {

      color: red;

      margin-top: 1rem;

    }

  </style>
</head>
<body>
  <h1>Health Reports Processor</h1>
  <form id="reportForm">
    <label for="patientId">Patient ID:</label>
    <input type="text" id="patientId" name="patientId" required />

    <label for="filenames">Filenames (comma-separated):</label>
    <input type="text" id="filenames" name="filenames" placeholder="e.g. cbc.pdf, thyroid.pdf" required />

    <button type="submit">Process Reports</button>
  </form>

  <div id="result"></div>

  <script>

    const form = document.getElementById('reportForm');

    const resultDiv = document.getElementById('result');



    form.addEventListener('submit', async (e) => {

      e.preventDefault();

      resultDiv.innerHTML = '';



      const patientId = form.patientId.value.trim();

      const filenamesRaw = form.filenames.value.trim();

      if (!patientId || !filenamesRaw) {

        resultDiv.innerHTML = '<p class="error">Please enter both Patient ID and filenames.</p>';

        return;

      }



      const filenames = filenamesRaw.split(',').map(f => f.trim()).filter(f => f.length > 0);



      try {

        const response = await fetch('/process_reports', {

          method: 'POST',

          headers: { 'Content-Type': 'application/json' },

          body: JSON.stringify({ patient_id: patientId, filenames: filenames })

        });



        if (!response.ok) {

          const errorData = await response.json();

          resultDiv.innerHTML = `<p class="error">Error: ${errorData.error || response.statusText}</p>`;

          return;

        }



        const data = await response.json();

        resultDiv.innerHTML = `<h2>Processed Result</h2><pre>${JSON.stringify(data, null, 2)}</pre>`;

      } catch (err) {

        resultDiv.innerHTML = `<p class="error">Request failed: ${err.message}</p>`;

      }

    });

  </script>
</body>
</html>