forked from botswana-harvard/edc-pharmacy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more celery work, add stock transfer confirmation and dispensing
- Loading branch information
Showing
65 changed files
with
2,329 additions
and
244 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
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
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from django.contrib import admin | ||
from django.template.loader import render_to_string | ||
from django.urls import reverse | ||
from django_audit_fields.admin import audit_fieldset_tuple | ||
from edc_utils.date import to_local | ||
|
||
from ...admin_site import edc_pharmacy_admin | ||
from ...forms import DispenseForm | ||
from ...models import Dispense | ||
from ..model_admin_mixin import ModelAdminMixin | ||
|
||
|
||
@admin.register(Dispense, site=edc_pharmacy_admin) | ||
class DispenseAdmin(ModelAdminMixin, admin.ModelAdmin): | ||
change_list_title = "Pharmacy: Dispense" | ||
change_form_title = "Pharmacy: Dispense" | ||
show_object_tools = True | ||
show_cancel = True | ||
list_per_page = 20 | ||
|
||
form = DispenseForm | ||
|
||
fieldsets = ( | ||
( | ||
"Section A: Dispense", | ||
{ | ||
"fields": ( | ||
"dispense_identifier", | ||
"dispense_datetime", | ||
"location", | ||
"rx", | ||
"dispensed_by", | ||
) | ||
}, | ||
), | ||
audit_fieldset_tuple, | ||
) | ||
|
||
list_display = ( | ||
"identifier", | ||
"dispense_date", | ||
"subject", | ||
"formulation", | ||
"location", | ||
"dispense_item_changelist", | ||
"stock_changelist", | ||
) | ||
|
||
search_fields = ( | ||
"id", | ||
"rx__subject_identifier", | ||
) | ||
|
||
list_filter = ( | ||
"dispense_datetime", | ||
"location__display_name", | ||
) | ||
|
||
readonly_fields = ( | ||
"dispense_identifier", | ||
"dispense_datetime", | ||
"rx", | ||
"location", | ||
"dispensed_by", | ||
) | ||
|
||
@admin.display(description="Dispense #", ordering="-dispense_identifier") | ||
def identifier(self, obj): | ||
return obj.dispense_identifier | ||
|
||
@admin.display( | ||
description="Subject #", ordering="rx__registered_subject__subject_identifier" | ||
) | ||
def subject(self, obj): | ||
return obj.rx.registered_subject.subject_identifier | ||
|
||
@admin.display(description="Formulation") | ||
def formulation(self, obj): | ||
return "<BR>".join([o.display_name for o in obj.rx.medications.all()]) | ||
|
||
@admin.display(description="Dispense date", ordering="dispense_datetime") | ||
def dispense_date(self, obj): | ||
return to_local(obj.dispense_datetime).date() | ||
|
||
@admin.display(description="Dispense items") | ||
def dispense_item_changelist(self, obj): | ||
url = reverse("edc_pharmacy_admin:edc_pharmacy_dispenseitem_changelist") | ||
url = f"{url}?q={obj.id}" | ||
context = dict(url=url, label="Dispense items", title="Go to items") | ||
return render_to_string("edc_pharmacy/stock/items_as_link.html", context=context) | ||
|
||
@admin.display(description="Stock") | ||
def stock_changelist(self, obj): | ||
url = reverse("edc_pharmacy_admin:edc_pharmacy_stock_changelist") | ||
url = f"{url}?q={obj.id}" | ||
context = dict(url=url, label="Stock", title="Go to stock") | ||
return render_to_string("edc_pharmacy/stock/items_as_link.html", context=context) |
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,95 @@ | ||
from django.contrib import admin | ||
from django.template.loader import render_to_string | ||
from django.urls import reverse | ||
from django_audit_fields.admin import audit_fieldset_tuple | ||
from edc_utils.date import to_local | ||
|
||
from ...admin_site import edc_pharmacy_admin | ||
from ...models import DispenseItem | ||
from ..model_admin_mixin import ModelAdminMixin | ||
|
||
|
||
@admin.register(DispenseItem, site=edc_pharmacy_admin) | ||
class DispenseItemAdmin(ModelAdminMixin, admin.ModelAdmin): | ||
change_list_title = "Pharmacy: Dispense items" | ||
change_form_title = "Pharmacy: Dispense item" | ||
show_object_tools = True | ||
show_cancel = True | ||
list_per_page = 20 | ||
|
||
fieldsets = ( | ||
( | ||
"Section A: Repack", | ||
{ | ||
"fields": ( | ||
"dispense_item_identifier", | ||
"dispense_item_datetime", | ||
"dispense", | ||
"stock", | ||
) | ||
}, | ||
), | ||
audit_fieldset_tuple, | ||
) | ||
|
||
list_display = ( | ||
"identifier", | ||
"subject", | ||
"location", | ||
"dispense_date", | ||
"dispense_changelist", | ||
"stock_changelist", | ||
"dispensed_by", | ||
) | ||
|
||
search_fields = ("id", "dispense__id", "stock__code", "dispense__rx__subject_identifier") | ||
|
||
readonly_fields = ( | ||
"dispense_item_identifier", | ||
"dispense_item_datetime", | ||
"dispense", | ||
"stock", | ||
) | ||
|
||
@admin.display(description="Dispense #", ordering="-dispense_item_identifier") | ||
def identifier(self, obj): | ||
return obj.dispense_item_identifier | ||
|
||
@admin.display( | ||
description="Subject #", | ||
ordering="dispense__rx__registered_subject__subject_identifier", | ||
) | ||
def subject(self, obj): | ||
return obj.dispense.rx.registered_subject.subject_identifier | ||
|
||
@admin.display( | ||
description="Location", | ||
ordering="dispense__location", | ||
) | ||
def location(self, obj): | ||
return obj.dispense.location | ||
|
||
@admin.display( | ||
description="dispensed by", | ||
ordering="dispense__dispensed_by", | ||
) | ||
def dispensed_by(self, obj): | ||
return obj.dispense.dispensed_by | ||
|
||
@admin.display(description="item date", ordering="dispense_item_datetime") | ||
def dispense_date(self, obj): | ||
return to_local(obj.dispense_item_datetime).date() | ||
|
||
@admin.display(description="DISPENSE #") | ||
def dispense_changelist(self, obj): | ||
url = reverse("edc_pharmacy_admin:edc_pharmacy_dispense_changelist") | ||
url = f"{url}?q={obj.dispense.id}" | ||
context = dict(url=url, label=obj.dispense.dispense_identifier, title="Go to dispense") | ||
return render_to_string("edc_pharmacy/stock/items_as_link.html", context=context) | ||
|
||
@admin.display(description="Stock #") | ||
def stock_changelist(self, obj): | ||
url = reverse("edc_pharmacy_admin:edc_pharmacy_stock_changelist") | ||
url = f"{url}?q={obj.stock.code}" | ||
context = dict(url=url, label=obj.stock.code, title="Go to stock") | ||
return render_to_string("edc_pharmacy/stock/items_as_link.html", context=context) |
Oops, something went wrong.