Adding custom column to the Samples table (view) issue

Hi,

We want to have Patient ID as a column in the Samples Table.

As it defined in Senaite.App.Lisitng manual:

  1. Created own subscriber:
    class PatientSamplesView(object):
        adapts(IListingView)
        implements(IListingViewAdapter)

        def __init__(self, listing, context):
            self.listing = listing
            self.context = context

        def before_render(self):
            self.listing.columns["PatientID"] = {
                "title": "Patient ID",
                "toggle": True,
                "sortable": True,
            }

        def folder_item(self, obj, item, index):        
            obj = api.get_object(obj)
            patient = get_obj_from_field(obj, 'Patient', None)
            patient_id = api.get_id(patient)
            patient_url = api.get_url(patient)
            item["PatientID"] = patient_id
            item["replace"]["PatientID"] = get_link(pa_url, value=patient_id)
            return item
  1. Registred adapter in configure.zcml

As the result:

  • adapter works;
  • AJAX-request delivers Patient ID values for each table item;
  • column name added to “Configure table columns” - section (where you can toggle and reorder columns);

BUT column not showing in the Samples table. No manipulations help (resetting/reorder columns).

Any idea where to look?

Plone ver: 5.2.4
Senaite.lims: 2.x (latest)
Senaite.core: 2.x (latest)

1 Like

Hi @toropok,

you need to add your column key to the review_states config for the states it should be displayed.
I think this part is missing in the howto…

Best regards,
Ramon

1 Like

Thank you @ramonski

that worked perfectly:

def before_render(self):
       
        ....
 
        review_states = [self.listing.review_states[0]]
        for review_state in review_states:
            review_state.update({"columns": self.listing.columns.keys()})    

regards,
–Leo

1 Like

Hi,

I am working on customizing the Analysis Reports section under the Clients view in SENAITE LIMS. Specifically, I want to display Patient Names and Test Profiles/Test Names as additional columns in the reports table.

Here’s what I have tried so far:

  1. I created a subscriber for the Samples table as follows:

(src/bika/lims/browser/publish/reports_listing.py)

def folderitem(self, obj, item, index):
........

        # Fetch patient name
        sample_patient_fullname = api.to_utf8(
            obj.getPatientFullName, default="")

        item["MRN"] = sample_patient_mrn
        item["Patient"] = sample_patient_fullname

        # get the patient object
        patient = self.get_patient_by_mrn(sample_patient_mrn)
.........

  1. I registered the adapter in configure.zcml.

Outcome:

Problem:

  • The Patient Names column does not show up in the Analysis Reports tab of Client Samples table, regardless of resetting or reordering columns.

I am using:

  • SENAITE.LIMS: 2.x (latest)
  • SENAITE.Core: 2.x (latest)

Additionally, I want to add Patient Names and Test Profiles/Test Names as columns in the Analysis Reports table. Could you advise which files need to be modified and how to achieve this? Any guidance on troubleshooting the missing column issue in the Samples table would also be appreciated.

Thanks in advance for your help!

hi

pls show your stacktrace and how you registered it in the configure.zcml

Hi @toropok ,

Thank you for your response and willingness to assist!

I managed to solve the issue, and I’d like to share my solution in case it helps someone else working on similar customizations in published reports_listing table.

What I did to resolve it:

  1. I added a new column definition to the table:

src/bika/lims/browser/publish/reports_listing.py

def __init__(self, context, request):
        super(ReportsListingView, self).__init__(context, request)
..........................
self.columns = collections.OrderedDict((
            ("Info", {
                "title": "",
                "toggle": True},),
            ("AnalysisRequest", {
                "title": _("Primary Sample"),
                "index": "sortable_title"},),
            ("PatientFullName", {
                "title": _("Patient Full Name")},),  # New column added here
...........................
  1. I updated the folderitem method to populate the new column:
    def folderitem(self, obj, item, index):
        """Augment folder listing item
        """
.............................................
        # Include Patient Full Name
        patient_full_name = obj.getPatientFullName()  # This is a placeholder, replace with actual method to get patient full name
        item["PatientFullName"] = patient_full_name

.............................................

After these changes, the “Patient Full Name” column now appears in the **Published Reports ** section and displays the data as expected.

Thanks again for your help, and I hope this solution proves useful to others working on similar tasks.

Warm regards,
ersan