Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cloud Storage/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cloud Storage/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cloud Storage/.idea/S3.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Cloud Storage/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cloud Storage/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cloud Storage/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cloud Storage/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Cloud Storage/Guide.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


1]Prerequisites before execution :
a) VSCODE, PyCharm or any IDE to run the python program

2]Steps to execute the program :
a) UPLOAD (Only for 1 demo test) :
1. Open Cloud Storage folder in your IDE
2. On terminal run the upload.py file.
3. You will get localhost (e.g. * Running on http://127.0.0.1:5000)
4. Follow the link in your browser.
5. Fill dummy details for the test.
6. Click the submit button.
7. You will get the notification of 'PDF file uploaded to S3 successfully' message.
8. If you want to upload again, you have to change the name of file in the code manually so that previous file would not get overwritten.

b) LIST :
1. Open Cloud Storage folder in your IDE
2. On terminal run the list.py file.
3. You will get localhost (e.g. * Running on http://127.0.0.1:5000)
4. Follow the link in your browser.
5. You will see the file in PDF format that you just uploaded. (Generally this shows all the files that are uploaded on the cloud, for this demo you will see only one)
6. By clicking on the name, the pdf file will get downloaded in your system.
7. You can verify the content that you uploaded in cloud is correct or not.
n
36 changes: 36 additions & 0 deletions Cloud Storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Cloud Storage Demo

This project demonstrates a simple cloud storage setup where users can upload and list PDF files stored on the cloud.

## Prerequisites

Before executing the program, make sure you have:

- **An IDE**: VS Code, PyCharm, or any other IDE to run Python programs.

## Steps to Execute the Program

### 1. Upload (For 1 Demo Test)

1. Open the `Cloud Storage` folder in your IDE.
2. In the terminal, run the `upload.py` file.
3. You should see an output indicating the localhost address (e.g., `* Running on http://127.0.0.1:5000`).
4. Follow the link in your browser.
5. Fill in dummy details for the test.
6. Click the **Submit** button.
7. You will receive a notification message: `'PDF file uploaded to S3 successfully'`.
8. **Note**: If you want to upload again, you must change the file name in the code manually to prevent overwriting the previous file.

### 2. List

1. Open the `Cloud Storage` folder in your IDE.
2. In the terminal, run the `list.py` file.
3. You should see an output indicating the localhost address (e.g., `* Running on http://127.0.0.1:5000`).
4. Follow the link in your browser.
5. You will see the uploaded PDF file (this displays all files uploaded to the cloud; for this demo, you’ll see only one).
6. Click on the file name to download the PDF file to your system.
7. Verify the content to ensure it matches what was uploaded to the cloud.

## Notes

- For this demo, only one file is shown; however, this setup generally supports multiple files on the cloud.
Binary file added Cloud Storage/__pycache__/secret.cpython-311.pyc
Binary file not shown.
Binary file added Cloud Storage/__pycache__/secret.cpython-312.pyc
Binary file not shown.
43 changes: 43 additions & 0 deletions Cloud Storage/list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from flask import Flask, render_template, send_file
import boto3
from botocore.exceptions import NoCredentialsError
from secret import access_key, secret_access_key

app = Flask(__name__)


s3 = boto3.client('s3', aws_access_key_id=access_key, aws_secret_access_key=secret_access_key)


S3_BUCKET = 'medical-reports-ssip'

@app.route('/')
def list_reports():
try:

response = s3.list_objects(Bucket=S3_BUCKET)

if 'Contents' in response:
reports = [obj['Key'] for obj in response['Contents']]
else:
reports = []

return render_template('list.html', reports=reports)
except NoCredentialsError:
return "AWS credentials not available."
except Exception as e:
print("Error listing S3 objects:", str(e))
return "An error occurred while listing S3 objects."

@app.route('/download_report/<filename>')
def download_report(filename):
try:

s3.download_file(S3_BUCKET, filename, 'downloaded_report.pdf')

return send_file('downloaded_report.pdf', as_attachment=True)
except NoCredentialsError:
return "AWS credentials not available."

if __name__ == '__main__':
app.run(debug=True)
2 changes: 2 additions & 0 deletions Cloud Storage/secret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
access_key="<access_key>"
secret_access_key="<access_key>"
213 changes: 213 additions & 0 deletions Cloud Storage/templates/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
text-align: center;
}
.form-container {
width: 500px;
margin: 0 auto;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-group {
margin-bottom: 10px;
}
label {
display: block;
font-weight: bold;
}
input[type="text"],
input[type="number"],
select {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 5px;
}
.hidden {
display: none;
}
button {
background-color: #007BFF;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px 20px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>



</head>
<body>
<div class="form-container">
<h2>Medical Report Form</h2>
<form id="medical-form">
<div class="form-group">
<label for="patient-name">Patient Name:</label>
<input type="text" id="patient-name" name="patient-name" required>
</div>
<div class="form-group">
<label for="patient-age">Age:</label>
<input type="number" id="patient-age" name="patient-age" required>

</div>
<div class="form-group">
<label for="past-disease">Any Past Disease?</label>
<select id="past-disease" name="past-disease">
<option value="no">No</option>
<option value="yes">Yes</option>
</select>
</div>
<div class="form-group hidden" id="disease-details">
<label for="disease-type">Specify Disease:</label>
<input type="text" id="disease-type" name="disease-type">
</div>
<div class="form-group">
<label for="past-surgery">Any Past Surgery?</label>
<select id="past-surgery" name="past-surgery">
<option value="no">No</option>
<option value="yes">Yes</option>
</select>
</div>
<div class="form-group hidden" id="surgery-details">
<label for="surgery-type">Specify Surgery:</label>
<input type="text" id="surgery-type" name="surgery-type" placeholder="Type surgery type">
</div>

<div class="form-group">
<label for="present-illness">Present Illness:</label>
<textarea id="present-illness" name="present-illness" rows="4"></textarea>
</div>

<div class="form-group">
<label for="has-allergies">Any Allergies?</label>
<select id="has-allergies" name="has-allergies">
<option value="no">No</option>
<option value="yes">Yes</option>
</select>
</div>
<div class="form-group hidden" id="allergies-description">
<label for="allergies-details">Allergies Description:</label>
<textarea id="allergies-details" name="allergies-details" rows="4"></textarea>
</div>

<div class="form-group" id="medicine-section">
<label for="medicine-prescription">Medicine/Prescription 1:</label>
<input type="text" id="medicine-prescription" name="medicine-prescription">
<label for="medication-timing">Medication Timing:</label>
<select id="medication-timing" name="medication-timing">
<option value="after_eating">After Eating</option>
<option value="after_eating_3_times">3 times After Eating</option>
<option value="before_eating_3_times">3 times before Eating</option>
<option value="before_eating">Before Eating only in the morning</option>
<option value="3_times_a_day">3 Times a Day</option>
</select>
</div>

<button type="button" id="add-medicine-button">Add Medicine</button>

<div class="form-group">
<label for="medical-report-file">Upload Medical Report (PDF or Image):</label>
<input type="file" id="medical-report-file" name="medical-report-file" accept=".pdf, .jpg, .jpeg, .png">
</div>

<button type="button" id="submit-button">Submit</button>

<a href="{{ url_for('form') }}" target="_blank"> </a>


</form>
</div>

<div id="message" class="hidden">
</div>

<script>
const addMedicineButton = document.getElementById('add-medicine-button');
const medicineSection = document.getElementById('medicine-section');
let medicineCounter = 2;

addMedicineButton.addEventListener('click', function () {
const clonedMedicineSection = medicineSection.cloneNode(true);
clonedMedicineSection.querySelector('label').textContent = `Medicine/Prescription ${medicineCounter}:`;
clonedMedicineSection.querySelector('input').value = '';
clonedMedicineSection.querySelector('select').value = 'after_eating';
medicineSection.parentNode.insertBefore(clonedMedicineSection, addMedicineButton);
medicineCounter++;
});

const hasAllergiesSelect = document.getElementById('has-allergies');
const allergiesDescription = document.getElementById('allergies-description');

hasAllergiesSelect.addEventListener('change', function () {
if (hasAllergiesSelect.value === 'yes') {
allergiesDescription.classList.remove('hidden');
} else {
allergiesDescription.classList.add('hidden');
}
});

const submitButton = document.getElementById('submit-button');
const messageDiv = document.getElementById('message');

submitButton.addEventListener('click', function () {
const formData = {
"patient-name": document.getElementById('patient-name').value,
"patient-age": document.getElementById('patient-age').value,
"past-disease": document.getElementById('past-disease').value,
"disease-type": document.getElementById('disease-type').value,
"past-surgery": document.getElementById('past-surgery').value,
"surgery-type": document.getElementById('surgery-type').value,
"present-illness": document.getElementById('present-illness').value,
"has-allergies": document.getElementById('has-allergies').value,
"allergies-details": document.getElementById('allergies-details').value,
};

const medicines = document.querySelectorAll('.form-group[id^="medicine-section"]');
formData.medicines = [];

medicines.forEach(function (medicine, index) {
formData.medicines.push({
"medicine-prescription": medicine.querySelector('input[name="medicine-prescription"]').value,
"medication-timing": medicine.querySelector('select[name="medication-timing"]').value
});
});


fetch('/submit', {
method: 'POST',
body: JSON.stringify(formData),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.message) {
messageDiv.textContent = data.message;
messageDiv.classList.remove('hidden');
} else if (data.error) {
messageDiv.textContent = `Error: ${data.error}`;
messageDiv.classList.remove('hidden');
}
})
.catch(error => {
messageDiv.textContent = `Error: ${error}`;
messageDiv.classList.remove('hidden');
});
});
</script>
</body>
</html>
Loading