Skip to content

Commit

Permalink
[IMP] connector_carepoint: Add disease export
Browse files Browse the repository at this point in the history
* Add patient disease export logic
  • Loading branch information
lasley committed Sep 28, 2016
1 parent c363671 commit e071af1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
32 changes: 32 additions & 0 deletions connector_carepoint/models/medical_patient_disease.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
from openerp.addons.connector.connector import ConnectorUnit
from openerp.addons.connector.unit.mapper import (mapping,
only_create,
none,
changed_by,
m2o_to_backend,
follow_m2o_relations,
ExportMapper,
)
from ..unit.backend_adapter import CarepointCRUDAdapter
from ..backend import carepoint
from ..unit.mapper import PartnerImportMapper
from ..unit.import_synchronizer import (DelayedBatchImporter,
CarepointImporter,
)
from ..unit.export_synchronizer import CarepointExporter

from .medical_pathology import MedicalPathologyUnit

Expand Down Expand Up @@ -134,3 +140,29 @@ def _create(self, data): # pragma: no cover
self.session, binding._name, binding.id, binding.backend_id.id
)
return binding


@carepoint
class MedicalPatientDiseaseExportMapper(ExportMapper):
_model_name = 'carepoint.medical.patient.disease'

direct = [
(none('diagnosed_date'), 'onset_date'),
(none('healed_date'), 'resolution_date'),
(m2o_to_backend('patient_id'), 'pat_id'),
(m2o_to_backend('physician_id'), 'caring_md_id'),
(follow_m2o_relations('pathology_id.code'), 'icd9'),
]


@carepoint
class MedicalPatientDiseaseExporter(CarepointExporter):
_model_name = 'carepoint.medical.patient.disease'
_base_mapper = MedicalPatientDiseaseExportMapper

def _export_dependencies(self):
record = self.carepoint_record
self._export_dependency(record['pat_id'],
'carepoint.medical.patient')
self._export_dependency(record['caring_md_id'],
'carepoint.medical.physician')
25 changes: 25 additions & 0 deletions connector_carepoint/tests/models/test_medical_patient_disease.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,28 @@ def test_after_import_dependencies_pathology_unit(self):
self.record['icd9'].strip(),
)
])


class TestMedicalPatientDiseaseExporter(MedicalPatientDiseaseTestBase):

def setUp(self):
super(TestMedicalPatientDiseaseExporter, self).setUp()
self.Unit = medical_patient_disease.MedicalPatientDiseaseExporter
self.unit = self.Unit(self.mock_env)
self.unit.carepoint_record = self.record

def test_after_export_dependencies(self):
""" It should export all depedencies """
with mock.patch.object(self.unit, '_export_dependency') as mk:
with mock.patch.object(self.unit, 'unit_for'):
self.unit._export_dependencies()
mk.assert_has_calls([
mock.call(
self.record['pat_id'],
'carepoint.medical.patient',
),
mock.call(
self.record['caring_md_id'],
'carepoint.medical.physician',
),
])

0 comments on commit e071af1

Please sign in to comment.