Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue using excluded_fields #110

Open
smseidl opened this issue Jun 20, 2024 · 2 comments
Open

Issue using excluded_fields #110

smseidl opened this issue Jun 20, 2024 · 2 comments

Comments

@smseidl
Copy link

smseidl commented Jun 20, 2024

Hi again - sorry for creating so many issues :-(
This one seems to be an actual issue. I'm trying to use the excluded_fields in my report View to remove some options from the filter form. My model has a bunch of different Foreign Keys that are showing up in the form. I want to limit that some what. When I put documents in the excluded_fields list it works, but I am unable to add any of the other without producing an error.

class Visit(models.Model):
    """Details for a medical visit"""
    date = models.DateField(null=False)
    patient = models.ForeignKey(Member, on_delete=models.PROTECT)
    provider = models.ForeignKey(Provider, on_delete=models.PROTECT)
    insurance = models.ForeignKey(InsurancePlan, on_delete=models.SET_NULL,blank=True, null=True)
    service = models.ForeignKey(Service,on_delete=models.PROTECT,verbose_name="Service",blank=False,null=False,default=Service.get_default_pk)
    eob = models.ForeignKey(EOB, on_delete=models.SET_NULL,null=True,blank=True,)
    documents = models.ManyToManyField(Document, related_name="Visits", )  

Error

2024-06-19 19:29:57 - ERROR - django.request - log_response - Internal Server Error: /reports/
Traceback (most recent call last):
  File "/workspaces/medicalexpensetracker/.venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/workspaces/medicalexpensetracker/.venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/workspaces/medicalexpensetracker/.venv/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/workspaces/medicalexpensetracker/.venv/lib/python3.10/site-packages/django/contrib/auth/mixins.py", line 135, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/workspaces/medicalexpensetracker/.venv/lib/python3.10/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/workspaces/medicalexpensetracker/.venv/lib/python3.10/site-packages/slick_reporting/views.py", line 185, in get
    form_class = self.get_form_class()
  File "/workspaces/medicalexpensetracker/.venv/lib/python3.10/site-packages/slick_reporting/views.py", line 248, in get_form_class
    return self.form_class or report_form_factory(
  File "/workspaces/medicalexpensetracker/.venv/lib/python3.10/site-packages/slick_reporting/forms.py", line 271, in report_form_factory
    del fkeys_map[excluded]
KeyError: 'eob'
@RamezIssac
Copy link
Owner

Can you share your ReportView ?

@smseidl
Copy link
Author

smseidl commented Jun 24, 2024

Sorry - busy weekend. Here's the View you wanted and a sample of one of the Class based ComputationField... all are very similar in definition.

@report_field_register
class TotalCCPaymentField(ComputationField):
    name = "sum__paidCC"
    calculation_field = "v_pay_dtl__paydetail_amount"  # the field we want to compute on
    calculation_method = Sum  # What method we want, default to Sum
    verbose_name = "Total CC Paid $"
    # base_q_filters={"v_pay_dtl__parentPayment__type","CC"}

    def get_queryset(self):
        queryset = self.report_model.objects
        # if self.base_q_filters:
        queryset = queryset.filter(v_pay_dtl__parentPayment__type="CC")
        # if self.base_kwargs_filters:
            # queryset = queryset.filter(**self.base_kwargs_filters)
        return queryset.order_by()
        
class ReportPageView(ReportView):
    report_title = "Visits by Patient"
    report_model = Visit
    date_field = "date"
    group_by = "patient"
    excluded_fields =["documents"]

    columns = [
        "name",
        ComputationField.create(
            Count, "id",verbose_name="# Visits",name="sum__value"
        ),
        isPaidField,
        ComputationField.create(
            Sum, "charge", name="sum__charge", verbose_name="Total Charged $"
        ),
        TotalPaidReportField,       #similar to TotalCCPaymentField
        TotalCCPaymentField,    
        TotalCheckPaymentField, #similar to TotalCCPaymentField
        TotalEXPPaymentField,     #similar to TotalCCPaymentField
    ]

    chart_settings = [
        Chart(
            "Total Visits",
            Chart.BAR,
            data_source=["sum__value"],
            title_source=["name"],
        ),
        Chart(
            "Total Charges $ [PIE]",
            Chart.PIE,
            data_source=["sum__charge"],
            title_source=["name"],
        ),
        Chart(
            "Total Unpaid $ [PIE]",
            Chart.PIE,
            data_source=["count__ispaid"],
            title_source=["name"],
        )        
    ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants