# Project export: MediConnect ER

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: TreeHacks 2024
- Tagline: MediConnect ER: Streamlines emergency healthcare by condensing EHR data for quick access, locating ERs, and engaging users through a user-friendly chatbot. Enhancing efficiency and outcomes.
- Devpost: https://devpost.com/software/mediconnect-er
- GitHub: https://github.com/praneetbang/TreeHacks2024-NPDP
- Team: 3 GitHub contributor(s) — Nilay2498 (14 commits), Dhruv S Patel (9 commits), Praneet Bang (3 commits)

## Devpost submission (written by the team)

### Overview

Problem Statement In emergency healthcare situations, accessing timely and accurate patient information is critical for healthcare providers to deliver effective and urgent care. However, the current process of sharing essential information between individuals in need of emergency care and healthcare professionals is often inefficient and prone to delays. Moreover, locating and scheduling an appointment in the nearest Emergency Room (ER) can be challenging, leading to unnecessary treatment delays and potential health risks. There is a pressing need for a solution that streamlines the transmission of vital patient information to healthcare providers and facilitates the seamless booking of ER appointments, ultimately improving the efficiency and effectiveness of emergency healthcare delivery. Introduction We have developed an app designed to streamline the process for individuals involved in accidents or requiring emergency care to provide essential information to doctors beforehand in a summarized format for Electronic Health Record (EHR) integration. Leveraging Language Model (LLM) technology, the app facilitates the efficient transmission of pertinent details, ensuring healthcare providers have access to critical information promptly and also allows doctors to deal with more volume of paitents. Moreover, the app includes functionality for users to locate and schedule an appointment in the nearest Emergency Room (ER), enhancing accessibility and ensuring timely access to care in urgent situations. By combining pre-emptive data sharing with convenient ER booking features, the app aims to improve the efficiency and effectiveness of emergency healthcare delivery, potentially leading to better patient outcomes. About MediConnect ER Content Summarization with LLM - "MediConnect ER" revolutionizes emergency healthcare by seamlessly integrating with Electronic Health Records (EHRs) and utilizing advanced Language Model (LLM) technology. Users EHR medical data, which the LLM summarizer condenses into EHR-compatible summaries. This automation grants healthcare providers immediate access to crucial patient information upon ER arrival, enabling swift and informed decision-making. By circumventing manual EHR searches, the app reduces wait times, allowing doctors to prioritize and expedite care effectively. This streamlined process enhances emergency healthcare efficiency, leading to improved patient outcomes and satisfaction. Geolocation and ER Booking - MediConnect ER includes functionality for users to quickly locate and book the nearest Emergency Room (ER). By leveraging geolocation technology, the app identifies nearby healthcare facilities, providing users with real-time information on wait times, available services, and directions to the chosen ER. This feature eliminates the uncertainty and Medi-Chatbot - The chatbot feature in "MediConnect ER" offers users a user-friendly interface to engage with and access essential information about their treatment plans. Patients can interact with the chatbot to inquire about various aspects of their treatment, including medication instructions, follow-up appointments, and potential side effects. By providing immediate responses to user queries, the chatbot improves accessibility to crucial treatment information, empowering patients to take a more active role in their healthcare journey. Building Process Our application leverages a sophisticated tech stack to deliver a seamless user experience. At the forefront, we utilize JavaScript, HTML, and CSS to craft an intuitive and visually appealing frontend interface. This combination of technologies ensures a smooth and engaging user interaction, facilitating effortless navigation and information access. Backing our frontend, we employ Flask, a powerful Python web framework, to orchestrate our backend operations. Flask provides a robust foundation for handling data processing, storage, and communication between our frontend and other components of our system. It enables efficient data management and seamless integration of various functionalities, enhancing the overall performance and reliability of our application. Central to our data summarization capabilities is Mistral 7B, a state-of-the-art language model meticulously fine-tuned to summarize clinical health records. Through extensive tuning on the Medalpaca dataset, we have optimized Misteral 7B to distill complex medical information into concise and actionable summaries. This tailored approach ensures that healthcare professionals receive relevant insights promptly, facilitating informed decision-making and personalized patient care. Additionally, our chatbot functionality is powered by GPT-3.5, one of the most advanced language models available. GPT-3.5 enables natural and contextually relevant conversations, allowing users to interact seamlessly and obtain pertinent information about their treatment plans. By leveraging cutting-edge AI technology, our chatbot enhances user engagement and accessibility, providing users with immediate support and guidance throughout their healthcare journey. To validate the effectiveness of our data summarization capabilities, we utilize Mistral 7B, a sophisticated language model specifically tailored for summarizing clinical health records. By running Mistral 7B through our synthetic EHR data records generated by Synteha, we validate the accuracy and relevance of the summarized information. This validation process ensures that our summarization process effectively captures essential medical insights and presents them in a concise and actionable format. One of the major challenges that we ran into are , bascially finding what EHR data looks like , after much research we found Syntheta that can generate the data we are looking into. One of the major challenges that we ran into are , bascially finding what EHR data looks like , after much research we found Syntheta that can generate the data we are looking into. We found that fine tunning dataset were not avaliable to fine tune datasets that were even remotely sdimilar to EHR data. We found that fine tunning dataset were not avaliable to fine tune datasets that were even remotely sdimilar to EHR data. In the future, our aim is to seamlessly integrate Amanuensis into established Electronic Health Record (EHR) systems like Epic and Cerner, offering physicians an AI-powered assistant to enhance their clinical decision-making processes. Additionally, we intend to augment our Natural Language Processing (NLP) pipeline by incorporating actual patient data rather than relying solely on synthetic EHR records. We will complement this with meticulously curated annotations provided by physicians, ensuring the accuracy and relevance of the information processed by our system.

