Welcome to NHClinical’s documentation!

NH Odoo Fixes

NH Odoo fixes wraps and amends Odoo functionality for use with NHClinical.

fields.many2many Set Override

fix_odoo8_fields_many2many_set.new_set(self, cr, model, id, name, values, user=None, context=None)[source]

read_group Fill Results

fix_read_group_fill_results._append_all(self, cr, uid, read_group_result, all_groups, all_group_tuples, groupby, result_template, domain, count_field)[source]
fix_read_group_fill_results._append_left

staticmethod(function) -> method

Convert a function to be a static method.

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C: def f(arg1, arg2, …): … f = staticmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see the classmethod builtin.

fix_read_group_fill_results._append_right

staticmethod(function) -> method

Convert a function to be a static method.

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C: def f(arg1, arg2, …): … f = staticmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see the classmethod builtin.

fix_read_group_fill_results._read_group_fill_results(self, cr, uid, domain, groupby, remaining_groupbys, aggregated_fields, count_field, read_group_result, read_group_order=None, context=None)[source]

Helper method for filling in empty groups for all possible values of the field being grouped by

Fix Server Shutdown Issue

fix_server_shutdown_issue.fixed_close_socket(self, sock)[source]

Closes a socket instance cleanly

Parameters:sock (socket.socket) – the network socket to close

Fixes to osv.expression

fixes_expression._quote(to_quote)[source]
fixes_expression.parse(self, cr, uid, context)[source]

Transform the leaves of the expression

The principle is to pop elements from a leaf stack one at a time. Each leaf is processed. The processing is a if/elif list of various cases that appear in the leafs (many2one, function fields, …). Two things can happen as a processing result: - the leaf has been modified and/or new leafs have to be introduced

in the expression; they are pushed into the leaf stack, to be processed right after
  • the leaf is added to the result
Some internal var explanation:
var obj working_model:
 model object, model containing the field (the name provided in the left operand)
var list field_path:
 left operand seen as a path (foo.bar -> [foo, bar])
var obj relational_model:
 relational model of a field (field._obj) ex: res_partner.bank_ids -> res.partner.bank

ORM timestamp fixes

orm_fixes.utc_timestamp

staticmethod(function) -> method

Convert a function to be a static method.

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C: def f(arg1, arg2, …): … f = staticmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see the classmethod builtin.

Remove the exception name from error dialogs

remove_exception_name_from_error_dialogs.new_init(self, name, value)[source]

Validation helpers

A place for generic validation functions.

In some places the variable name date_time has been used to avoid conflict with the imported datetime class.

validate._convert_string_to_datetime(date_time)[source]
validate.in_min_max_range(min_value, max_value, value)[source]
validate.not_in_the_future(date_time)[source]
validate.not_in_the_future_multiple_args(*args)[source]
validate.start_datetime_not_after_end_datetime(start_datetime, end_datetime)[source]

NH Activity

activity.py defines the classes and methods to allow for an audit event driven system to be built on top of it.

activity.data_model_event(callback=None)[source]

Decorator for activity methods. This will automatically call a method with the same name on the data model related to the activity instance after calling the activity method. The result returned is the one from the data_model method.

nh_activity

class activity.nh_activity(pool, cr)[source]

Class representing any event that needs to be recorded by the system.

Any user executed event that has a starting and ending point in time could be represented as an instance of this class.

Most of them will need extra information recorded within them and that is why this class is closely related to the data model classes, which could be also named activity type.

assign(**kwargs)[source]

Sets user_id to the specified user if allowed by access rights.

See data model assign for full implementation.

Parameters:
Returns:

True

Return type:

bool

assign_locked
cancel(**kwargs)[source]

Sets activity state to cancelled and records the date and user on date_terminated and terminate_uid respectively. See data model cancel for full implementation.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
child_ids

One2many field; the value of such a field is the recordset of all the records in comodel_name such that the field inverse_name is equal to the current record.

