Skip to content

Commit

Permalink
[ADD] connector_carepoint: Physician export logic
Browse files Browse the repository at this point in the history
* Add physician export
  • Loading branch information
lasley committed Sep 16, 2016
1 parent 9e80135 commit 81d78d1
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 7 deletions.
1 change: 1 addition & 0 deletions connector_carepoint/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'depends': [
'connector',
'first_databank',
'medical_physician_us',
'delivery',
'l10n_multilang',
'l10n_us',
Expand Down
4 changes: 4 additions & 0 deletions connector_carepoint/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def delay_export(session, model_name, record_id, vals):
'carepoint.address.patient',
'carepoint.organization',
'carepoint.address.organization',
'medical.physician',
'carepoint.address.physician',
])
def delay_export_all_bindings(session, model_name, record_id, vals):
""" Delay a job which export all the bindings of a record.
Expand All @@ -57,6 +59,8 @@ def delay_export_all_bindings(session, model_name, record_id, vals):
'carepoint.organization',
'carepoint.address.organization',
'carepoint.account',
'medical.physician',
'carepoint.address.physician',
])
def delay_create(session, model_name, record_id, vals):
""" Create a new binding record, then trigger delayed export
Expand Down
48 changes: 43 additions & 5 deletions connector_carepoint/models/address_physician.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from openerp import models, fields
from openerp import models, fields, api
from openerp.addons.connector.connector import ConnectorUnit
from openerp.addons.connector.unit.mapper import (mapping,
only_create,
Expand All @@ -14,6 +14,8 @@

from .address_abstract import (CarepointAddressAbstractImportMapper,
CarepointAddressAbstractImporter,
CarepointAddressAbstractExportMapper,
CarepointAddressAbstractExporter,
)

_logger = logging.getLogger(__name__)
Expand All @@ -25,11 +27,11 @@ class CarepointCarepointAddressPhysician(models.Model):
_inherit = 'carepoint.binding'
_inherits = {'carepoint.address.physician': 'odoo_id'}
_description = 'Carepoint Address Physician Many2Many Rel'
_cp_lib = 'doctor_address' # Name of model in Carepoint lib (snake_case)
_cp_lib = 'doctor_address'

odoo_id = fields.Many2one(
comodel_name='carepoint.address.physician',
string='Company',
string='Address',
required=True,
ondelete='cascade'
)
Expand All @@ -49,6 +51,11 @@ class CarepointAddressPhysician(models.Model):
string='Carepoint Bindings',
)

@api.model
def _default_res_model(self):
""" It returns the res model. """
return 'medical.physician'


@carepoint
class CarepointAddressPhysicianAdapter(CarepointCRUDAdapter):
Expand All @@ -75,10 +82,20 @@ class CarepointAddressPhysicianImportMapper(
def partner_id(self, record):
""" It returns either the commercial partner or parent & defaults """
binder = self.binder_for('carepoint.medical.physician')
physician_id = binder.to_odoo(record['md_id'], browse=True)
physician = binder.to_odoo(record['md_id'], browse=True)
_sup = super(CarepointAddressPhysicianImportMapper, self)
return _sup.partner_id(
record, physician_id,
record, physician,
)

@mapping
@only_create
def res_model_and_id(self, record):
binder = self.binder_for('carepoint.medical.physician')
physician = binder.to_odoo(record['md_id'], browse=True)
_sup = super(CarepointAddressPhysicianImportMapper, self)
return _sup.res_model_and_id(
record, physician,
)

@mapping
Expand Down Expand Up @@ -111,3 +128,24 @@ def _import_addresses(self, physician_id, partner_binding):
address_ids = adapter.search(md_id=physician_id)
for address_id in address_ids:
importer.run(address_id)


@carepoint
class CarepointAddressPhysicianExportMapper(
CarepointAddressAbstractExportMapper
):
_model_name = 'carepoint.carepoint.address.physician'

@mapping
def md_id(self, binding):
binder = self.binder_for('carepoint.medical.physician')
rec_id = binder.to_backend(binding.res_id)
return {'md_id': rec_id}


@carepoint
class CarepointAddressPhysicianExporter(
CarepointAddressAbstractExporter
):
_model_name = 'carepoint.carepoint.address.physician'
_base_mapper = CarepointAddressPhysicianExportMapper
38 changes: 36 additions & 2 deletions connector_carepoint/models/medical_physician.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
)
from ..unit.backend_adapter import CarepointCRUDAdapter
from ..unit.mapper import (PersonImportMapper,
PersonExportMapper,
trim,
)
from ..backend import carepoint
from ..unit.import_synchronizer import (DelayedBatchImporter,
CarepointImporter,
)
from ..unit.export_synchronizer import CarepointExporter


_logger = logging.getLogger(__name__)

Expand All @@ -25,7 +28,7 @@ class CarepointMedicalPhysician(models.Model):
_inherit = 'carepoint.binding'
_inherits = {'medical.physician': 'odoo_id'}
_description = 'Carepoint Physician'
_cp_lib = 'doctor' # Name of model in Carepoint lib (snake_case)
_cp_lib = 'doctor'

odoo_id = fields.Many2one(
comodel_name='medical.physician',
Expand Down Expand Up @@ -71,7 +74,7 @@ class MedicalPhysicianImportMapper(PersonImportMapper):
(trim('url'), 'website'),
(trim('dea_no'), 'dea_num'),
(trim('fed_tax_id'), 'vat'),
(trim('stat_lic_id'), 'license_num'),
(trim('state_lic_id'), 'license_num'),
(trim('npi_id'), 'npi_num'),
]