## README (from the GitHub repository)

# TreeHacks2024-NPDP

# MediConnect ER

## Problem Statement

In emergency healthcare situations, accessing timely and accurate patient information is critical for healthcare providers to deliver effective and urgent care. However, the current process of sharing essential information between individuals in need of emergency care and healthcare professionals is often inefficient and prone to delays. Moreover, locating and scheduling an appointment in the nearest Emergency Room (ER) can be challenging, leading to unnecessary treatment delays and potential health risks. There is a pressing need for a solution that streamlines the transmission of vital patient information to healthcare providers and facilitates the seamless booking of ER appointments, ultimately improving the efficiency and effectiveness of emergency healthcare delivery.

## Introduction

We have developed an app designed to streamline the process for individuals involved in accidents or requiring emergency care to provide essential information to doctors beforehand in a summarized format for Electronic Health Record (EHR) integration. Leveraging Language Model (LLM) technology, the app facilitates the efficient transmission of pertinent details, ensuring healthcare providers have access to critical information promptly and also allows doctors to deal with more volume of paitents.

Moreover, the app includes functionality for users to locate and schedule an appointment in the nearest Emergency Room (ER), enhancing accessibility and ensuring timely access to care in urgent situations. By combining pre-emptive data sharing with convenient ER booking features, the app aims to improve the efficiency and effectiveness of emergency healthcare delivery, potentially leading to better patient outcomes.

## About MediConnect ER

1. Content Summarization with LLM - 
"MediConnect ER" revolutionizes emergency healthcare by seamlessly integrating with Electronic Health Records (EHRs) and utilizing advanced Language Model (LLM) technology. Users EHR medical data, which the LLM summarizer condenses into EHR-compatible summaries. This automation grants healthcare providers immediate access to crucial patient information upon ER arrival, enabling swift and informed decision-making. By circumventing manual EHR searches, the app reduces wait times, allowing doctors to prioritize and expedite care effectively. This streamlined process enhances emergency healthcare efficiency, leading to improved patient outcomes and satisfaction.

2. Geolocation and ER Booking -

MediConnect ER includes functionality for users to quickly locate and book the nearest Emergency Room (ER). By leveraging geolocation technology, the app identifies nearby healthcare facilities, providing users with real-time information on wait times, available services, and directions to the chosen ER. This feature eliminates the uncertainty and 

3. Medi-Chatbot -

