Skip to content

Commit

Permalink
[IMP] Fix and improve for v10
Browse files Browse the repository at this point in the history
* Add some additional error handling
* Update attributes and values for v10
* Add validation skip on create/write for partner IDs
* Add rx dispense force to circumvent over-dispenses in CP, which are allowed
* Remove all alpha characters in rx line dose units to fix SD-1979
* Fix unit handling
* Fix missing orders in dispenses by adding a relation in the order line for lookups
* Handle undocumented order state (0)
* Fix account lookup
* Hard code day category to match with pre-existing codes
* Add active toggle button to carepoint.backend view
* Add change/write date/users
* Fix adapter search return in multi-pk instances
* Add NDC concept to carepoint item
* Add NDC inference on rx export
* Add import NDC by control code
  • Loading branch information
lasley committed Mar 6, 2017
1 parent 2179d8b commit d7c0ec6
Show file tree
Hide file tree
Showing 131 changed files with 765 additions and 313 deletions.
2 changes: 1 addition & 1 deletion connector_carepoint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
Expand Down
53 changes: 27 additions & 26 deletions connector_carepoint/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
'name': 'CarePoint Connector',
'description': 'Two-Way Sync With CarePoint',
'version': '10.0.1.0.0',
'category': 'Connector',
'author': "LasLabs",
'license': 'AGPL-3',
'website': 'https://laslabs.com',
'depends': [
'connector',
'first_databank',
'medical_physician_us',
'delivery',
'l10n_multilang',
'l10n_us',
"name": "CarePoint Connector",
"description": "Two-Way Sync With CarePoint",
"version": "10.0.1.0.0",
"category": "Connector",
"author": "LasLabs",
"license": "AGPL-3",
"website": "https://laslabs.com",
"depends": [
"connector",
"first_databank",
"medical_physician_us",
"medical_patient_us",
"delivery",
"l10n_multilang",
"l10n_us",
],
"external_dependencies": {
"python": [
'carepoint',
"carepoint",
],
},
'data': [
'views/carepoint_backend_view.xml',
'views/connector_menu.xml',
'data/medical_drug_form_data.xml',
'data/carepoint_state_data.xml',
'data/carepoint_carepoint_account_data.xml',
'data/ir_cron_data.xml',
'security/ir.model.access.csv',
"data": [
"views/carepoint_backend_view.xml",
"views/connector_menu.xml",
"data/medical_drug_form_data.xml",
"data/carepoint_state_data.xml",
"data/carepoint_carepoint_account_data.xml",
"data/ir_cron_data.xml",
"security/ir.model.access.csv",
],
'installable': True,
'application': False,
"installable": True,
"application": False,
}
2 changes: 1 addition & 1 deletion connector_carepoint/backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import odoo.addons.connector.backend as backend
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/connector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields, api
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/consumer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.addons.connector.connector import Binder
Expand Down
10 changes: 9 additions & 1 deletion connector_carepoint/data/carepoint_state_data.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>


<record model="carepoint.state" id="state_0">
<field name="name">New</field>
<field name="code">0</field>
<field name="order_state">draft</field>
<field name="invoice_state">draft</field>
<field name="prescription_state">draft</field>
</record>

<record model="carepoint.state" id="state_10">
<field name="name">Entered</field>
<field name="code">10</field>
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/data/medical_units.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

#
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

# Backend
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/account_invoice_line.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address_abstract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address_organization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address_patient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address_physician.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address_store.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
24 changes: 23 additions & 1 deletion connector_carepoint/models/carepoint_account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down Expand Up @@ -89,6 +89,27 @@ def create(self, data):
data['ID'] = self.carepoint.get_next_sequence('acct_id')
return super(CarepointAccountAdapter, self).create(data)

def read(self, _id, attributes=None, return_all=False):
""" Gets record by id and returns the object
:param _id: Id of record to get from Db. Can be comma sep str
for multiple indexes
:type _id: mixed
:param attributes: Attributes to rcv from db. None for *
:type attributes: list or None
:rtype: :class:`sqlalchemy.engine.ResultProxy`
"""
if ',' in str(_id):
return super(CarepointAccountAdapter, self).read(
_id, attributes, return_all,
)
model_obj = self._get_cp_model()
domain = {'ID': _id}
res = self.carepoint.search(model_obj, domain, attributes)
try:
return res if return_all else res[0]
except IndexError:
return None


@carepoint
class CarepointAccountUnit(ConnectorUnit):
Expand All @@ -99,6 +120,7 @@ def _import_accounts(self, patient_id):
importer = self.unit_for(CarepointAccountImporter)
accounts = adapter.search(pat_id=patient_id)
for account in accounts:
_logger.debug('ACCOUNT %s', account)
importer.run(account)


Expand Down
33 changes: 30 additions & 3 deletions connector_carepoint/models/carepoint_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down Expand Up @@ -173,6 +173,10 @@ class CarepointBackend(models.Model):
comodel_name='account.payment.term',
required=True,
)
can_export = fields.Boolean(
default=True,
help='Uncheck this to disable data exporting for this backend.',
)
import_items_from_date = fields.Datetime()
import_patients_from_date = fields.Datetime()
import_physicians_from_date = fields.Datetime()
Expand All @@ -182,6 +186,16 @@ class CarepointBackend(models.Model):
import_phones_from_date = fields.Datetime()
import_pickings_from_date = fields.Datetime()
import_invoices_from_date = fields.Datetime()
import_fdb_ndc_control_code = fields.Selection([
('0', 'Not Controlled'),
('1', 'C1'),
('2', 'C2'),
('3', 'C3'),
('4', 'C4'),
('5', 'C5'),
],
help='Federal drug scheduling code for medicament.',
)
company_id = fields.Many2one(
string='Company',
comodel_name='res.company',
Expand Down Expand Up @@ -272,8 +286,6 @@ def _import_from_date(self, model, from_date_field,
filters[chg_date_field]['>='] = fields.Datetime.from_string(
from_date
)
else:
from_date = None
import_batch.delay(session, model, backend.id, filters=filters)
# Records from Carepoint are imported based on their `add_date`
# date. This date is set on Carepoint at the beginning of a
Expand All @@ -288,6 +300,21 @@ def _import_from_date(self, model, from_date_field,
next_time = fields.Datetime.to_string(next_time)
self.write({from_date_field: next_time})

@api.multi
def import_fdb_ndc_by_control_code(self):
""" It triggers an import of FDB NDCs by DEA code. """
session = self.__get_model_session()
for backend in self:
backend.check_carepoint_structure()
import_batch.delay(
session,
'carepoint.fdb.ndc',
backend.id,
filters={
'dea': int(backend.import_fdb_ndc_control_code),
},
)

@api.model
def resync_all(self, binding_model):
""" Resync all bindings for model """
Expand Down
23 changes: 19 additions & 4 deletions connector_carepoint/models/carepoint_item.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down Expand Up @@ -30,6 +30,11 @@ class CarepointItem(models.Model):
ondelete='cascade',
required=True,
)
ndc_id = fields.Many2one(
string='NDC',
comodel_name='fdb.ndc',
required=True,
)
warehouse_id = fields.Many2one(
string='Warehouse',
comodel_name='stock.warehouse',
Expand Down Expand Up @@ -124,16 +129,26 @@ def warehouse_id(self, record):
def carepoint_id(self, record):
return {'carepoint_id': record['item_id']}

@mapping
@only_create
def ndc_id(self, record):
self._get_ndc(record)
return {'ndc_id': ndc_id.id}

@mapping
@only_create
def odoo_id(self, record):
""" It binds on a medicament of an existing NDC """
ndc_id = self.env['fdb.ndc'].search(
ndc = self._get_ndc(record)
if ndc:
return {'odoo_id': ndc.medicament_id.id}

def _get_ndc(self, record):
""" It returns the FDB NDC for the record. """
return self.env['fdb.ndc'].search(
[('name', '=', record['NDC'].strip())],
limit=1,
)
if len(ndc_id):
return {'odoo_id': ndc_id[0].medicament_id.id}


@carepoint
Expand Down
9 changes: 6 additions & 3 deletions connector_carepoint/models/carepoint_organization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand All @@ -11,6 +11,7 @@
from ..unit.backend_adapter import CarepointCRUDAdapter
from ..unit.mapper import (PartnerImportMapper,
ExportMapper,
CommonDateImporterMixer,
trim,
)
from ..backend import carepoint
Expand Down Expand Up @@ -69,7 +70,8 @@ class CarepointOrganizationAdapter(CarepointCRUDAdapter):


@carepoint
class CarepointOrganizationBatchImporter(DelayedBatchImporter):
class CarepointOrganizationBatchImporter(DelayedBatchImporter,
CommonDateImporterMixer):
""" Import the Carepoint Organizations.
For every organization in the list, a delayed job is created.
"""
Expand Down Expand Up @@ -109,7 +111,8 @@ def odoo_id(self, record):


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

Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/carepoint_state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 LasLabs Inc.
# Copyright 2015-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields
Expand Down
Loading

0 comments on commit d7c0ec6

Please sign in to comment.