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
2 changes: 2 additions & 0 deletions heal-diapp/healdi_main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"



STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
Expand Down
2 changes: 2 additions & 0 deletions heal-diapp/healdi_main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@

if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
16 changes: 16 additions & 0 deletions heal-diapp/medrecords/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# myapp/forms.py
# myapp/forms.py
from django import forms
from .models import Documents

class DocumentUploadForm(forms.ModelForm):
class Meta:
model = Documents
fields = ['title', 'file']

def save(self, commit=True):
instance = super().save(commit=False)
instance.owner = self.instance.uploaded_by # Set owner to the user who uploaded the document
if commit:
instance.save()
return instance
29 changes: 29 additions & 0 deletions heal-diapp/medrecords/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.23 on 2023-12-29 18:33

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Documents',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('file', models.FileField(upload_to='documents/')),
('creation_time', models.DateTimeField(default=django.utils.timezone.now)),
('patient_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('uploaded_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='uploaded_by', to=settings.AUTH_USER_MODEL)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.23 on 2023-12-29 19:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('medrecords', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='documents',
name='patient_name',
field=models.CharField(max_length=255),
),
]
18 changes: 18 additions & 0 deletions heal-diapp/medrecords/migrations/0003_alter_documents_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.23 on 2023-12-29 19:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('medrecords', '0002_alter_documents_patient_name'),
]

operations = [
migrations.AlterField(
model_name='documents',
name='file',
field=models.FileField(upload_to=''),
),
]
13 changes: 13 additions & 0 deletions heal-diapp/medrecords/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
from django.db import models
from django.utils import timezone
from accounts.models import User

# Create your models here.

class Documents(models.Model):
title = models.CharField(max_length=255)
file = models.FileField(upload_to='')
patient_name = models.ForeignKey(User, on_delete=models.CASCADE)
creation_time = models.DateTimeField(default=timezone.now)
uploaded_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='uploaded_by')
patient_name = models.CharField(max_length=255) # Adjust this field based on your requirements

def __str__(self):
return self.title
19 changes: 19 additions & 0 deletions heal-diapp/medrecords/templates/medrecords.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,24 @@

{% block content %}
<h2>Medrecords</h2>
<a href="{% url 'upload_document' %}">Upload Document</a>
<!-- Your appointment scheduling form goes here -->

<hr>
<h1>Document List</h1>

<ul>
{% for document in documents %}
<li>
<strong>{{ document.title }}</strong><br>
Uploaded by: {{ document.uploaded_by.username }}<br>
Upload Time: {{ document.creation_time }}<br>
{% if document.file.url|slice:"-4:" == '.pg' %}
<iframe src="{{ document.file.url }}" width="600" height="400"></iframe>
{% else %}
<a href="{{ document.file.url }}" download>Download Document</a>
{% endif %}
</li>
{% endfor %}
</ul>
{% endblock %}
11 changes: 11 additions & 0 deletions heal-diapp/medrecords/templates/upload_document.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- in appointments/templates/appointments/schedule_appointment.html -->
{% extends 'base.html' %}

{% block content %}
<h2>Upload Document</h2>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Upload</button>
</form>
{% endblock %}
3 changes: 2 additions & 1 deletion heal-diapp/medrecords/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# appointments/urls.py
from django.urls import path
from .views import medrecords
from .views import medrecords,upload_document

urlpatterns = [
path('medrecords/', medrecords, name='medrecords'),
# Add other URL patterns as needed
path('medrecords/upload/', upload_document, name='upload_document'),
]
24 changes: 21 additions & 3 deletions heal-diapp/medrecords/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# appointments/views.py
from django.shortcuts import render
# myapp/views.py
from django.shortcuts import render, redirect
from .forms import DocumentUploadForm
from .models import Documents
from django.contrib.auth.decorators import login_required

#@login_required
def upload_document(request):
if request.method == 'POST':
form = DocumentUploadForm(request.POST, request.FILES)
if form.is_valid():
form.instance.uploaded_by = request.user # Set the uploaded_by field to the current user
form.instance.patient_name = request.user
form.save()
return redirect('medrecords') # Redirect to the document list view
else:
form = DocumentUploadForm()

return render(request, 'upload_document.html', {'form': form})

def medrecords(request):
return render(request, 'medrecords.html')
documents = Documents.objects.all()
return render(request, 'medrecords.html', {'documents': documents})