The chatbot feature in "MediConnect ER" offers users a user-friendly interface to engage with and access essential information about their treatment plans. Patients can interact with the chatbot to inquire about various aspects of their treatment, including medication instructions, follow-up appointments, and potential side effects. By providing immediate responses to user queries, the chatbot improves accessibility to crucial treatment information, empowering patients to take a more active role in their healthcare journey. 


## Building Process

Our application leverages a sophisticated tech stack to deliver a seamless user experience. At the forefront, we utilize JavaScript, HTML, and CSS to craft an intuitive and visually appealing frontend interface. This combination of technologies ensures a smooth and engaging user interaction, facilitating effortless navigation and information access.

Backing our frontend, we employ Flask, a powerful Python web framework, to orchestrate our backend operations. Flask provides a robust foundation for handling data processing, storage, and communication between our frontend and other components of our system. It enables efficient data management and seamless integration of various functionalities, enhancing the overall performance and reliability of our application.

Central to our data summarization capabilities is Mistral 7B, a state-of-the-art language model meticulously fine-tuned to summarize clinical health records. Through extensive tuning on the Medalpaca dataset, we have optimized Misteral 7B to distill complex medical information into concise and actionable summaries. This tailored approach ensures that healthcare professionals receive relevant insights promptly, facilitating informed decision-making and personalized patient care.

Additionally, our chatbot functionality is powered by GPT-3.5, one of the most advanced language models available. GPT-3.5 enables natural and contextually relevant conversations, allowing users to interact seamlessly and obtain pertinent information about their treatment plans. By leveraging cutting-edge AI technology, our chatbot enhances user engagement and accessibility, providing users with immediate support and guidance throughout their healthcare journey.


# EHR Datageneration

To validate the effectiveness of our data summarization capabilities, we utilize Mistral 7B, a sophisticated language model specifically tailored for summarizing clinical health records. By running Mistral 7B through our synthetic EHR data records generated by Synteha, we validate the accuracy and relevance of the summarized information. This validation process ensures that our summarization process effectively captures essential medical insights and presents them in a concise and actionable format.

# Challenges we Ran into

1. One of the major challenges that we ran into are , bascially finding what EHR data looks like , after much research we found Syntheta that can generate the data we are looking into.

2. We found that fine tunning dataset were not avaliable to fine tune datasets that were even remotely sdimilar to EHR data.


# Future Directions

In the future, our aim is to seamlessly integrate Amanuensis into established Electronic Health Record (EHR) systems like Epic and Cerner, offering physicians an AI-powered assistant to enhance their clinical decision-making processes. Additionally, we intend to augment our Natural Language Processing (NLP) pipeline by incorporating actual patient data rather than relying solely on synthetic EHR records. We will complement this with meticulously curated annotations provided by physicians, ensuring the accuracy and relevance of the information processed by our system.

# Running the application

1. Clone the code repository

```
git clone <url>

```

2. Create the venv 

```
source /venv/bin/activate
```

3. Install Requirements
```
pip3 install rerquirements
```

4. Run the Flask Server
```
python3 app.py
```

# Development Team

Dhruv Patel
Praneet Bang
Nilay Shah
Poojan Shah



















## Detected evidence (automated analysis)

Indexed codebase: 20 recognized source files, 51 KB.
- CSS (language) — detected in the code
- Flask (technology) — detected in the code
- HTML (language) — detected in the code
- JavaScript (language) — detected in the code
- Python (language) — detected in the code
- React (technology) — detected in the code
- AWS (technology) — claimed on Devpost, not found in the code
- SQL (language) — claimed on Devpost, not found in the code

## Codebase structure (from repository index)

### Files (29 of 29)

```
.DS_Store
app.py
creds.rtf
data_gen/construct_database.Rmd
frontend/.gitignore
frontend/package.json
frontend/public/index.html
frontend/public/manifest.json
frontend/public/robots.txt
frontend/README.md
frontend/src/App.css
frontend/src/App.js
frontend/src/App.test.js
frontend/src/index.css
frontend/src/index.js
frontend/src/reportWebVitals.js
frontend/src/setupTests.js
README.md
requirements.txt
scripts/.DS_Store
scripts/chat_bot_service/app.py
scripts/creds.py
scripts/make_llm_request.py
scripts/payload_generator.py
templates/home.html
templates/hospital_dashboard.html
templates/login.html
templates/signup.html
templates/user_dashboard.html
```

