Adding new fields to Sample

Hi everyone, I am looking to add new fields to Sample, by developing a custom_lims add on to modify Sample and Patient fields. The problem is I cannot access ISample or Sample (commented below). Can someone who went through this help me? I am working with docker image of 2.x.

extender.py ----->
from zope.interface import implements
from zope.component import adapts
from plone.app.content.interfaces import INameFromTitle
from bika.lims.content.sample import Sample # does not work
from bika.lims.interfaces import ISample # does not work
from senaite.core.interfaces import ISamples # does not work
from senaite.lims.content.sample import Sample # does not work
from archetypes.schemaextender.interfaces import ISchemaExtender, IBrowserLayerAwareExtender
from archetypes.schemaextender.interfaces import ISchemaModifier
from Products.Archetypes import atapi

from custom.lims.interfaces import ICustomLimsLayer # your browser layer

class SampleExtender(object):
implements(ISchemaExtender, IBrowserLayerAwareExtender)
adapts(ISample)
layer = ICustomLimsLayer
def init(self, context):
self.context = context
def getFields(self):
return [
atapi.StringField(
“SampleSource”,
required=False,
searchable=True,
schemata=“Sample”,
widget=atapi.StringWidget(
label=“Sample Source”,
description=“Enter the source of the sample”,
),
)
]
docker-compose.yaml ---->
senaite:
image: senaite/senaite:2.x
ports:
- “8082:8080”
volumes:
- senaite_data:/data
- ./src:/home/senaite/senaitelims/src
- ./src:/plone/instance/src
restart: unless-stopped
environment:
ADDONS: “senaite.patient custom.lims”
SOURCES: |
senaite.patient=git GitHub - senaite/senaite.patient: Patient handling for SENAITE branch=master
custom.lims=fs custom.lims path=src/.

This is my code extender.py, the problem is that the add view no show the new field:

from zope.interface import implements
from zope.component import adapts

from archetypes.schemaextender.interfaces import ISchemaExtender
from archetypes.schemaextender.field import ExtensionField

from Products.Archetypes.public import TextField
from Products.Archetypes.public import TextAreaWidget

from bika.lims.interfaces import IAnalysisRequest

class ExtendedTextField(ExtensionField, TextField):
“”“Campo de texto extendido para SchemaExtender.”“”

class AnalysisRequestExtender(object):
“”“Extiende el esquema de AnalysisRequest añadiendo el campo ‘partidas’.”“”
adapts(IAnalysisRequest)
implements(ISchemaExtender)
# Definir el nuevo campo.
fields = [
ExtendedTextField(
‘partidas’, # nombre interno del campo
default=‘’, # valor por defecto
widget=TextAreaWidget(
label=“Partidas”, # etiqueta visible en el formulario
description=“Ingrese las partidas asociadas”,
rows=4, cols=40,
visible={‘view’: ‘visible’, ‘edit’: ‘visible’},
),
),
]

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

def getFields(self):
    # Devolver los campos a insertar en el esquema
    return self.fields

Thanks for sharing, I am doing something similar. However, the extra fields are shown only when I click on the sample and try to edit it. It does not appear when I do ‘add Sample’. Also, it breaks and I get a SampleHeader error. I tried adapting ‘ISample’ instead, but I cannot resolve the right reference to ISample using version 2.x docker.

from zope.interface import implements
from zope.component import adapts
# from bika.lims.content.sample import Sample
# from bika.lims.interfaces import ISample
# from bika.lims.interfaces import ISample
# from senaite.lims.content.sample import Sample
from Products.Archetypes.public import AnnotationStorage, StringField, StringWidget

# from bika.lims.content.analysisrequest import IAnalysisRequest
from bika.lims.interfaces import IAnalysisRequest

class ExtraARFields(object):
    implements(ISchemaExtender)
    adapts(IAnalysisRequest)
    # adapts(ISample)
    fields = [
        StringField(
            "wellPosition",
            storage=AnnotationStorage(),
            required=False,
            mutator="setWellPosition",
            accessor="getWellPosition",
            widget=StringWidget(
                label="Well Position",
                visible={'view': 'visible', 'edit': 'visible'},
            ),
        )
    ]

This is my docker-compose,


services:
  instance1:
    image: senaite/senaite:2.x
    ports:
      - 8082:8080
    volumes:
      - senaite_data:/data
      - ./src/custom.lims:/home/senaite/senaitelims/src/custom.lims
      - ./src/custom.lims:/plone/instance/src/custom.lims
    deploy:
      resources:
        limits:
          cpus: "1"
          memory: 2048MB
    environment:
      ADDONS: "custom.lims"
      SOURCES: |
          custom.lims=fs custom.lims path=src/
      BUILDOUT_CONFIG: custom.cfg
      TZ: "UTC"

We are in the same problem, I am devepment a senaite addon on:

github.com

GitHub - hochkofler/senaite.manufacture

Contribute to hochkofler/senaite.manufacture development by creating an account on GitHub.

My addon aims to extend SENAITE’s functionality for the pharmaceutical industry where I work.
It focuses on product registration, product presentations, and linking to batches.
It also records deviations and nonconformities based on obtained samples.

Currently, senaite.manufacture only creates new product content.

I’m from Bolivia (my native language is Spanish). If you need any support we can help each other, you can contact me privately (I sent you my email and number).

and once we have solved the problem we will post the solution in this thread