Expand Down Expand Up @@ -99,3 +102,34 @@ def odoo_id(self, record):
class MedicalPhysicianImporter(CarepointImporter):
_model_name = ['carepoint.medical.physician']
_base_mapper = MedicalPhysicianImportMapper


@carepoint
class MedicalPhysicianExportMapper(PersonExportMapper):
_model_name = 'carepoint.medical.physician'

direct = [
('email', 'email'),
('website', 'url'),
('dea_num', 'dea_no'),
('vat', 'fed_tax_id'),
('license_num', 'state_lic_id'),
('npi_num', 'npi_id'),
]

@mapping
def md_id(self, record):
return {'md_id': record.carepoint_id}


@carepoint
class MedicalPhysicianExporter(CarepointExporter):
_model_name = ['carepoint.medical.physician']
_base_mapper = MedicalPhysicianExportMapper

def _after_export(self):
self.env['carepoint.address.physician']._get_by_partner(
self.binding_record.commercial_partner_id,
edit=True,
recurse=True,
)
24 changes: 24 additions & 0 deletions connector_carepoint/tests/models/test_address_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,27 @@ def test_org_id_return(self):
res = self.unit.org_id(self.record)
expect = self.unit.binder_for().to_backend()
self.assertDictEqual({'org_id': expect}, res)


class TestCarepointAddressOrganizationExporter(
AddressOrganizationTestBase
):

def setUp(self):
super(TestCarepointAddressOrganizationExporter, self).setUp()
self.Unit = \
address_organization.CarepointAddressOrganizationExporter
self.unit = self.Unit(self.mock_env)
self.record = mock.MagicMock()
self.unit.binding_record = self.record

def test_after_export(self):
""" It should call _get_by_partner w/ proper args """
with mock.patch.object(self.unit.session, 'env') as env:
self.unit._after_export()
model = env['carepoint.address.organization']
model._get_by_partner.assert_called_once_with(
self.record.commercial_partner_id,
edit=True,
recurse=True,
)
24 changes: 24 additions & 0 deletions connector_carepoint/tests/models/test_address_patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,27 @@ def test_pat_id_return(self):
res = self.unit.pat_id(self.record)
expect = self.unit.binder_for().to_backend()
self.assertDictEqual({'pat_id': expect}, res)


class TestCarepointAddressPatientExporter(
AddressPatientTestBase
):

def setUp(self):
super(TestCarepointAddressPatientExporter, self).setUp()
self.Unit = \
address_patient.CarepointAddressPatientExporter
self.unit = self.Unit(self.mock_env)
self.record = mock.MagicMock()
self.unit.binding_record = self.record

def test_after_export(self):
""" It should call _get_by_partner w/ proper args """
with mock.patch.object(self.unit.session, 'env') as env:
self.unit._after_export()
model = env['carepoint.address.patient']
model._get_by_partner.assert_called_once_with(
self.record.commercial_partner_id,
edit=True,
recurse=True,
)
63 changes: 63 additions & 0 deletions connector_carepoint/tests/models/test_address_physician.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,66 @@ def test_import_addresses_import(self):
mk().search.return_value = [expect]
self.unit._import_addresses(1, None)
mk().run.assert_called_once_with(expect)


class TestCarepointAddressPhysicianExportMapper(
AddressPhysicianTestBase
):

def setUp(self):
super(TestCarepointAddressPhysicianExportMapper, self).setUp()
self.Unit = \
address_physician.CarepointCarepointAddressPhysicianExportMapper
self.unit = self.Unit(self.mock_env)
self.record = mock.MagicMock()

def test_md_id_get_binder(self):
""" It should get binder for prescription line """
with mock.patch.object(self.unit, 'binder_for'):
self.unit.binder_for.side_effect = EndTestException
with self.assertRaises(EndTestException):
self.unit.md_id(self.record)
self.unit.binder_for.assert_called_once_with(
'carepoint.medical.physician'
)

def test_md_id_to_backend(self):
""" It should get backend record for rx """
with mock.patch.object(self.unit, 'binder_for'):
self.unit.binder_for().to_backend.side_effect = EndTestException
with self.assertRaises(EndTestException):
self.unit.md_id(self.record)
self.unit.binder_for().to_backend.assert_called_once_with(
self.record.patient_id,
)

def test_md_id_return(self):
""" It should return formatted md_id """
with mock.patch.object(self.unit, 'binder_for'):
res = self.unit.md_id(self.record)
expect = self.unit.binder_for().to_backend()
self.assertDictEqual({'md_id': expect}, res)


class TestCarepointAddressPhysicianExporter(
CarepointAddressPhysicianTestBase
):

def setUp(self):
super(TestCarepointAddressPhysicianExporter, self).setUp()
self.Unit = \
address_physician.CarepointAddressPhysicianExporter
self.unit = self.Unit(self.mock_env)
self.record = mock.MagicMock()
self.unit.binding_record = self.record

def test_after_export(self):
""" It should call _get_by_partner w/ proper args """
with mock.patch.object(self.unit.session, 'env') as env:
self.unit._after_export()
model = env['carepoint.address.physician']
model._get_by_partner.assert_called_once_with(
self.record.commercial_partner_id,
edit=True,
recurse=True,
)

0 comments on commit 81d78d1

Please sign in to comment.