### Dependencies

- frontend/package.json: @testing-library/jest-dom@^5.17.0, @testing-library/react@^13.4.0, @testing-library/user-event@^13.5.0, react@^18.2.0, react-dom@^18.2.0, react-scripts@5.0.1, web-vitals@^2.1.4
- requirements.txt: Flask@==3.0.2, Flask-SQLAlchemy@==3.0.2, pg8000, pip@==21.2.4, setuptools@==57.5.0, wheel@==0.36.2

### Recent commits (newest first)

- update1
- Merge branch 'main' of https://github.com/praneetbang/TreeHacks2024-NPDP
- readme md
- Changed few names
- Update home.html
- Corrected Name issue in Hospital Dashboard
- Merge branch 'main' of https://github.com/praneetbang/TreeHacks2024-NPDP
- Solved long text issue
- added chat nbot
- Merge branch 'main' of https://github.com/praneetbang/TreeHacks2024-NPDP
- added current_problem data filed + ui promt box
- Login/Signup pages
- Removed URI for google API and Postgres
- Added api for booking test
- List refresh after patient pickup
- Added Hospital Dashboard
- summariozation scripts
- Alert pop up
- changes made to UI
- changed ui and positioning

## Key source files (fetched from GitHub, selected and truncated for size)

### requirements.txt

```
# requirements.txt

# Dependencies required for installing packages

setuptools==57.5.0
wheel==0.36.2
pip==21.2.4


# Flask and Flask-SQLAlchemy
Flask==3.0.2
Flask-SQLAlchemy==3.0.2
pg8000



```

### frontend/package.json

```
{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

```

### app.py

```python
from flask import Flask, request, jsonify, render_template,redirect, url_for, session
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

app.secret_key = "super secret key"

# PostgreSQL Configuration
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:admin123@tree-hacks-ehr-data.cn8kq2284drd.us-east-1.rds.amazonaws.com/ehr_database'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(50), unique=True, nullable=False)
    password = db.Column(db.String(50), nullable=False)
    user_type = db.Column(db.String(50), nullable=False)
    user_id = db.Column(db.String(50),unique=True, nullable=False)
    
class Appointments(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    patient_id = db.Column(db.String(50),unique=True, nullable=False)
    medical_history = db.Column(db.String(1000), nullable=False)
    current_problem = db.Column(db.String(1000), nullable=False)
    user_name = db.Column(db.String(50), nullable=False)

class EhrSummary(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    patient_id = db.Column(db.Integer, nullable=False)
    summary = db.Column(db.String(255), nullable=False)

@app.route('/')
def index():
    return render_template('home.html')

@app.route('/login')
def login():
    return render_template('login.html')

@app.route('/logout')
def logout():
    # Clear the session and redirect to the home page
    return redirect(url_for('index'))

@app.route('/user_dashboard')
def user_dashboard():
    return render_template('user_dashboard.html')

@app.route('/hospital_dashboard')
def hospital_dashboard():  # Change the function name
    return render_template('hospital_dashboard.html')


@app.route('/login', methods=['POST'])
def login_post():
    if request.method == 'POST':
        try:
            # Assuming your front-end sends data as JSON
            data = request.get_json()

            # Print received data for debugging
            print("Received data:", data)

            # Get username and password from the request
            username = data.get('username')
            password = data.get('password')

            # Query the database for the user
            user = User.query.filter_by(username=username).first()
            if user and user.password == password:
                # Successful login
                session['user_id'] = user.id
                if user.user_type == 'user':
                    response = {'message': 'Login successful', 'redirect': url_for('user_dashboard')}
                    return jsonify(response), 200
                elif user.user_type == 'hospital':
                    response = {'message': 'Login successful', 'redirect': url_for('hospital_dashboard')}
                    return jsonify(response), 200

            else:
                # Invalid credentials
                response = {'message': 'Invalid credentials'}
                return jsonify(response), 401

        except Exception as e:
            response = {'message': 'Error: {}'.format(str(e))}
            return jsonify(response), 500
        
@app.route('/get_appointments')
def get_appointments():
    # Assuming you have an Appointments model and relevant fields
    appointments = Appointments.query.all()

    # Convert appointments to a list of dictionaries
    appointment_list = [
        {
            'patient_id': appointment.patient_id,
            'medical_history': appointment.medical_history,
            'current_problem': appointment.current_problem,
            'user_name' : appointment.user_name
        }
        for appointment in appointments
    ]

    return jsonify(appointment_list)

@app.route('/remove_appointment/<string:patient_id>', methods=['DELETE'])
def remove_appointment(patient_id):
    try:
        # Query the database for the appointment with the given patient_id
        appointment = Appointments.query.filter_by(patient_id=patient_id).first()

        if appointment:
            # Remove the appointment from the database
            db.session.delete(appointment)
            db.session.commit()

            response = {'success': True, 'message': 'Appointment removed successfully'}
            return jsonify(response), 200
        else:
            response = {'success': False, 'message': 'Appointment not found'}
            return jsonify(response), 404

    except Exception as e:
        response = {'success': False, 'message': 'Error: {}'.format(str(e))}
        return jsonify(response), 500

@app.route('/book_appointment', methods=['POST'])
def book_appointment():
    try:
        # Assuming you're passing user_id in the request
        user_id = request.json.get('user_id')
        booking_reason = request.json.get('booking_reason')
        # Fetch the user from the database
        user = User.query.filter_by(user_id= user_id).first()

        if user:
            # Assuming you have a way to get patient_id associated with the user (replace with your logic)
            
            # Fetch the EhrSummary based on the patient_id
            ehr_summary = EhrSummary.query.filter_by(patient_id=user_id).first()

            if ehr_summary:
                # Create a new appointment

                appointment = Appointments(patient_id=user_id, medical_history=ehr_summary.summary,user_name=user.username,current_problem = booking_reason)


                # Add and commit to the database
                db.session.add(appointment)
                db.session.commit()

                print('Appointment booked successfully!')
                return jsonify({'success': True, 'message': 'Appointment booked successfully!'})
            else:
                print('No EhrSummary found for the user.')
                return jsonify({'success': False, 'message': 'No EhrSummary found for the user.'})
        else:
            print('User not found.')
            re
[truncated — 1355 more characters]
```

