Esempio n. 1
0
def handle_after_submit(context, request, state):
    """Handles actions provided in extra_buttons slot from edit forms
    """
    status_id = "created"
    if request.get("form.button.new_sample"):
        # Redirect to Sample Add from Patient
        next_url = api.get_url(context)
        if IPatient.providedBy(context):
            uid = context.UID()
            client = context.getPrimaryReferrer()
            folder = client or api.get_portal().analysisrequests
            folder_url = api.get_url(folder)
            ar_count = get_default_num_samples()
            next_url = "{}/ar_add?Patient={}&ar_count={}".format(
                folder_url, uid, ar_count)

        # Redirect to Sample Add form from Batch
        elif IBatch.providedBy(context):
            ar_count = get_default_num_samples()
            next_url = "{}/ar_add?ar_count={}".format(next_url, ar_count)

        state.setNextAction('redirect_to:string:{}'.format(next_url))

    elif request.get("form.button.new_batch"):
        # Redirect to New Batch from Patient
        next_url = api.get_url(context)
        if IPatient.providedBy(context):
            # Create temporary Batch inside Patient context (the case will be
            # moved in client's folder later thanks to objectmodified event)
            next_url = "{}/createObject?type_name=Batch".format(next_url)
            #tmp_path = "portal_factory/Batch/{}".format(tmpID())
            #tmp_obj = context.restrictedTraverse(tmp_path)
            #batch_url = api.get_url(tmp_obj)
            #next_url = "{}/edit".format(batch_url)

        state.setNextAction('redirect_to:string:{}'.format(next_url))

    elif IPatient.providedBy(context):
        # Redirect to Patient's samples view
        next_url = "{}/analysisrequests".format(api.get_url(context))
        state.setNextAction('redirect_to:string:{}'.format(next_url))
    else:
        status_id = "success"
    return status_id
Esempio n. 2
0
    def __call__(self, context):
        if IPatient.providedBy(context):
            return context

        # Try to get the client from selected Batch
        batch = BatchDefaultFieldValue(self.request)(context)
        patient = batch and batch.getField("Patient").get(context) or None
        if patient:
            return patient

        # Try with patient explicitly defined in request
        return self.get_object_from_request_field("Patient")
Esempio n. 3
0
    def isVisible(self, field, mode="view", default="visible"):
        """Renders Patient and ClientPatientID fields as hidden if the current
        mode is "edit" and the the container is a Patient or if the Batch has
        a Patient already assigned (do not allow the modification of Patient)
        """
        if mode == "edit":
            container = self.context.aq_parent
            if IPatient.providedBy(container):
                return "readonly"

            # Do not allow the edition of Patient if assigned already
            patient = self.context.getField("Patient").get(self.context)
            if patient:
                return "readonly"

        return default
Esempio n. 4
0
def getClient(self):
    """Returns the Client from the Batch passed-in, if any
    """
    parent = self.aq_parent
    if IClient.providedBy(parent):
        # The Batch belongs to an External Client
        return parent

    elif IPatient.providedBy(parent):
        # The Batch belongs to a Patient
        return parent.getClient()

    parent = self.getField("Client").get(self)
    if parent:
        # The Batch belongs to an Internal Client
        return parent

    # The Batch belongs to the laboratory (no Client assigned)
    return None
Esempio n. 5
0
def resolve_client(obj, field_name=None):
    """Tries to resolve the client for the given obj
    """
    if not field_name:
        field_name = "Client"
        if IPatient.providedBy(obj) or IDoctor.providedBy(obj):
            field_name = "PrimaryReferrer"

    # Try to get the client directly from the field
    client = obj.getField(field_name).get(obj)
    if client and IClient.providedBy(client):
        return client

    # Maybe the object is being created
    if obj.isTemporary():
        parent = obj.getFolderWhenPortalFactory()
    else:
        parent = api.get_parent(obj)

    # Get the Client from the acquisition chain, if any
    return get_client_from_chain(parent)
Esempio n. 6
0
    def isVisible(self, field, mode="view", default="visible"):
        """Renders the Client field as hidden if the current mode is "edit" and
        the container is either a Patient or a Client
        """
        if mode == "edit":
            container = self.context.aq_parent

            # If the Batch is created or edited inside a Client, Patient or
            # Doctor make Client field to be rendered, but hidden to prevent
            # the error message "Patient is required, please correct".
            if IPatient.providedBy(container):
                return "readonly"

            elif IClient.providedBy(container):
                return "readonly"

            elif IDoctor.providedBy(container):
                # Doctor can be assigned to a Client or not!
                if container.getClient():
                    return "readonly"

        return default
Esempio n. 7
0
from bika.health.subscribers import try_share_unshare
from bika.lims.interfaces import IClient


def ObjectCreatedEventHandler(case, event):
    """Actions done when a Batch (Clinic Case) is created. Automatically assigns
    value for "PrimaryReferrer" (Client), "Patient" and "Doctor" fields
    """
    if case.isTemporary():
        # Assign client
        client = resolve_client(case, field_name="Client")
        case.getField("Client").set(case, client)

        # Assign the Patient
        parent = case.getFolderWhenPortalFactory()
        if IPatient.providedBy(parent):
            # Batch is being created inside a Patient
            cpid = parent.getClientPatientID()
            case.getField("Patient").set(case, parent)
            case.getField("ClientPatientID").set(case, cpid)

        elif IDoctor.providedBy(parent):
            # Batch is being created inside a Doctor
            case.getField("Doctor").set(case, parent)


def ObjectModifiedEventHandler(case, event):
    """Actions to be done when a Batch is modified. Transitions the case to
    "shared" or "open" when necessary

    There is an ObjectModifiedEventHandler registered at senaite.core already,
 def getPatientsGender(self):
     patient = self.aq_parent
     return IPatient.providedBy(patient) and patient.getGender() or "dk"
Esempio n. 9
0
    def __call__(self, context):
        if IPatient.providedBy(context):
            return context

        # Try with doctor explicitly defined in request
        return self.get_object_from_request_field("Patient")