-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from PROTO-TYPE-SOLUTIONS/development
Development
- Loading branch information
Showing
120 changed files
with
5,054 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,7 @@ | ||
# pull official base image | ||
FROM python:3.11-slim-bullseye as builder | ||
|
||
# set work directory | ||
WORKDIR /usr/src/app | ||
|
||
# set environment variables | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# install psycopg2 dependencies | ||
RUN apt-get update \ | ||
&& apt-get install -y postgresql-client gcc python3-dev musl-dev \ | ||
&& apt-get install -y netcat | ||
|
||
# install dependencies | ||
RUN pip install --upgrade pip | ||
COPY ./requirements.txt . | ||
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt | ||
|
||
|
||
# pull official base image | ||
FROM python:3.11-slim-bullseye | ||
|
||
# create directory for the app user | ||
RUN mkdir -p /home/app | ||
|
||
# create the app user | ||
RUN groupadd app && useradd -m -g app app | ||
|
||
# create the appropriate directories | ||
ENV HOME=/home/app | ||
ENV APP_HOME=/home/app/web | ||
|
||
ENV DJANGO_SETTINGS_MODULE=makeeasyhmis.settings.base | ||
|
||
RUN mkdir $APP_HOME | ||
WORKDIR $APP_HOME | ||
|
||
|
||
RUN mkdir $APP_HOME/staticfiles | ||
RUN mkdir $APP_HOME/mediafiles | ||
|
||
# install dependencies | ||
RUN apt-get update && apt-get install -y libpq-dev | ||
COPY --from=builder /usr/src/app/wheels /wheels | ||
COPY --from=builder /usr/src/app/requirements.txt . | ||
RUN pip install --no-cache /wheels/* | ||
|
||
# copy entrypoint.sh | ||
COPY ./entrypoint.sh $APP_HOME | ||
|
||
# copy project | ||
COPY . $APP_HOME | ||
|
||
# chown all the files to the app user | ||
RUN chown -R app:app $APP_HOME | ||
|
||
# change to the app user | ||
USER app | ||
|
||
# run entrypoint.sh | ||
ENTRYPOINT ["/home/app/web/entrypoint.sh"] | ||
RUN chmod +x /home/app/web/entrypoint.sh | ||
FROM python:3 | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
ENV PYTHONUNBUFFERED=1 | ||
WORKDIR /code | ||
COPY requirements.txt /code/ | ||
RUN pip install -r requirements.txt | ||
COPY . /code/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
from .models import Announcement, Channel, Comment | ||
|
||
admin.site.register(Announcement) | ||
admin.site.register(Channel) | ||
admin.site.register(Comment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AnnouncementConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'announcement' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.db import models | ||
from customuser.models import CustomUser | ||
|
||
class Channel(models.Model): | ||
name = models.CharField(max_length=45) | ||
photo = models.FileField(upload_to='announcements/channel/', null=True, blank=True) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
class Announcement(models.Model): | ||
title = models.CharField(max_length=45) | ||
content = models.CharField(max_length=45) | ||
created_by = models.ForeignKey(CustomUser, on_delete=models.CASCADE) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
channel = models.ForeignKey(Channel, on_delete=models.CASCADE) | ||
file = models.FileField(upload_to='announcements/file/', null=True, blank=True) | ||
|
||
|
||
def __str__(self): | ||
return self.title | ||
|
||
|
||
|
||
class Comment(models.Model): | ||
title = models.CharField(max_length=45) | ||
content = models.CharField(max_length=45) | ||
created_by = models.ForeignKey(CustomUser, on_delete=models.CASCADE) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE) | ||
file = models.FileField(upload_to='announcements/comments/', null=True, blank=True) | ||
|
||
|
||
def __str__(self): | ||
return self.title | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from rest_framework import serializers | ||
from .models import ( | ||
Channel, | ||
Announcement, | ||
Comment, | ||
) | ||
|
||
|
||
class ChannelSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Channel | ||
fields = '__all__' | ||
|
||
|
||
class AnnouncementSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Announcement | ||
fields = '__all__' | ||
|
||
|
||
|
||
class CommentSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Comment | ||
fields = '__all__' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.urls import path, include | ||
from rest_framework.routers import DefaultRouter | ||
from django.conf.urls.static import static | ||
|
||
from django.conf import settings | ||
|
||
|
||
from .views import ( | ||
ChannelViewset, | ||
AnnouncementViewset, | ||
CommentViewset, | ||
) | ||
|
||
router = DefaultRouter() | ||
|
||
router.register(r'channels', ChannelViewset) | ||
router.register(r'announcements', AnnouncementViewset) | ||
router.register(r'comments', CommentViewset) | ||
|
||
urlpatterns = [ | ||
path('', include(router.urls)), | ||
] | ||
|
||
if settings.DEBUG: | ||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.shortcuts import render | ||
from .models import ( | ||
Channel, | ||
Announcement, | ||
Comment, | ||
) | ||
|
||
from authperms.permissions import ( | ||
IsStaffUser, | ||
IsDoctorUser, | ||
IsLabTechUser, | ||
IsNurseUser, | ||
IsSystemsAdminUser | ||
) | ||
|
||
from rest_framework import viewsets | ||
|
||
from .serializeers import ( | ||
ChannelSerializer, | ||
AnnouncementSerializer, | ||
CommentSerializer, | ||
) | ||
|
||
class ChannelViewset(viewsets.ModelViewSet): | ||
queryset = Channel.objects.all() | ||
serializer_class = ChannelSerializer | ||
permission_classes = (IsDoctorUser | IsNurseUser | IsLabTechUser,) | ||
|
||
class AnnouncementViewset(viewsets.ModelViewSet): | ||
queryset = Announcement.objects.all() | ||
serializer_class = AnnouncementSerializer | ||
permission_classes = (IsDoctorUser | IsNurseUser | IsLabTechUser,) | ||
|
||
|
||
class CommentViewset(viewsets.ModelViewSet): | ||
queryset = Comment.objects.all() | ||
serializer_class = CommentSerializer | ||
permission_classes = (IsDoctorUser | IsNurseUser | IsLabTechUser,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,45 @@ | ||
from django.db import models | ||
from inventory.models import Item | ||
from patient.models import Patient | ||
from django.db.models import Sum | ||
|
||
|
||
def invoice_file_path(instance, filename): | ||
return f'invoices/{instance.invoice_number}/{filename}' | ||
|
||
class Invoice(models.Model): | ||
STATUS_CHOICES = ( | ||
('pending', 'Pending'), | ||
('paid', 'Paid'), | ||
) | ||
patient = models.ForeignKey(Patient, on_delete = models.SET_NULL, null=True) | ||
invoice_number = models.CharField(max_length=50) | ||
invoice_date = models.DateField() | ||
invoice_amount = models.DecimalField(max_digits=10, decimal_places=2) | ||
status = models.CharField( | ||
max_length=10, choices=STATUS_CHOICES, default='pending') | ||
invoice_description = models.CharField(max_length=200) | ||
invoice_file = models.FileField(upload_to='invoices', null=True, blank=True) | ||
invoice_file = models.FileField(upload_to=invoice_file_path, null=True, blank=True) | ||
invoice_created_at = models.DateTimeField(auto_now_add=True) | ||
invoice_updated_at = models.DateTimeField(auto_now=True) | ||
|
||
def calculate_invoice_amount(self): | ||
# Sum up the total sale price of all related invoice items | ||
total_amount = self.invoiceitem_set.aggregate( | ||
total_amount=Sum('service__inventory__sale_price'))['total_amount'] or 0 | ||
self.invoice_amount = total_amount | ||
self.save() | ||
|
||
|
||
|
||
class InvoiceItem(models.Model): | ||
invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE) | ||
item_name = models.CharField(max_length=100) | ||
service = models.ForeignKey(Item, on_delete=models.CASCADE) | ||
item_price = models.DecimalField(max_digits=10, decimal_places=2) | ||
item_created_at = models.DateTimeField(auto_now_add=True) | ||
item_updated_at = models.DateTimeField(auto_now=True) | ||
item_updated_at = models.DateTimeField(auto_now=True) | ||
# quantity = models.CharField(max_length=50, null=True) | ||
|
||
def save(self, *args, **kwargs): | ||
super().save(*args, **kwargs) | ||
# Recalculate invoice amount after saving the InvoiceItem | ||
self.invoice.calculate_invoice_amount() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
from .models import Invoice | ||
from makeeasyhmis.celery_tasks import generate_invoice_pdf | ||
'''signal to fire up celery task to to generated pdf once Invoice tale gets a new entry''' | ||
@receiver(post_save, sender=Invoice) | ||
def generate_invoice(sender, instance, created, **kwargs): | ||
if created: | ||
generate_invoice_pdf.delay(instance.pk) |
Oops, something went wrong.