### frontend/src/App.js

```javascript
import logo from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;

```

### frontend/src/index.js

```javascript
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

```

### scripts/chat_bot_service/app.py

```python
import gradio as gr
import requests
import psycopg2

# Connect to the database
conn = psycopg2.connect(
    dbname='ehr_database',
    user='postgres',
    password='admin123',
    host='tree-hacks-ehr-data.cn8kq2284drd.us-east-1.rds.amazonaws.com',
    port='5432'
)
# Define your chatbot function
def chatbot(input_text):
    # Your chatbot logic here
   

    url = "https://api.together.xyz/v1/completions"

    payload = {
    "model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
    "prompt": "<s>[INST] "+ input_text+ " [/INST]",
    "max_tokens": 100,
    "stop": ["</s>", "[/INST]"],
    "temperature": 0.7,
    "top_p": 0.7,
    "top_k": 50,
    "repetition_penalty": 1,
    "n": 1
    }
    headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "Authorization": "Bearer 1018dc73006cb81e2bde91a7b4667b122e8db39ece49d5815b91a7c4810fcb26"
    }

    response = requests.post(url, json=payload, headers=headers)
    data = response.json()
    return data['choices'][0]['text']
    

# Create Gradio interface
iface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="AskMedi", allow_flagging=False)

# Launch Gradio interface
iface.launch(share=True)
```

### scripts/creds.py

```python
url =  "https://api.together.xyz/v1/completions"
api_key = "1018dc73006cb81e2bde91a7b4667b122e8db39ece49d5815b91a7c4810fcb26"
model = "mistralai/Mixtral-8x7B-Instruct-v0.1"
token_len = 512
```

### scripts/payload_generator.py

```python
import creds
def make_paylaod(prompt):
    headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "Authorization": "Bearer "+creds.api_key
    }
    
    payload = {
        "model": creds.model,
        "prompt": "<s>[INST] " + prompt  + " [/INST]",
        "max_tokens": creds.token_len,
        "stop": ["</s>", "[/INST]"],
        "temperature": 0.7,
        "top_p": 0.7,
        "top_k": 50,
        "repetition_penalty": 1,
        
    }
    
    return headers , payload
```

