Skip to content

Commit

Permalink
[ADD] connector_carepoint: Prescription Export
Browse files Browse the repository at this point in the history
* Add prescription export logic
* Add prescription line export logic
* Switch to delayed import for monograph data
* Rename carepoint_carepoint_organization to carepoint_org_bind
* Add migrations for table renames
  • Loading branch information
lasley committed Oct 12, 2016
1 parent 83f3149 commit b9cc5ef
Show file tree
Hide file tree
Showing 25 changed files with 374 additions and 70 deletions.
23 changes: 17 additions & 6 deletions connector_carepoint/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ CarePoint Connector

This module provides CarePoint connector functionality.

Note that record creation will take place on the current user's company's
default Carepoint backend.

Records imported from other backends will maintain their relation with that
backend when exporting updates.

The following two-way sync logic is implemented:

* Odoo Patient / CarePoint Patient
* Odoo Physician / CarePoint Doctor
* Odoo Pharmacy / Careoint Organization
* Odoo Prescription & Line / CarePoint Prescription

The following logic is impented on a one-way (CarePoint to Odoo) basis:

* Odoo Pharmacy / CarePoint Store
* Odoo Physician / CarePoint Doctor
* Odoo Prescription & Line / CarePoint Prescription
* Odoo Pharmacy Warehouse / CarePoint Store
* Odoo Order / CarePoint Order
* Odoo Order Line / CarePoint Order Line
* Odoo NDC / FDB NDC
Expand All @@ -26,7 +33,6 @@ The following logic is impented on a one-way (CarePoint to Odoo) basis:
* Odoo Unit of Measure / FDB Strength
* Odoo Drug Route / FDB Route


Installation
============

Expand Down Expand Up @@ -59,13 +65,18 @@ To use this module, you need to:
Known Issues / Roadmap
======================

* More intelligent PK handling, and allowance of searches without
* Automatic failed connection renegotiation
* Add more retryable errors (such as in event of temp db d/c)
* Multiple DB connections not currently supported (namespace isolation required)
* Have to reboot server after reinstall to kill dup namespaces
* Medicament creation in NDC is bad & should use medicament importer instead
* Medicament category setting is not enforced - also need Rx/OTC delineation
* Add Rx/OTC Tax delineation
* ``import_dependency`` usage in ``_after_import`` should be replaced for delay
* ``_import_dependency`` usage in ``_after_import`` should be replaced for delay
* Needs to be split into multiple modules to isolate dependencies
* Carepoint organizations import as pharmacies, but might be other entities
* Prescription lines are in a bad namespace due to `OCA/connector#20
<https://github.com/OCA/connector/issues/209>`_


Bug Tracker
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
'name': 'CarePoint Connector',
'description': 'Two-Way Sync With CarePoint',
'version': '9.0.1.2.0',
'version': '9.0.1.3.0',
'category': 'Connector',
'author': "LasLabs",
'license': 'AGPL-3',
Expand Down
7 changes: 5 additions & 2 deletions connector_carepoint/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
from openerp.addons.connector.checkpoint import checkpoint


def get_environment(session, model_name, backend_id):
def get_environment(session, model_name, backend_id=None):
""" Create an environment to work with. """
backend_record = session.env['carepoint.backend'].browse(backend_id)
if not backend_id:
backend_record = session.env[model_name]._default_backend_id()
else:
backend_record = session.env['carepoint.backend'].browse(backend_id)
env = ConnectorEnvironment(backend_record, session, model_name)
return env
# @TODO: Multiple lang support. Seems not needed.
Expand Down
26 changes: 14 additions & 12 deletions connector_carepoint/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

