-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] connector_carepoint: Implement pathology and codes
* Add `medical.pathology` bindings and import * Add `medical.pathology.code.type` bindings and import
- Loading branch information
Showing
8 changed files
with
380 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2015-2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import logging | ||
from openerp import models, fields | ||
from openerp.addons.connector.unit.mapper import (mapping, | ||
only_create, | ||
) | ||
from ..unit.backend_adapter import CarepointCRUDAdapter | ||
from ..backend import carepoint | ||
from ..unit.mapper import PartnerImportMapper, trim | ||
from ..unit.import_synchronizer import (DelayedBatchImporter, | ||
CarepointImporter, | ||
) | ||
|
||
from ..connector import add_checkpoint | ||
|
||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class CarepointMedicalPathology(models.Model): | ||
""" Binding Model for the Carepoint Store """ | ||
_name = 'carepoint.medical.pathology' | ||
_inherit = 'carepoint.binding' | ||
_inherits = {'medical.pathology': 'odoo_id'} | ||
_description = 'Carepoint Pathologies' | ||
_cp_lib = 'pathology' | ||
|
||
odoo_id = fields.Many2one( | ||
comodel_name='medical.pathology', | ||
string='Company', | ||
required=True, | ||
ondelete='cascade' | ||
) | ||
|
||
|
||
class MedicalPathology(models.Model): | ||
""" Adds the ``one2many`` relation to the Carepoint bindings | ||
(``carepoint_bind_ids``) | ||
""" | ||
_inherit = 'medical.pathology' | ||
|
||
carepoint_bind_ids = fields.One2many( | ||
comodel_name='carepoint.medical.pathology', | ||
inverse_name='odoo_id', | ||
string='Carepoint Bindings', | ||
) | ||
|
||
|
||
@carepoint | ||
class MedicalPathologyAdapter(CarepointCRUDAdapter): | ||
""" Backend Adapter for the Carepoint Store """ | ||
_model_name = 'carepoint.medical.pathology' | ||
|
||
|
||
@carepoint | ||
class MedicalPathologyBatchImporter(DelayedBatchImporter): | ||
""" Import the Carepoint Stores. | ||
For every company in the list, a delayed job is created. | ||
""" | ||
_model_name = ['carepoint.medical.pathology'] | ||
|
||
|
||
@carepoint | ||
class MedicalPathologyImportMapper(PartnerImportMapper): | ||
_model_name = 'carepoint.medical.pathology' | ||
|
||
direct = [ | ||
(trim('icd_cd'), 'code'), | ||
(trim('icd_desc'), 'name'), | ||
] | ||
|
||
@mapping | ||
@only_create | ||
def odoo_id(self, record): | ||
""" Will bind the record on an existing record with the same name """ | ||
code_type = self.code_type_id(record) | ||
record = self.env['medical.pathology'].search([ | ||
('code_type_id', '=', code_type['code_type_id']), | ||
('code', '=', record['icd_cd'].strip()), | ||
], | ||
limit=1, | ||
) | ||
if record: | ||
return {'odoo_id': record.id} | ||
|
||
@mapping | ||
def code_type_id(self, record): | ||
binder = self.binder_for('carepoint.medical.pathology.code.type') | ||
type_id = binder.to_odoo(record['icd_cd_type'].strip()) | ||
return {'code_type_id': type_id} | ||
|
||
@mapping | ||
def carepoint_id(self, record): | ||
return {'carepoint_id': '%s,%s' % (record['icd_cd'].strip(), | ||
record['icd_cd_type'].strip(), | ||
)} | ||
|
||
|
||
@carepoint | ||
class MedicalPathologyImporter(CarepointImporter): | ||
_model_name = ['carepoint.medical.pathology'] | ||
_base_mapper = MedicalPathologyImportMapper | ||
|
||
def _import_dependencies(self): | ||
record = self.carepoint_record | ||
self._import_dependency(record['icd_cd_type'].strip(), | ||
'carepoint.medical.pathology.code.type') | ||
|
||
def _create(self, data): # pragma: no cover | ||
binding = super(MedicalPathologyImporter, self)._create(data) | ||
add_checkpoint( | ||
self.session, binding._name, binding.id, binding.backend_id.id | ||
) | ||
return binding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2015-2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import logging | ||
from openerp import models, fields | ||
from openerp.addons.connector.unit.mapper import (mapping, | ||
only_create, | ||
) | ||
from ..unit.backend_adapter import CarepointCRUDAdapter | ||
from ..backend import carepoint | ||
from ..unit.mapper import PartnerImportMapper, trim | ||
from ..unit.import_synchronizer import (DelayedBatchImporter, | ||
CarepointImporter, | ||
) | ||
|
||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class CarepointMedicalPathologyCodeType(models.Model): | ||
""" Binding Model for the Carepoint Store """ | ||
_name = 'carepoint.medical.pathology.code.type' | ||
_inherit = 'carepoint.binding' | ||
_inherits = {'medical.pathology.code.type': 'odoo_id'} | ||
_description = 'Carepoint Pathology Code Types' | ||
_cp_lib = 'pathology_code_type' | ||
|
||
odoo_id = fields.Many2one( | ||
comodel_name='medical.pathology.code.type', | ||
string='Company', | ||
required=True, | ||
ondelete='cascade' | ||
) | ||
|
||
|
||
class MedicalPathologyCodeType(models.Model): | ||
""" Adds the ``one2many`` relation to the Carepoint bindings | ||
(``carepoint_bind_ids``) | ||
""" | ||
_inherit = 'medical.pathology.code.type' | ||
|
||
carepoint_bind_ids = fields.One2many( | ||
comodel_name='carepoint.medical.pathology.code.type', | ||
inverse_name='odoo_id', | ||
string='Carepoint Bindings', | ||
) | ||
|
||
|
||
@carepoint | ||
class MedicalPathologyCodeTypeAdapter(CarepointCRUDAdapter): | ||
""" Backend Adapter for the Carepoint Store """ | ||
_model_name = 'carepoint.medical.pathology.code.type' | ||
|
||
|
||
@carepoint | ||
class MedicalPathologyCodeTypeBatchImporter(DelayedBatchImporter): | ||
""" Import the Carepoint Stores. | ||
For every company in the list, a delayed job is created. | ||
""" | ||
_model_name = ['carepoint.medical.pathology.code.type'] | ||
|
||
|
||
@carepoint | ||
class MedicalPathologyCodeTypeImportMapper(PartnerImportMapper): | ||
_model_name = 'carepoint.medical.pathology.code.type' | ||
|
||
direct = [ | ||
(trim('icd_cd_type_desc'), 'name'), | ||
] | ||
|
||
@mapping | ||
@only_create | ||
def odoo_id(self, record): | ||
""" Will bind the record on an existing record with the same name """ | ||
record = self.env['medical.pathology.code.type'].search( | ||
[('name', 'ilike', record['icd_cd_type_desc'].strip())], | ||
limit=1, | ||
) | ||
if record: | ||
return {'odoo_id': record.id} | ||
|
||
@mapping | ||
def carepoint_id(self, record): | ||
return {'carepoint_id': record['icd_cd_type']} | ||
|
||
|
||
@carepoint | ||
class MedicalPathologyCodeTypeImporter(CarepointImporter): | ||
_model_name = ['carepoint.medical.pathology.code.type'] | ||
_base_mapper = MedicalPathologyCodeTypeImportMapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
connector_carepoint/tests/models/test_medical_pathology.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2015-2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import mock | ||
|
||
from openerp.addons.connector_carepoint.models import medical_pathology | ||
|
||
from ..common import SetUpCarepointBase | ||
|
||
|
||
class EndTestException(Exception): | ||
pass | ||
|
||
|
||
class MedicalPathologyTestBase(SetUpCarepointBase): | ||
|
||
def setUp(self): | ||
super(MedicalPathologyTestBase, self).setUp() | ||
self.model = 'carepoint.medical.pathology' | ||
self.mock_env = self.get_carepoint_helper( | ||
self.model | ||
) | ||
self.record = { | ||
'icd_cd': ' ICD Code ', | ||
'icd_cd_type': ' ICD Type Code ', | ||
} | ||
|
||
|
||
class TestMedicalPathologyImportMapper(MedicalPathologyTestBase): | ||
|
||
def setUp(self): | ||
super(TestMedicalPathologyImportMapper, self).setUp() | ||
self.Unit = medical_pathology.MedicalPathologyImportMapper | ||
self.unit = self.Unit(self.mock_env) | ||
|
||
def test_odoo_id(self): | ||
""" It should return odoo_id of recs with same code & type """ | ||
with mock.patch.object(self.unit, 'binder_for'): | ||
model_obj = self.env['carepoint.medical.pathology.code.type'] | ||
code_type_id = model_obj.create({ | ||
'name': self.record['icd_cd_type'].strip(), | ||
}) | ||
self.unit.binder_for().to_odoo.return_value = code_type_id.id | ||
expect = self.env['medical.pathology'].create({ | ||
'name': 'Pathology', | ||
'code_type_id': code_type_id.id, | ||
'code': self.record['icd_cd'].strip(), | ||
}) | ||
res = self.unit.odoo_id(self.record) | ||
expect = {'odoo_id': expect.id} | ||
self.assertDictEqual(expect, res) | ||
|
||
def test_code_type_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.code_type_id(self.record) | ||
self.unit.binder_for.assert_called_once_with( | ||
'carepoint.medical.pathology.code.type' | ||
) | ||
|
||
def test_code_type_id_to_odoo(self): | ||
""" It should get Odoo record for rx """ | ||
with mock.patch.object(self.unit, 'binder_for'): | ||
self.unit.binder_for().to_odoo.side_effect = EndTestException | ||
with self.assertRaises(EndTestException): | ||
self.unit.code_type_id(self.record) | ||
self.unit.binder_for().to_odoo.assert_called_once_with( | ||
self.record['icd_cd_type'].strip(), | ||
) | ||
|
||
def test_code_type_id_return(self): | ||
""" It should return formatted code_type_id """ | ||
with mock.patch.object(self.unit, 'binder_for'): | ||
res = self.unit.code_type_id(self.record) | ||
expect = self.unit.binder_for().to_odoo() | ||
self.assertDictEqual({'code_type_id': expect}, res) | ||
|
||
def test_carepoint_id(self): | ||
""" It should return correct attribute """ | ||
res = self.unit.carepoint_id(self.record) | ||
expect = { | ||
'carepoint_id': '%s,%s' % ( | ||
self.record['icd_cd'].strip(), | ||
self.record['icd_cd_type'].strip(), | ||
), | ||
} | ||
self.assertDictEqual(expect, res) | ||
|
||
|
||
class TestMedicalPathologyImporter(MedicalPathologyTestBase): | ||
|
||
def setUp(self): | ||
super(TestMedicalPathologyImporter, self).setUp() | ||
self.Unit = medical_pathology.MedicalPathologyImporter | ||
self.unit = self.Unit(self.mock_env) | ||
self.unit.carepoint_record = self.record | ||
|
||
def test_after_import_dependencies(self): | ||
""" It should import all depedencies """ | ||
with mock.patch.object(self.unit, '_import_dependency') as mk: | ||
self.unit._import_dependencies() | ||
mk.assert_has_calls([ | ||
mock.call( | ||
self.record['icd_cd_type'].strip(), | ||
'carepoint.medical.pathology.code.type', | ||
), | ||
]) |
Oops, something went wrong.