### templates/home.html

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Healthcare Hub</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mui/system@5.10.0/dist/system/system.css" integrity="sha512-Vrl5ZSCpwf8gJWO3O2waL/uhYCG2jEmaO43ZMtAWiJ2DDl3zyWhgB8GimFHaI5NYCDt/Nx5opBm1e6N/hzzZAg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<style>
    body {
        margin: 0;
        padding: 0;
        font-family: 'Roboto', sans-serif;
        background: linear-gradient(to right, #2980B9, #6DD5FA);
        color: #fff;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 100vh;
    }

    h2 {
        margin-bottom: 20px;
    }

    p {
        font-size: 18px;
        margin-bottom: 30px;
        text-align: center;
    }

    img {
        width: 80%;
        max-width: 400px;
        border-radius: 10px;
        margin-bottom: 20px;
    }

    a {
        text-decoration: none;
        color: #fff;
        padding: 10px 20px;
        font-size: 18px;
        border: 2px solid #fff;
        border-radius: 5px;
        margin: 10px;
        transition: all 0.3s ease-in-out;
    }

    a:hover {
        background-color: #fff;
        color: #2980B9;
    }
</style>
<body>
    <h2>Welcome to Healthcare Hub</h2>
    <p>Your one-stop solution for finding the nearest emergency rooms and scheduling appointments with ease.</p>
    <img src="https://wallpapers.com/images/featured/healthcare-oco8w27tkw40cp90.jpg" alt="Healthcare Image">
    <a href="/login">Login</a>
    <a href="/signup">Signup</a>
</body>
</html>

```

### scripts/make_llm_request.py

```python
import requests
import creds
import gradio as gr
import psycopg2

conn = psycopg2.connect(
    dbname='ehr_database',
    user='postgres',
    password='admin123',
    host='tree-hacks-ehr-data.cn8kq2284drd.us-east-1.rds.amazonaws.com',
    port='5432'
)

def summarize_ehr_records(prompt):
    headers, payload = make_paylaod(prompt)
    response = requests.post(creds.url , json=payload, headers=headers)
    data = response.json()
    

    insert_patient("8c85983a-a538-522f-bce0-03678b0fc7ce" , data['choices'][0]['text'])

def insert_patient(id , val):

    cur = conn.cursor()
    cur.execute("INSERT INTO ehr_summary (patient_id, summary) VALUES (%s, %s)", (id , val))
    conn.commit()
    cur.close()
    

def make_paylaod(prompt):
    headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "Authorization": "Bearer "+creds.api_key
    }
    
    payload = {
        "model": creds.model,
        "prompt": "<s>[INST] " + prompt  + " [/INST]",
        "max_tokens": creds.token_len,
        "stop": ["</s>", "[/INST]"],
        "temperature": 0.7,
        "top_p": 0.7,
        "top_k": 50,
        "repetition_penalty": 1,
        
    }
    
    return headers , payload



input_string =  """
Patient Name: Lily Garcia
Date of Visit: December 10, 2023
Chief Complaint: Anxiety
History of Present Illness:
Lily Garcia, a 35-year-old female, presents with complaints of persistent feelings of worry, nervousness, and restlessness for the past several months. She reports difficulty concentrating, irritability, and trouble falling asleep at night.
Past Medical History:
Lily Garcia has a history of generalized anxiety disorder and depression. She takes medications for anxiety and attends therapy sessions regularly.
Family History:
There is a family history of anxiety and mood disorders.
Social History:
Lily Garcia works as a teacher and lives with her partner. She enjoys reading and spending time with her pets.
Physical Examination:
Vital signs are stable. The patient appears anxious but is cooperative and engages in conversation.
"""


prompt_data = "Summarize the above deatils of a paitent for a doctor make it short within 1024 chars"
summarize_ehr_records(str(input_string) +"  "+prompt_data)
```

[10 more indexed source files omitted to keep this export small. The full file list is in the Codebase structure section above.]