# from openerp.addons.connector.connector import Binder
from openerp.addons.connector.connector import Binder
from .unit.export_synchronizer import export_record
# from .unit.delete_synchronizer import export_delete_record
# from .connector import get_environment
from .connector import get_environment
from openerp.addons.connector.event import (on_record_write,
on_record_create,
# on_record_unlink
Expand All @@ -31,7 +31,8 @@ def delay_export(session, model_name, record_id, vals):
export_record.delay(session, model_name, record_id, fields=fields)


@on_record_write(model_names=['medical.patient',
@on_record_write(model_names=['medical.prescription.order.line',
'medical.patient',
'carepoint.address',
'carepoint.address.patient',
'carepoint.organization',
Expand All @@ -53,7 +54,8 @@ def delay_export_all_bindings(session, model_name, record_id, vals):
fields=fields)


@on_record_create(model_names=['medical.patient',
@on_record_create(model_names=['medical.prescription.order.line',
'medical.patient',
'carepoint.address',
'carepoint.address.patient',
'carepoint.organization',
Expand All @@ -67,14 +69,14 @@ def delay_create(session, model_name, record_id, vals):
In this case, it is called on records of normal models to create
binding record, and trigger external system export
"""
model_obj = session.env['carepoint.%s' % model_name].with_context(
connector_no_export=True,
)
if not len(model_obj.search([('odoo_id', '=', record_id)])):
model_obj.create({
'odoo_id': record_id,
})
delay_export_all_bindings(session, model_name, record_id, vals)
if session.context.get('connector_no_export'):
return
bind_model_name = session.env[model_name].carepoint_bind_ids._name
record = session.env[model_name].browse(record_id)
env = get_environment(session, bind_model_name)
binder = env.get_connector_unit(Binder)
bind_record = binder.create_bind(record)
delay_export(session, bind_model_name, bind_record.id, vals)


# @on_record_unlink(model_names=['carepoint.medical.patient',
Expand Down
11 changes: 11 additions & 0 deletions connector_carepoint/migrations/9.0.1.3.0/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


def migrate(cr, version):
cr.execute('ALTER TABLE carepoint_medical_prescription_order_line '
'RENAME TO carepoint_rx_ord_ln')

cr.execute('ALTER TABLE carepoint_carepoint_organization '
'RENAME TO carepoint_org_bind')
2 changes: 1 addition & 1 deletion connector_carepoint/models/address_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class CarepointAddressOrganizationExportMapper(

@mapping
def org_id(self, binding):
binder = self.binder_for('carepoint.carepoint.organization')
binder = self.binder_for('carepoint.org.bind')
rec_id = binder.to_backend(binding.res_id)
return {'org_id': rec_id}

Expand Down
17 changes: 16 additions & 1 deletion connector_carepoint/models/carepoint_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ class CarepointBackend(models.Model):
],
default=CarepointDb.ODBC_DRIVER,
)
db_pool_size = fields.Integer(
required=True,
default=20,
help='This is passed to SQLAlchemy `create_engine`',
)
db_max_overflow = fields.Integer(
required=True,
default=20,
help='This is passed to SQLAlchemy `create_engine`',
)
db_pool_timeout = fields.Integer(
required=True,
default=30,
help='This is passed to SQLAlchemy `create_engine`',
)
server = fields.Char(
required=True,
help="IP/DNS to Carepoint database",
Expand Down Expand Up @@ -313,7 +328,7 @@ def cron_import_medical_physician(self):

@api.multi
def import_medical_prescription(self):
self._import_from_date('carepoint.medical.prescription.order.line',
self._import_from_date('carepoint.rx.ord.ln',
'import_prescriptions_from_date')
return True

Expand Down
16 changes: 8 additions & 8 deletions connector_carepoint/models/carepoint_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class CarepointCarepointOrganization(models.Model):
""" Binding Model for the Carepoint Organization """
_name = 'carepoint.carepoint.organization'
_name = 'carepoint.org.bind'
_inherit = 'carepoint.binding'
_inherits = {'carepoint.organization': 'odoo_id'}
_description = 'Carepoint Organization'
Expand Down Expand Up @@ -56,7 +56,7 @@ class CarepointOrganization(models.Model):
ondelete='cascade',
)
carepoint_bind_ids = fields.One2many(
comodel_name='carepoint.carepoint.organization',
comodel_name='carepoint.org.bind',
inverse_name='odoo_id',
string='Carepoint Bindings',
)
Expand All @@ -65,20 +65,20 @@ class CarepointOrganization(models.Model):
@carepoint
class CarepointOrganizationAdapter(CarepointCRUDAdapter):
""" Backend Adapter for the Carepoint Organization """
_model_name = 'carepoint.carepoint.organization'
_model_name = 'carepoint.org.bind'


@carepoint
class CarepointOrganizationBatchImporter(DelayedBatchImporter):
""" Import the Carepoint Organizations.
For every organization in the list, a delayed job is created.
"""
_model_name = ['carepoint.carepoint.organization']
_model_name = ['carepoint.org.bind']


@carepoint
class CarepointOrganizationImportMapper(PartnerImportMapper):
_model_name = 'carepoint.carepoint.organization'
_model_name = 'carepoint.org.bind'

direct = [
(trim('name'), 'name'),
Expand Down Expand Up @@ -110,7 +110,7 @@ def odoo_id(self, record):

@carepoint
class CarepointOrganizationImporter(CarepointImporter):
_model_name = ['carepoint.carepoint.organization']
_model_name = ['carepoint.org.bind']
_base_mapper = CarepointOrganizationImportMapper

def _after_import(self, partner_binding):
Expand All @@ -125,7 +125,7 @@ def _after_import(self, partner_binding):

@carepoint
class CarepointOrganizationExportMapper(ExportMapper):
_model_name = 'carepoint.carepoint.organization'
_model_name = 'carepoint.org.bind'

direct = [
(none('name'), 'name'),
Expand All @@ -142,7 +142,7 @@ def org_id(self, record):

@carepoint
class CarepointOrganizationExporter(CarepointExporter):
_model_name = ['carepoint.carepoint.organization']
_model_name = ['carepoint.org.bind']
_base_mapper = CarepointOrganizationExportMapper

def _after_export(self):
Expand Down
12 changes: 8 additions & 4 deletions connector_carepoint/models/fdb_pem_mogc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ..backend import carepoint
from ..unit.import_synchronizer import (DelayedBatchImporter,
CarepointImporter,
import_record,
)
from .fdb_pem_moe import FdbPemMoeAdapter

Expand Down Expand Up @@ -94,7 +95,10 @@ def _after_import(self, binding):
domain = {'pemono': record['pemono']}
attributes = ['pemono', 'pemono_sn']
for rec_id in pem_adapter.search_read(attributes, **domain):
self._import_dependency('{0},{1}'.format(rec_id['pemono'],
rec_id['pemono_sn'],
),
'carepoint.fdb.pem.moe')
import_record.delay(
self.session,
'carepoint.fdb.pem.moe',
self.backend_record.id,
'{0},{1}'.format(rec_id['pemono'], rec_id['pemono_sn']),
force=False,
)
6 changes: 0 additions & 6 deletions connector_carepoint/models/medical_prescription_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ def _import_dependencies(self):
self._import_dependency(record['md_id'],
'carepoint.medical.physician')

#
# def _after_import(self, partner_binding):
# """ Import the addresses """
# book = self.unit_for(PartnerAddressBook, model='carepoint.address')
# book.import_addresses(self.carepoint_id, partner_binding.id)


@carepoint
class MedicalPrescriptionOrderExportMapper(ExportMapper):
Expand Down
Loading

0 comments on commit b9cc5ef

Please sign in to comment.