Parameters:
  • comodel_name – name of the target model (string)
  • inverse_name – name of the inverse Many2one field in comodel_name (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • limit – optional limit to use upon read (integer)

The attributes comodel_name and inverse_name are mandatory except in the case of related fields or field extensions.

complete(**kwargs)[source]

Sets activity state to completed and records the date and user on date_terminated and terminate_uid respectively. See data model complete for full implementation.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
create(*args, **kwargs)[source]

Creates an activity. Raises an exception if data_model isn’t in parameter vals or if data_model doesn’t exist as a table in the database.

Parameters:vals (dict) – must include data_model key:value pair
Raises:osv.except_osv
Returns:id of created activity
Return type:int
create_date
create_uid

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

created_ids

One2many field; the value of such a field is the recordset of all the records in comodel_name such that the field inverse_name is equal to the current record.

Parameters:
  • comodel_name – name of the target model (string)
  • inverse_name – name of the inverse Many2one field in comodel_name (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • limit – optional limit to use upon read (integer)

The attributes comodel_name and inverse_name are mandatory except in the case of related fields or field extensions.

creator_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

data_model

Very similar to Char but used for longer contents, does not have a size and usually displayed as a multiline text box.

Parameters:translate – whether the value of this field can be translated
data_ref
date_deadline
date_expiry
date_planned
date_scheduled
date_started
date_terminated
get_recursive_created_ids(*args, **kwargs)[source]

Recursively gets ids of all activities created by an activity or all activitie

Parameters:activity_id (int) – id of activity
Returns:list of activity ids
Return type:list
notes

Very similar to Char but used for longer contents, does not have a size and usually displayed as a multiline text box.

Parameters:translate – whether the value of this field can be translated
parent_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

schedule(**kwargs)[source]

Sets date_scheduled to the specified date and changes the activity state to scheduled. See data model schedule for full implementation.

Parameters:
  • activity_id (int) – activity id
  • date_scheduled (str) – date formatted string
Returns:

True

Return type:

bool

sequence
start(**kwargs)[source]

Sets activity state to started.

See data model start for full implementation.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
state
Parameters:
  • selection – specifies the possible values for this field. It is given as either a list of pairs (value, string), or a model method, or a method name.
  • selection_add – provides an extension of the selection in the case of an overridden field. It is a list of pairs (value, string).

The attribute selection is mandatory except in the case of related fields or field extensions.

submit(**kwargs)[source]

Updates activity data. See data model submit for full implementation.

Parameters:
  • activity_id (int) – activity id
  • vals (dict) – dictionary containing {field_name: new_value}
Returns:

True

Return type:

bool

summary

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
terminate_uid

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

unassign(**kwargs)[source]

Sets user_id to False. Only the current owner of the activity is allowed to do this action. See data model unassign for full implementation.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
update_activity(**kwargs)[source]

This method is meant to refresh any real time data that needs to be refreshed on the activity. Does nothing as default. Included for potential utility on some activity types.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
user_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

write(*args, **kwargs)[source]

Writes to an activity. sequence will be updated if the the state of the activity is changed.

Parameters:
  • ids (list) – activity ids to write to
  • vals (dict) – values to write to activity
Returns:

True

Return type:

bool

write_date
write_uid

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

nh_activity_data

class activity.nh_activity_data(pool, cr)[source]

Abstract class that relates to activity from which every activity type will inherit from.

activity_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

assign(*args, **kwargs)[source]

Assigns activity to a user. Raises an exception if it is already assigned to another user. If it is already assigned to the same user, then the activity is locked.

Parameters:
Returns:

True

Return type:

bool

cancel(*args, **kwargs)[source]

Cancels an activity and sets its date_terminated.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
check_action(state, action)[source]
complete(*args, **kwargs)[source]

Completes an activity and sets its date_terminated.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
complete_ui(*args, **kwargs)[source]
convert_record_to_data_ref(*args, **kwargs)[source]

Useful for getting the value for domains so you can search on data_ref.

Returns:
Return type:str
create(vals) → record[source]

Creates a new record for the model.

The new record is initialized using the values from vals and if necessary those from default_get().

Parameters:

vals (dict) –

values for the model’s fields, as a dictionary:

{'field_name': field_value, ...}

see write() for details

Returns:

new record created

Raises:
  • AccessError
    • if user has no create rights on the requested object
    • if user tries to bypass access rules for create on the requested object
  • ValidateError – if user tries to enter invalid value for a field that is not in selection
  • UserError – if a loop would be created in a hierarchy of objects a result of the operation (such as setting an object as its own parent)
create_activity(*args, **kwargs)[source]

Creates a new activity of the current data type.

Parameters:
  • vals_activity (dict) – values to save in the activity
  • vals_data (dict) – values to save in the data model<activity.nh_activity_data
Returns:

activity id.

Return type:

int

date_started
date_terminated
static format_many_2_many_fields(field_names)[source]
get_activity()[source]
classmethod get_description()[source]
get_latest_activity(*args, **kwargs)[source]

Return the most recent activity for a given data model.

Parameters:
  • data_model
  • spell_activity_id
Returns:

get_open_activities(*args, **kwargs)[source]

Get open activity(s) for one spell or all spells. :return: list of activities :rtype: list

get_open_activity(*args, **kwargs)[source]

Get the latest open activity for the given model. The method assumes that only one open activity at a time is possible for the given model. If more than one is found an exception is raised.

Parameters:spell_activity_id
Returns:
is_action_allowed(state, action)[source]

Tells us if the specified action is allowed in the specified state.

Parameters:
  • state (str) – state of the activity where we want to execute the action.
  • action (str) – action we want to execute.
Returns:

True or False

Return type:

bool

name

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
schedule(*args, **kwargs)[source]

Schedules an activity and sets its date_scheduled.

Parameters:
  • activity_id (int) – activity id
  • date_scheduled (str) – date formatted string
Returns:

True

Return type:

bool

start(*args, **kwargs)[source]

Starts an activity and sets its date_started.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
state

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
submit(*args, **kwargs)[source]

Updates submitted data. It creates a new instance of the data model if it does not exist yet.

Parameters:
Returns:

True

Return type:

bool

submit_ui(*args, **kwargs)[source]
terminate_uid

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

unassign(*args, **kwargs)[source]

Unassigns an activity. Raises an exception if it is not assigned. Raises an exception if another user tries to unassign an activity not assigned to them.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
update_activity(*args, **kwargs)[source]

Hook for data-driven activity update. Should be called on methods that change activity data.

NH Clinical

Activity Extension

Extends module nh_activity, introducing patients, spells, users and locations. See also base module for more information on their representative classes.

activity_extension.list2sqlstr()

Activity

class activity_extension.nh_activity(pool, cr)[source]

Extends class nh_activity.

cancel_open_activities(*args, **kwargs)[source]

Cancels all open activities of parent activity.

Parameters:
  • parent_id (int) – id of the parent activity
  • model (str) – model (type) of activity
Returns:

True if all open activities are cancelled or if there are no open activities. Otherwise, False

Return type:

bool

cancel_with_reason(*args, **kwargs)[source]

Cancel the activity add a cancel reason to it.

Parameters:
  • activity_id
  • cancel_reason_id
Returns:

True

Return type:

bool

create(*args, **kwargs)[source]

Extends Odoo’s create() method.

Writes user_ids for responsible users of the activities` location.

Parameters:vals (doct) – values to create record
Returns:nh_activity id
Return type:int
update_spell_users(*args, **kwargs)[source]

Updates spell activities with the user_ids of users responsible for parent locations of spell location.

Parameters:user_ids (list) – user ids. See class res_users
Returns:True
Return type:bool
update_users(*args, **kwargs)[source]

Updates activities with the user_ids of users responsible for the activities’ locations.

Parameters:user_ids (list) – user ids. See class res_users
Returns:True
Return type:bool
write(*args, **kwargs)[source]

Extends Odoo’s write() method.

Also writes user_ids for responsible users of the activities’ location. See class nh_clinical_location.

Parameters:
  • ids (list) – nh_activity record ids
  • vals (dict) – values to update records (may include location_id)
Returns:

True

Return type:

bool

Activity Data

class activity_extension.nh_activity_data(pool, cr)[source]

Extends class nh_activity_data.

_audit_shift_coordinator(*args, **kwargs)[source]

Writes shift_coordinator_id for ward manager responsible for the activity’s location. If location doesn’t exist or it’s not within the ward or there’s no ward assigned, then no audit happens.

Parameters:activity_id (int) – activity id
Returns:True if the shift_coordinator_id is stored. Otherwise False
Return type:bool
cancel(*args, **kwargs)[source]

Extends cancel() method to audit the ward manager responsible for activity location.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
complete(*args, **kwargs)[source]

Extends complete() method to audit the ward manager responsible for activity location.

Parameters:activity_id (int) – activity id
Returns:True
Return type:bool
get_activity_location_id(*args, **kwargs)[source]

Gets the activity’s location id.

Parameters:activity_id (int) – activity id
Returns:location_id. See class nh_clinical_location
Return type:int
get_activity_patient_id(*args, **kwargs)[source]

Gets the activity’s patient id.

Parameters:activity_id (int) – activity id
Returns:patient_id. See class nh_clinical_patient
Return type:int
get_activity_pos_id(*args, **kwargs)[source]

Gets activity point of service (POST) id.

Parameters:activity_id (int) – activity id of updated activity
Returns:POS id
Return type:int
get_activity_user_ids(*args, **kwargs)[source]

Gets the activity’s user ids.

Parameters:activity_id (int) – activity id
Returns:patient_id. See class res_users
Return type:list
get_child_activity(activity_model, activity, data_model, context=None)[source]

Generator to return the child activity of the specified data model. The inputs use the Odoo v8 API record sets

Parameters:
  • activity_model – Instance of nh.activity environment
  • activity – Activity instance to get child of
  • data_model – data_model child activity should be
  • context – Odoo context
Returns:

Record of child activity

trigger_policy(*args, **kwargs)[source]

Triggers the list of activities in the _POLICY['activities'] list.

Parameters:
  • activity_id (int) – id of activity triggering policy
  • location_id (int) – location id [optional]. Required for checking context
  • case (bool or int) – default False. Otherwise integer related to risk of patient
Returns:

True

Return type:

bool

update_activity(*args, **kwargs)[source]

Extends update_activity() method.

Parameters:activity_id (int) – activity id of updated activity
Returns:True
Return type:bool

Cancel Reason

class activity_extension.nh_cancel_reason(pool, cr)[source]

Cancellation reason for an activity.

Activity Access

class activity_extension.nh_clinical_activity_access(pool, cr)[source]

Adds an additional permission type called perm_responsibility to an activity. This defines if a particular user group can or cannot perform an activity.

_auto = False
_columns = {'location_activity_ids_text': <openerp.osv.fields.text object at 0x7fcc88e99890>, 'location_ids_text': <openerp.osv.fields.text object at 0x7fcc89228c90>, 'parent_location_activity_ids_text': <openerp.osv.fields.text object at 0x7fcc88e991d0>, 'parent_location_ids_text': <openerp.osv.fields.text object at 0x7fcc88e99910>, 'user_id': <openerp.osv.fields.many2one object at 0x7fcc88fb05d0>}
_module = 'activity_extension'
_name = 'nh.clinical.activity.access'
init(*args, **kwargs)[source]
location_activity_ids_text

Very similar to Char but used for longer contents, does not have a size and usually displayed as a multiline text box.

Parameters:translate – whether the value of this field can be translated
location_ids_text

Very similar to Char but used for longer contents, does not have a size and usually displayed as a multiline text box.

Parameters:translate – whether the value of this field can be translated
parent_location_activity_ids_text

Very similar to Char but used for longer contents, does not have a size and usually displayed as a multiline text box.

Parameters:translate – whether the value of this field can be translated
parent_location_ids_text

Very similar to Char but used for longer contents, does not have a size and usually displayed as a multiline text box.

Parameters:translate – whether the value of this field can be translated
user_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

ADT

adt.py defines a set of activity types to deal with patient management systems operations.

Admit

class adt.nh_clinical_adt_patient_admit(pool, cr)[source]

Represents the patient admission operation in the patient management system. (A01 Message)

Consulting and referring doctors are expected in the submitted values in the following format:

[...
    {
        'type': 'c' or 'r', 'code': 'code_string,
        'title': 'Mr', 'given_name': 'John',
        'family_name': 'Smith'
    }...
]

If doctor doesn’t exist, then a partner is created (but no user is created).

complete(*args, **kwargs)[source]

Calls complete and then creates and completes a new admission to the provided location.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data and then calls submit.

If a ward location with the provided code does not exist, it will create a new one.

Due to this behaviour the user submitting the data must be related to a point of service linked to a valid location instance of pos type, as new Wards will need to be assigned to a point of service.

Returns:True
Return type:bool

Cancel Admit

class adt.nh_clinical_adt_patient_cancel_admit(pool, cr)[source]

Represents the cancel admission operation in the patient management system. (A11 Message)

complete(*args, **kwargs)[source]

Calls complete and then cancels the last completed admission for the provided patient.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data is correct, finding the last completed instance of admission and then calls submit.

Returns:True
Return type:bool

Cancel Discharge

class adt.nh_clinical_adt_patient_cancel_discharge(pool, cr)[source]

Represents the cancel discharge operation in the patient management system. (A13 Message)

complete(*args, **kwargs)[source]

Calls complete and then cancels the last completed discharge for the provided patient.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data is correct, finding the last completed instance of discharge and then calls submit.

Returns:True
Return type:bool

Cancel Transfer

class adt.nh_clinical_adt_patient_cancel_transfer(pool, cr)[source]

Represents the cancel transfer operation in the patient management system. (A12 Message)

complete(*args, **kwargs)[source]

Calls complete and then cancels the last completed transfer for the provided patient.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data is correct, finding the last completed instance of transfer and then calls submit.

Returns:True
Return type:bool

Discharge

class adt.nh_clinical_adt_patient_discharge(pool, cr)[source]

Represents the patient discharge operation in the patient management system. (A03 Message)

complete(*args, **kwargs)[source]

Calls complete and then creates and completes a new discharge for the provided patient.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data and then calls submit.

Creates a new spell for the provided patient if there is not an open instance related to it. Requires the user to be linked to a point of service due to similar behaviour as the admission in this particular scenario.

Returns:True
Return type:bool

Patient Merge

class adt.nh_clinical_adt_patient_merge(pool, cr)[source]

Represents the patient merge operation in the patient management system. (A40 Message) Merges a patient into another patient making the resulting patient own all activities.

complete(*args, **kwargs)[source]

Calls complete and then adds every piece of information that the source patient has and the destination patient lacks into the destination patient.

The destination patient ends up being linked to all the activities both patients were linked to.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data and then calls submit.

Returns:True
Return type:bool

Register

class adt.nh_clinical_adt_patient_register(pool, cr)[source]

Represents the patient register operation in the patient management system. (A28 Message)

complete(*args, **kwargs)[source]

Creates a new instance of patient and then calls complete.

Returns:patient id
Return type:int
submit(*args, **kwargs)[source]

Checks the patient data is correct and then calls submit.

Returns:True
Return type:bool

Admit

class adt.nh_clinical_adt_patient_transfer(pool, cr)[source]

Represents the patient transfer operation in the patient management system. (A02 Message)

complete(*args, **kwargs)[source]

Calls complete and then creates and completes a new transfer for the provided patient.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data and then calls submit.

Creates a new spell for the provided patient if there is not an open instance related to it and an origin location for the transfer was provided. Requires the user to be linked to a point of service due to similar behaviour as the admission in this particular scenario.

Returns:True
Return type:bool

Update

class adt.nh_clinical_adt_patient_update(pool, cr)[source]

Represents the patient update operation in the patient management system. (A31 Message)

complete(*args, **kwargs)[source]

Overwrites the target patient instance information and then calls complete.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the patient data is correct and then calls submit.

Returns:True
Return type:bool

Spell Update

class adt.nh_clinical_adt_spell_update(pool, cr)[source]

Represents the admission update operation in the patient management system. (A08 Message)

complete(*args, **kwargs)[source]

Overwrites the target spell information and then calls complete.

If location information needs to be updated a new instance of movement is created and completed.

If the new location is located in a different Ward than the current spell location, a policy trigger will be kicked off. As that is technically a transfer movement.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data and then calls submit.

If a location of ward usage with the provided code does not exist, it will create a new one.

Due to this behaviour the user submitting the data must be related to a point of service linked to a valid location instance of pos type, as new Wards will need to be assigned to a point of service.

Returns:True
Return type:bool

API

api.py defines the core methods to interface with the adt module.

API

class api.nh_clinical_api(pool, cr)[source]

Core API for nh_clinical

admit(*args, **kwargs)[source]

Admits a patient into a specified location.

Parameters:
  • hospital_number (str) – Hospital number of the patient
  • data (dict) – contains location_code, start_date and a list of dictionaries of consulting and referring doctors, containing the following keys: type, code, title, given_name and family_name
Returns:

True

Return type:

bool

admit_update(*args, **kwargs)[source]

Updates the spell information of a patient.

Parameters:
  • hospital_number (str) – hospital number of the patient
  • data (dict) – may contain other_identifier and patient_identifier among others
Returns:

True

Return type:

bool

cancel_admit(*args, **kwargs)[source]

Cancels the open admission of the patient.

Parameters:hospital_number (str) – hospital number of the patient
Returns:True
Return type:bool
cancel_discharge(*args, **kwargs)[source]

Cancels the last discharge of a patient.

Parameters:hospital_number (str) – hospital number of the patient
Returns:True
Return type:bool
cancel_transfer(*args, **kwargs)[source]

Cancels the last transfer of a patient.

Parameters:hospital_number (str) – hospital number of the patient
Returns:True
Return type:bool
check_activity_access(*args, **kwargs)[source]

Verifies if an activity is assigned to a user.

Parameters:
  • uid (int) – id of user to verify
  • activity_id (int) – id of activity to verify
Returns:

True if user is assigned. Otherwise False

Return type:

bool

discharge(*args, **kwargs)[source]

Discharges a patient.

Parameters:
  • hospital_number (str) – hospital number of the patient
  • data (dict) – may contain the key discharge_date
Returns:

True

Return type:

bool

merge(*args, **kwargs)[source]

Merges a specified patient into a patient.

Parameters:
  • hospital_number (str) – hospital number of the patient merged INTO
  • data (dict) – may contain the key from_identifier, the hospital number of the patient merged FROM
Returns:

True

Return type:

bool

register(*args, **kwargs)[source]

Registers a new patient in the system.

Parameters:
  • hospital_number (str) – hospital number of the patient
  • data – may contain the following keys: patient_identifier, family_name, given_name, middle_names, dob, gender and sex
Returns:

True

Return type:

bool

transfer(*args, **kwargs)[source]

Transfers the patient to a specified location.

Parameters:
  • hospital_number (str) – hospital number of the patient
  • data (dict) – required is location_code of the patient’s transfer destination
Returns:

True

Return type:

bool

update(*args, **kwargs)[source]

Update patient information.

Parameters:
  • hospital_number (str) – hospital number of the patient
  • data (dict) – may contain the following keys: patient_identifier and other_identifier among others
Returns:

True

Return type:

bool

Auditing

auditing.py defines some activity types to audit some specific operations that are not represented by any other objects in the system but still need to be audittable.

Activate Location

class auditing.nh_clinical_location_activate(pool, cr)[source]

Activity is meant to audit the activation of a Location. location_id is the location that is going to be activated by the activity complete method.

complete(*args, **kwargs)[source]

Calls complete and then sets the activity active parameter as True.

Deactivate Location

class auditing.nh_clinical_location_deactivate(pool, cr)[source]

This Activity is meant to audit the deactivation of a Location. location_id is the location that is going to be deactivated by the activity complete method.

A Location cannot be deactivated if there is a patient using it.

complete(*args, **kwargs)[source]

Calls complete and then sets the activity active parameter as False.

User Responsibility Allocation

class auditing.nh_clinical_user_responsibility_allocation(pool, cr)[source]

This activity is meant to audit the allocation of responsibility of users to locations.

complete(*args, **kwargs)[source]

Calls complete and then sets updates the location_ids list for the user.

If the user is in the HCA or Nurse user groups the method will automatically assign every location child of the ones provided on top of them. If the user is not within those user groups, that will also be done when the location is not of ward usage.

Returns:True
Return type:bool
get_allocation_locations(*args, **kwargs)[source]

Get a list locations to allocate the user to :param cr: Cursor :param uid: User ID to perform operation with :param allocation_obj: The activity data ref from a user responsibility allocation :param context: Odoo context :return: list of location ids

Context

Defines context.

Context

class context.nh_clinical_context(pool, cr)[source]

Indicates if a specific policy is applicable to a model.

A context will trigger actions related to the context. If an action is executed in a particular context, then its context-dependent actions will be triggered as a result (if there are any).

check_model(*args, **kwargs)[source]

Checks if model is applicable for the context.

Parameters:
  • ids (list) – context ids
  • model – model to check
Returns:

True if model is applicable

Return type:

bool

Raises:

except_orm if not applicable

Devices

devices.py defines a set of objects and activity types to deal with clinical devices management within the Hospital.

Device

class devices.nh_clinical_device(pool, cr)[source]

Represents a physical instance of a device, which will have its own unique serial number.

category_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

is_available
name_get() → [(id, name), ...][source]

Returns a textual representation for the records in self. By default this is the value of the display_name field.

Returns:list of pairs (id, text_repr) for each records
Return type:list(tuple)
serial_number

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
type_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Category

class devices.nh_clinical_device_category(pool, cr)[source]

Represents a group of device types that share the same category / specialty (i.e. surgical).

Connect

class devices.nh_clinical_device_connect(pool, cr)[source]

Represents the action of connecting a device to a patient.

complete(*args, **kwargs)[source]

Creates and starts a new device session and then calls complete.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data and calls submit.

Returns:True
Return type:bool

Disconnect

class devices.nh_clinical_device_disconnect(pool, cr)[source]

Represents the action of disconnecting a device from a patient.

complete(*args, **kwargs)[source]

Completes the related device session and then calls complete.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data is correct, finding the last started device session for the provided device or device type (if the specific device is not provided) and calls submit.

Returns:True
Return type:bool

Session

class devices.nh_clinical_device_session(pool, cr)[source]

Represents a period of time where an instance of device or device type (the specific physical instance of the device is not required) is being used during a spell

complete(*args, **kwargs)[source]

Sets the specified device as available and calls complete.

Returns:True
Return type:bool
get_activity_id(*args, **kwargs)[source]

Looks for a started device session for the provided patient and device type. It will throw a warning if finds more than one, as the method will only return the last started one.

Parameters:
  • patient_id (int) – patient id
  • device_type_id (int) – device type id
Returns:

device session id

Return type:

int

start(*args, **kwargs)[source]

Sets the specified device as not available and calls start.

Returns:True
Return type:bool

Type

class devices.nh_clinical_device_type(pool, cr)[source]

Represents a specific device type of a device

Groups

Extends Odoo’s res_groups and ir_model_access.

Model Access

class groups.ir_model_access(pool, cr)[source]

Extends Odoo’s class ir_model_access which defines write, read, create and unlink permissions for models by user group.

Extension adds field perm_responsibility, which gives permanent responsibility to a user group for a model.

Groups

class groups.res_groups(pool, cr)[source]

Extends Odoo’s res_groups

write(*args, **kwargs)[source]

Extends Odoo’s write() to update nh_activity records with the responsible users.

Parameters:
  • ids (list) – group ids
  • values (dict) – may contain user ids of responsible users
Returns:

True

Return type:

bool

Location

Location

class location.nh_clinical_location(pool, cr)[source]

Represents a location where a patient may be located or an activity may take place.

There are different types of locations. The most common usage is to have a hospital as a parent location to a group of wards where each ward is a parent to several beds. The bed location is where the patient can be placed.

check_context_ids(*args, **kwargs)[source]
Parameters:
  • cr
  • uid
  • context_ids
  • context
Returns:

create(*args, **kwargs)[source]

Extends Odoo’s create() method. Updates nh_clinical_location to write context_ids field.

Parameters:vals (dict) – values to update the records with
Returns:True
Return type:bool
get_available_location_ids(*args, **kwargs)[source]

Gets a list of available locations, only returning beds unless specified otherwise.

Parameters:usages – location type (ward, bed, etc.) of available locations
Returns:location ids of available locations (default usage is bed)i
Return type:list
get_by_code(*args, **kwargs)[source]

Gets the location’s id by the location’s code. Creates a location if auto_create is True and the location doesn’t exist.

Parameters:
  • code (str) – location’s code
  • auto_create (bool) – False [default].
Returns:

location id of the location. False if auto_create is True and location doesn’t exist, the location id of new ward location created. Otherwise False

Return type:

int or bool

get_closest_parent_id(*args, **kwargs)[source]

Gets a location’s closest ancestor (parent) location id of a particular usage. Returns False if no such location exists.

Parameters:
Returns:

location id of the ancestor. Otherwise False

Return type:

int or bool

is_child_of(*args, **kwargs)[source]

Checks if a location is a child of another location.

Parameters:
  • location_id (int) – location id
  • code (str) – location code
Returns:

the dictionary location_id (key) and a string containing location name and parent location name (value) Otherwise False is returned.

Return type:

dict or bool

onchange_parent_id(*args, **kwargs)[source]

Hospital locations can not have a parent location

onchange_type(*args, **kwargs)[source]

Hospital locations can only be Point of Service type

onchange_usage(*args, **kwargs)[source]

Hospital locations don’t have parent locations and they are always Point of Service type.

switch_active_status(*args, **kwargs)[source]

Activates the location if inactive and deactivates it if active.

Parameters:location_id (int) – location id of location to be switched
Returns:True
Return type:bool
write(*args, **kwargs)[source]

Extends Odoo’s write() method. Updates nh_clinical_location to write context_ids field.

Parameters:
  • ids (list) – ids of the records to update
  • vals (dict) – values to update the records with
Returns:

True

Return type:

bool

Operations

operations.py defines a set of activity types to deal with hospital administrative tasks like patient movements, admissions, discharge, etc.

Admission

class operations.nh_clinical_patient_admission(pool, cr)[source]

Represents the action of a patient visiting the Hospital and being admitted to one of the Wards.

cancel(*args, **kwargs)[source]

Calls cancel and then cancels every activity related to the admission, including the current patient spell.

Returns:True
Return type:bool
complete(*args, **kwargs)[source]

Calls complete and then creates and starts a new spell for the selected patient.

It will also create and complete a movement to the admitted location.

This operation kicks off a policy trigger as actions may need to take place after the patient is admitted into the Hospital.

Returns:True
Return type:bool
get_last(*args, **kwargs)[source]

Checks if there is a completed admission for the provided patient and returns the last one.

Parameters:exception (str) – ‘True’ will raise exception when found. ‘False’ when not.
Returns:admission id
Return type:int
submit(*args, **kwargs)[source]

Checks the submitted data is correct and then calls submit.

Returns:True
Return type:bool

Discharge

class operations.nh_clinical_patient_discharge(pool, cr)[source]

Represents the action of a patient leaving the Hospital after completing his or her visit for any reason.

cancel(*args, **kwargs)[source]

Calls cancel and then opens (changes state to started) the last completed patient spell.

It will also create and complete a movement to the bed location the patient was previously located if it is still available. If not, the patient will be moved to the corresponding ward location parent of that bed.

This operation will kick off a policy trigger as this is technically equivalent to an admission back to the Hospital.

Returns:True
Return type:bool
complete(*args, **kwargs)[source]

Calls complete and then creates and completes a new movement to the discharge location, which is a virtual location representing the patient is no longer in the Hospital.

It will also complete the current spell.

Returns:True
Return type:bool
get_last(*args, **kwargs)[source]

Checks if there is a completed discharge for the provided patient and returns the last one.

Parameters:exception (str) – ‘True’ will raise exception when found. ‘False’ when not.
Returns:discharge id
Return type:int
submit(*args, **kwargs)[source]

Checks the submitted data is correct and then calls submit.

Returns:True
Return type:bool

Follow

class operations.nh_clinical_patient_follow(pool, cr)[source]

Represents the action to invite another user to follow a group of patients adding visibility for those patients even when the invited user does not have a responsibility towards them.

complete(*args, **kwargs)[source]

Calls complete and then updates the following_ids list for the assigned user.

It will also call update activity for all not completed or cancelled activities related to the list of patients.

Returns:True
Return type:bool

Move

class operations.nh_clinical_patient_move(pool, cr)[source]

Represents any physical patient movement between different instances of location.

It is meant to work as an audit mechanism to track any patient movements within the Hospital.

complete(*args, **kwargs)[source]

Updates the patient current_location_id and the related spell location_id and then calls complete.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data and then calls submit.

Returns:True
Return type:bool

Placement

class operations.nh_clinical_patient_placement(pool, cr)[source]

Represents the action of assigning a bed usage location to an admitted patient.

complete(*args, **kwargs)[source]

Calls complete and then creates and completes a movement to the selected bed usage location.

This operation will kick off a policy trigger as Hospitals usually start observations or measurements on patients after this action is taken.

Returns:True
Return type:bool
get_activity_location_id(*args, **kwargs)[source]

Returns the location where the patient is waiting to be placed, usually of ward usage.

Returns:location id
Return type:int
get_form_description(*args, **kwargs)[source]
Returns a description in dictionary format of the input fields that would be required in the user gui when completing this action.
Parameters:patient_id (int) – patient id
Returns:a list of dictionaries
Return type:list
get_placement_activities_for_spell(*args, **kwargs)[source]
location_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

patient_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

pos_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

reason

Very similar to Char but used for longer contents, does not have a size and usually displayed as a multiline text box.

Parameters:translate – whether the value of this field can be translated
submit(*args, **kwargs)[source]

Checks the submitted data is correct and then calls submit.

Returns:True
Return type:bool
suggested_location_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Swap Beds

class operations.nh_clinical_patient_swap_beds(pool, cr)[source]

Represents the simultaneous movement of two patients that are located in bed usage location instances. The patients will end placed in the location the other patient was in.

It is meant to be used to move patients specially when there are no available beds to use as a buffer, although it can be used any time.

complete(*args, **kwargs)[source]

Creates and completes a movement for each patient to swap their locations.

Returns:True
Return type:bool
submit(*args, **kwargs)[source]

Checks the submitted data is correct and then calls submit.

Returns:True
Return type:bool

Transfer

class operations.nh_clinical_patient_transfer(pool, cr)[source]

Represents the action of a patient being moved to a ward usage location within the Hospital.

cancel(*args, **kwargs)[source]

Calls cancel and then if the origin ward usage location is different from where the current patient location is located, a new movement is created and completed.

If the origin location was of bed usage then the movement will assign that location back to the patient if it is still available.

This operation will kick off a policy trigger if the movement takes place as this is technically equivalent to an admission into the new Ward.

Returns:True
Return type:bool
complete(*args, **kwargs)[source]

Calls complete and then if the destination ward usage location is different from where the current patient location is located, a new movement is created and completed.

This operation will kick off a policy trigger if the movement takes place as this is technically equivalent to an admission into the new Ward.

Returns:True
Return type:bool
get_last(*args, **kwargs)[source]

Checks if there is a completed transfer for the provided patient and returns the last one.

Parameters:exception (str) – ‘True’ will raise exception when found. ‘False’ when not.
Returns:transfer id
Return type:int
patient_was_transferred_after_date(*args, **kwargs)[source]

Check if a patient transfer occurred some time after the given date.

Parameters:
  • patient_id (int) –
  • date (str) –
Returns:

Return type:

bool

submit(*args, **kwargs)[source]

Checks the submitted data is correct and then calls submit.

Returns:True
Return type:bool

Unfollow

class operations.nh_clinical_patient_unfollow(pool, cr)[source]

Represents the action to remove followers from a group of patients removing visibility for those patients unless the user has a responsibility towards them.

complete(*args, **kwargs)[source]

Calls complete and then removes the follower_ids list for the selected patients.

It will also cancel any number of open (not completed or cancelled) follow invitations that contain the selected patients.

Returns:True
Return type:bool

Partner

partner.py extends Odoo classes for doctor and role functionality.

Partner Extension

class partner.res_partner(pool, cr)[source]

Extends Odoo’s res_partner which defines a business entity i.e. customer, supplier, employer.

Extension adds boolean field doctor and code for doctor type.

Please note: must precede res_company (below) to ensure these fields are added to the model in the database.

create(*args, **kwargs)[source]

Extends Odoo’s create() to update fields group_ids and doctor_id.

Partner Category Extension

class partner.res_partner_category_extension(pool, cr)[source]

Extends Odoo’s res_partner_category to add functionality for roles.

Creates many-to-many relationship between categories (roles) and groups, allowing a relation between each role and corresponding group(s).

An example would be the role ‘Registrar’ belonging to groups base, doctor, senior doctor and registrar groups.

get_child_of_ids(*args, **kwargs)[source]

Gets all child category ids of parent, recursively.

Parameters:id (int) – parent id
Returns:parent id follow by child ids
Return type:list
get_user_roles(*args, **kwargs)[source]
group_ids

Many2many field; the value of such a field is the recordset.

Parameters:comodel_name – name of the target model (string)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Parameters:
  • relation – optional name of the table that stores the relation in the database (string)
  • column1 – optional name of the column referring to “these” records in the table relation (string)
  • column2 – optional name of the column referring to “those” records in the table relation (string)

The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!

Parameters:
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • limit – optional limit to use upon read (integer)
name_get(*args, **kwargs)[source]

Extends Odoo’s name_get() method, fetching the short version of category name belonging to ids (without their direct parent).

Parameters:
  • user (int) – user id
  • ids (list) – ids of the categories
Returns:

categories’ display names

Return type:

list

Partner Title Extension

class partner.res_partner_title_extension(pool, cr)[source]

Extends Odoo’s res_partner_title to include method get_title_by_name().

get_title_by_name(*args, **kwargs)[source]

Searches for the title by name. If the title does not exist, a new title is created by default.

Parameters:
  • title (string) – title of partner (‘Mr’, ‘Dr, ‘Miss’, etc.)
  • create (bool [default is True]) – when True, the title will be created if the title doesn’t exist
Returns:

id of title

Return type:

int

Patient

Patient

class patient.nh_clinical_patient(pool, cr)[source]

Represents a patient.

check_data(*args, **kwargs)[source]

Default will check if patient exists. Either hospital number (other_identifier) or NHS number (patient_identifier) is required.

If create is True, then both other_identifier and patient_identifier must be unique. Otherwise either or both identifiers will be accepted in data parameter.

If title is in data parameter, then method changes title to res.partner.title id. If title is not included, a new title will be created.

Parameters:
  • data (dict) – must include either patient_identifier or other_identifier
  • create (bool) – True [default]
  • exception – if True [default], it will raise an exception if no patient exists or more than one patient exists
Raises:

except_orm if exception arguments is True and if patient doesn’t exists or if duplicate patients are found

Returns:

True if successful. Otherwise False

Return type:

bool

check_hospital_number(*args, **kwargs)[source]

Checks for a patient by hospital number.

Parameters:
  • hospital_number (string) – patient’s hospital number
  • exception (bool) – True or False. Default is False
Returns:

True if patient exists. Otherwise False

Return type:

bool

Raises:

except_orm if exception is True and if the patient exists or if the patient does not

check_nhs_number(*args, **kwargs)[source]

Checks for patient by provided NHS Number.

Parameters:
  • nhs_number (string) – patient’s nhs number
  • exception (bool) – True or False. Default is False
Returns:

True if patient exists. Otherwise False

Return type:

bool

Raises:

except_orm if exception is True and if the patient exists or if the patient does not

create(*args, **kwargs)[source]

Extends Odoo’s create() to write name, other_identifier and patient_identifier upon creation.

Returns:True if created
Return type:bool
current_location_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

display_name

Very similar to Char but used for longer contents, does not have a size and usually displayed as a multiline text box.

Parameters:translate – whether the value of this field can be translated
dob
ethnicity
Parameters:
  • selection – specifies the possible values for this field. It is given as either a list of pairs (value, string), or a model method, or a method name.
  • selection_add – provides an extension of the selection in the case of an overridden field. It is a list of pairs (value, string).

The attribute selection is mandatory except in the case of related fields or field extensions.

family_name

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
follower_ids

Many2many field; the value of such a field is the recordset.

Parameters:comodel_name – name of the target model (string)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Parameters:
  • relation – optional name of the table that stores the relation in the database (string)
  • column1 – optional name of the column referring to “these” records in the table relation (string)
  • column2 – optional name of the column referring to “those” records in the table relation (string)

The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!

Parameters:
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • limit – optional limit to use upon read (integer)
format_data(fields, data, context=None)[source]
full_name

Very similar to Char but used for longer contents, does not have a size and usually displayed as a multiline text box.

Parameters:translate – whether the value of this field can be translated
gender
Parameters:
  • selection – specifies the possible values for this field. It is given as either a list of pairs (value, string), or a model method, or a method name.
  • selection_add – provides an extension of the selection in the case of an overridden field. It is a list of pairs (value, string).

The attribute selection is mandatory except in the case of related fields or field extensions.

get_not_admitted_patient_ids(*args, **kwargs)[source]

Returns patients ids for patients with no open spell.

given_name

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
load(*args, **kwargs)[source]

Attempts to load the data matrix, and returns a list of ids (or False if there was an error and no id could be generated) and a list of messages.

The ids are those of the records created and saved (in database), in the same order they were extracted from the file. They can be passed directly to read()

Parameters:
  • fields (list(str)) – list of fields to import, at the same index as the corresponding data
  • data (list(list(str))) – row-major matrix of data to import
  • context (dict) –
Returns:

{ids: list(int)|False, messages: [Message]}

middle_names

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
name_get(*args, **kwargs)[source]

Override name_get method so we return the patient’s fullname instead of the default name field

not_admitted
other_identifier

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
partner_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

patient_identifier

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
sex
Parameters:
  • selection – specifies the possible values for this field. It is given as either a list of pairs (value, string), or a model method, or a method name.
  • selection_add – provides an extension of the selection in the case of an overridden field. It is a list of pairs (value, string).

The attribute selection is mandatory except in the case of related fields or field extensions.

“Deletes” a patient from the system without deleting the record from the database. This allows the retrieval of patient data if necessary.

Parameters:ids (list) – ids of patients to unlink
Returns:True
Return type:bool
update(*args, **kwargs)[source]

Updates patient data by provided hospital number or nhs number, instead of patient_id as per usual.

Parameters:
  • identifier (str) – identifier of patient
  • data (dict) – data to write to the patient record
  • selection (str) – type of identifier used to lookup patient. Default is other_identifier, which is hospital number. patient_identifier will do it through the nhs number.
Returns:

True

Return type:

bool

write(*args, **kwargs)[source]

Extends Odoo’s write().

Returns:True if created
Return type:bool

POS

Defines POS class and extends Odoo’s res_company.

POS

class pos.nh_clinical_pos(pool, cr)[source]

Represents clinical point of service.

Company

class pos.res_company(pool, cr)[source]

Extends Odoo’s res_company to include one-to-many point of service (pos) field. See nh_clinical_pos.

Spell

Defines the Spell class.

Spell

class spell.nh_clinical_spell(pool, cr)[source]

A spell represents the time between a patient admission to the hospital and the patient discharge. It will be open as long as the patient remains in the hospital and will be connected to every activity related to that patient during this period of time.

code

Basic string field, can be length-limited, usually displayed as a single-line string in clients

Parameters:
  • size (int) – the maximum size of values stored for that field
  • translate (bool) – whether the values of this field can be translated
con_doctor_ids

Many2many field; the value of such a field is the recordset.

Parameters:comodel_name – name of the target model (string)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Parameters:
  • relation – optional name of the table that stores the relation in the database (string)
  • column1 – optional name of the column referring to “these” records in the table relation (string)
  • column2 – optional name of the column referring to “those” records in the table relation (string)

The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!

Parameters:
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • limit – optional limit to use upon read (integer)
create(*args, **kwargs)[source]

Checks the patient does not have already an open spell and then calls create

Returns:spell id
Return type:int
get_activity_user_ids(*args, **kwargs)[source]

Returns a list of user ids that would have visibility or responsibility over the specified spell activity

Returns:res.users ids
Return type:list
get_by_patient_id(*args, **kwargs)[source]

Checks if there is a started spell for the provided patient. Returns false if there are no spells found.

If the patient has had a previous spell that has now ended, no spells will be found by this method and it will return False. This is because activity state == completed when a spell has ended and so is not picked up by the search used in this method which contains state == started.

Parameters:
  • patient_id (int) – patient id
  • exception (str) – ‘True’ will raise an exception if found. ‘False’ if not.
Returns:

spell id

Return type:

int

get_spell_activity_by_patient_id(*args, **kwargs)[source]

Get the nh.clinical.spell record for the given patient.

Parameters:patient_id ('nh.clinical.patient' record) –
Returns:spell if it exists, otherwise None
Return type:‘nh.clinical.spell’ record
get_spell_start_date(*args, **kwargs)[source]
location_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

move_date
patient_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

pos_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

ref_doctor_ids

Many2many field; the value of such a field is the recordset.

Parameters:comodel_name – name of the target model (string)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Parameters:
  • relation – optional name of the table that stores the relation in the database (string)
  • column1 – optional name of the column referring to “these” records in the table relation (string)
  • column2 – optional name of the column referring to “those” records in the table relation (string)

The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!

Parameters:
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • limit – optional limit to use upon read (integer)
start_date
transferred_user_ids

Many2many field; the value of such a field is the recordset.

Parameters:comodel_name – name of the target model (string)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Parameters:
  • relation – optional name of the table that stores the relation in the database (string)
  • column1 – optional name of the column referring to “these” records in the table relation (string)
  • column2 – optional name of the column referring to “those” records in the table relation (string)

The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!

Parameters:
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • limit – optional limit to use upon read (integer)
write(*args, **kwargs)[source]

If location_id is updated, it will update move_date too. Then calls write

Returns:True
Return type:bool

User

Extends Odoo’s res_users.

Mail Message Override

class user.mail_message(pool, cr)[source]

Change Password

class user.nh_change_password_wizard(pool, cr)[source]

Extension of Odoo’s res.users change password wizard. Used to allow users to change their password securely.

Doctor

class user.nh_clinical_doctor(pool, cr)[source]

Represents a doctor.

create(*args, **kwargs)[source]

Extends Odoo’s create() to update doctor_id field in res_users.

Returns:True if created
Return type:bool
evaluate_doctors_dict(*args, **kwargs)[source]

Evaluates doctors, checking for a doctor before creating a new doctor if it doesn’t exist.

Parameters:data (dict) – must contain doctors key. Its value will be a list of dictionaries which must contain the keys code, gender, gmc and type. It many contain title.
Returns:True if either it finds a doctor or creates a new doctor. Otherwise False
Return type:bool
write(*args, **kwargs)[source]

Extends Odoo’s write() to update doctor_id field in res_users.

Returns:True if created
Return type:bool

Clinical Specialty

class user.nh_clinical_specialty(pool, cr)[source]

Specialty represent a doctor clinical specialty

Users

class user.res_users(pool, cr)[source]

Extends Odoo’s res_users to include point of service, parent locations of responsibility, following patients and the related doctor for the user.

check_pos(*args, **kwargs)[source]

Checks if user has an assigned point of service (POS).

Parameters:
  • user_id (int) – id of user to check
  • exception (bool) – False [default]
Returns:

if exception parameter is False, then returns True if POS is defined. Otherwise False. If is True, them returns True if POS is defined. If POS is undefined, then osv.except_osv is raised

create(*args, **kwargs)[source]

Extends Odoo’s create() to update fields group_ids and doctor_id.

Parameters:vals (dict) – values to initialise the new record
Returns:id of created record
Return type:int
doctor_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

following_ids

Many2many field; the value of such a field is the recordset.

Parameters:comodel_name – name of the target model (string)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Parameters:
  • relation – optional name of the table that stores the relation in the database (string)
  • column1 – optional name of the column referring to “these” records in the table relation (string)
  • column2 – optional name of the column referring to “those” records in the table relation (string)

The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!

Parameters:
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • limit – optional limit to use upon read (integer)
get_groups_string(*args, **kwargs)[source]
Returns:list of NH Clinical user groups for UID in string format
get_name(*args, **kwargs)[source]
location_ids

Many2many field; the value of such a field is the recordset.

Parameters:comodel_name – name of the target model (string)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Parameters:
  • relation – optional name of the table that stores the relation in the database (string)
  • column1 – optional name of the column referring to “these” records in the table relation (string)
  • column2 – optional name of the column referring to “those” records in the table relation (string)

The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!

Parameters:
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • limit – optional limit to use upon read (integer)
name_get(*args, **kwargs)[source]

Gets the names of users.

Parameters:ids (list or int) – user ids
Returns:user names
Return type:list
pos_id

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters:
  • comodel_name – name of the target model (string)
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • ondelete – what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
  • auto_join – whether JOINs are generated upon search through that field (boolean, by default False)
  • delegate – set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

pos_ids

Many2many field; the value of such a field is the recordset.

Parameters:comodel_name – name of the target model (string)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

Parameters:
  • relation – optional name of the table that stores the relation in the database (string)
  • column1 – optional name of the column referring to “these” records in the table relation (string)
  • column2 – optional name of the column referring to “those” records in the table relation (string)

The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!

Parameters:
  • domain – an optional domain to set on candidate values on the client side (domain or string)
  • context – an optional context to use on the client side when handling that field (dictionary)
  • limit – optional limit to use upon read (integer)
update_doctor_status(*args, **kwargs)[source]

Updates doctor field in res_partner if user is a doctor.

Parameters:ids (list) – user ids
Returns:True
Return type:bool
update_group_vals(*args, **kwargs)[source]

Updates a user’s groups(see res_partner_category_extension and res_groups) for the user.

Parameters:
  • user_id (int) – id of user
  • vals (dict) – expecting a dictionary with keys group_ids and/or category_id. Values will be a list of ints
Returns:

True

Return type:

bool

write(*args, **kwargs)[source]

Extends Odoo’s write() method.

Parameters:
  • ids (list or int) – id of records to update
  • values (dict) – values to update the records with
Returns:

True

Return type:

bool

NH Clinical LDAP Extension

auth.ldap Extension

class auth_ldap_extension.NHClinicalLDAPExtension(pool, cr)[source]
map_ldap_attributes(*args, **kwargs)[source]

Compose values for a new resource of model res_users, based upon the retrieved ldap entry and the LDAP settings.

Parameters:
  • conf (dict) – LDAP configuration
  • login – the new user’s login
  • ldap_entry (tuple) – single LDAP result (dn, attrs)
Returns:

parameters for a new resource of model res_users

Return type:

dict

NH Logging

Logging Override

nh_logging.new_format(self, record)[source]

Override the log output to include the User ID

Parameters:record – Log record
Returns:Formatted log record

Indices and tables