Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #196 from senaite/client-editable-internal-client
Browse files Browse the repository at this point in the history
Allow to edit the client on batch creation if internal patient
  • Loading branch information
ramonski authored Jul 24, 2020
2 parents 004ef7f + 9858629 commit da57652
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bika/health/adapters/referencewidget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from bika.health import logger
from bika.health.utils import get_client_from_chain
from bika.health.utils import is_external_client
from bika.health.utils import resolve_query_for_shareable
from bika.lims import api
from bika.lims.adapters.referencewidgetvocabulary import \
Expand Down Expand Up @@ -153,8 +154,7 @@ def get_raw_query(self):
context_portal_type = api.get_portal_type(self.context)
if context_portal_type in self.internally_shared_types:

# Current context can be shared internally (e.g. Batch)
if client:
if client and is_external_client(client):
# Display only the current Client in searches
criteria = self.resolve_query(portal_type, client, False)

Expand Down
12 changes: 10 additions & 2 deletions bika/health/adapters/widgetvisibility/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#
# Copyright 2018-2020 by it's authors.
# Some rights reserved, see README and LICENSE.

from bika.health.interfaces import IDoctor
from bika.health.interfaces import IPatient
from bika.health.utils import is_from_external_client
from bika.lims.adapters.widgetvisibility import SenaiteATWidgetVisibility
from bika.lims.interfaces import IClient

Expand All @@ -33,7 +35,10 @@ def __init__(self, context):

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
the container is a Patient that belongs to an external client or when
the container is a Client. If the container is a Patient that belongs to
an internal client, the field is kept editable, cause user might want to
assign the batch to an internal client other than the current one.
"""
if mode == "edit":
container = self.context.aq_parent
Expand All @@ -42,7 +47,10 @@ def isVisible(self, field, mode="view", default="visible"):
# 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"
# User might want to assign the batch to an internal client
# other than the Patient's
if is_from_external_client(container):
return "readonly"

elif IClient.providedBy(container):
return "readonly"
Expand Down
7 changes: 5 additions & 2 deletions bika/health/monkeys/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Some rights reserved, see README and LICENSE.

from bika.health.interfaces import IPatient
from bika.health.utils import is_from_external_client
from bika.lims.interfaces import IClient


Expand All @@ -30,13 +31,15 @@ def getClient(self):
# The Batch belongs to an External Client
return parent

elif IPatient.providedBy(parent):
elif IPatient.providedBy(parent) and is_from_external_client(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
# The Batch belongs to an Internal Client, either because is directly
# assigned to the Client or because belongs to a Patient from an
# internal client
return parent

# The Batch belongs to the laboratory (no Client assigned)
Expand Down
10 changes: 8 additions & 2 deletions bika/health/static/js/bika.health.batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ function HealthBatchEditView() {
return succeed;
}

this.isPatientEditable = function() {
return $('#Patient').attr("type") != "hidden";
}

this.flushDoctor = function() {
// Flush doctor field
$('#Doctor').val('');
Expand All @@ -184,8 +188,10 @@ function HealthBatchEditView() {
function loadEventHandlers() {
$("#Client").bind("selected paste blur", function(){
var uid = getElementAttr('#Client', 'uid');
// Flush Patient field
that.fillPatient(null);
// Flush Patient field, but only if is editable!
if (that.isPatientEditable()) {
that.fillPatient(null);
}
// Flush Doctor field
that.flushDoctor();
// Applies the filtering for other client-related fields
Expand Down

0 comments on commit da57652

Please sign in to comment.