def build_local_measure_specialists_checkup(self, header_meta, entities, rend_serv_data, measure_item, measure_code): src_operation_code = header_meta['remote_operation_code'] if measure_item: sp_ckeckup_item = entities.set_child_entity( parent_item=measure_item, dst_entity_code=RisarEntityCode.MEASURE_SPECIALISTS_CHECKUP, dst_parents_params=header_meta['local_parents_params'], dst_main_id_name='result_action_id', dst_parent_id_name='measure_id', src_operation_code=src_operation_code, src_entity_code=TambovEntityCode.REND_SERVICE, src_main_id_name='id', src_id=rend_serv_data['id'], ) else: sp_ckeckup_item = entities.set_main_entity( dst_entity_code=RisarEntityCode.MEASURE_SPECIALISTS_CHECKUP, dst_parents_params=header_meta['local_parents_params'], dst_main_id_name='result_action_id', src_operation_code=src_operation_code, src_entity_code=TambovEntityCode.REND_SERVICE, src_main_id_name='id', src_id=rend_serv_data['id'], level_count=1, ) if src_operation_code != OperationCode.DELETE: resourceGroupId = safe_traverse_attrs(rend_serv_data, 'resourceGroupId') employee_position_id = self.get_employee_position(resourceGroupId) sp_ckeckup_item['body'] = { # 'result_action_id': None, # заполняется в set_current_id_func # 'measure_id': None, # заполняется в set_parent_id_common_func 'external_id': rend_serv_data['id'], 'measure_type_code': measure_code, 'checkup_date': encode(rend_serv_data['dateTo']), 'lpu_code': safe_traverse_attrs(rend_serv_data, 'orgId') or '', 'doctor_code': employee_position_id or '', 'status': 'performed' if safe_traverse_attrs( rend_serv_data, 'isRendered') else 'assigned', } dm = DiagsMatch() diagnosisId = safe_traverse_attrs(rend_serv_data, 'diagnosisId') if diagnosisId: sp_ckeckup_item['body']['diagnosis'] = dm.diag_code( diagnosisId) or Undefined return entities
def build_local_measure_research(self, header_meta, entities, rend_serv_item, rend_serv_data, measure_item, measure_code): src_operation_code = header_meta['remote_operation_code'] srv_attachment_item = rend_serv_item['addition'][ TambovEntityCode.SERVICE_ATTACHMENT][0] srv_attachment_data = srv_attachment_item['data'] if measure_item: research_item = entities.set_child_entity( parent_item=measure_item, dst_entity_code=RisarEntityCode.MEASURE_RESEARCH, dst_parents_params=header_meta['local_parents_params'], dst_main_id_name='result_action_id', dst_parent_id_name='measure_id', src_operation_code=src_operation_code, src_entity_code=TambovEntityCode.REND_SERVICE, src_main_id_name='id', src_id=rend_serv_data['id'], ) else: research_item = entities.set_main_entity( dst_entity_code=RisarEntityCode.MEASURE_RESEARCH, dst_parents_params=header_meta['local_parents_params'], dst_main_id_name='result_action_id', src_operation_code=src_operation_code, src_entity_code=TambovEntityCode.REND_SERVICE, src_main_id_name='id', src_id=rend_serv_data['id'], level_count=1, ) if src_operation_code != OperationCode.DELETE: resourceGroupId = safe_traverse_attrs(rend_serv_data, 'resourceGroupId') employee_position_id = self.get_employee_position(resourceGroupId) research_item['body'] = { # 'result_action_id': None, # заполняется в set_current_id_func # 'measure_id': # заполняется в set_parent_id_common_func 'external_id': rend_serv_data['id'], 'measure_type_code': measure_code, 'realization_date': encode(rend_serv_data['dateFrom']), 'lpu_code': safe_traverse_attrs(rend_serv_data, 'orgId') or '', 'doctor_code': employee_position_id or '', 'results': self.make_refs(srv_attachment_data), 'status': 'performed' if safe_traverse_attrs( rend_serv_data, 'isRendered') else 'assigned', } return entities
def get_employee_position(self, location_id): if not location_id: return None location_api_method = self.reformer.get_api_method( self.remote_sys_code, TambovEntityCode.LOCATION, OperationCode.READ_ONE, ) req = DataRequest(self.reformer.stream_id) req.set_req_params( url=location_api_method['template_url'], method=location_api_method['method'], protocol=ProtocolCode.SOAP, data={'location': location_id}, ) location_data = self.transfer__send_request(req) res = None for employeePosition_item in safe_traverse_attrs( location_data, 'employeePositionList', 'EmployeePosition') or []: if not self.valid_employee_position(employeePosition_item): continue res = employeePosition_item['employeePosition'] # валидный врач должен быть в ресурсе только один break return res
def build_local_org_body(self, org_item, clinic_data, AddressAllInfos, header_meta): town_kladr = '' if AddressAllInfos: town_kladr = self.get_town_kladr(AddressAllInfos[0]) org_item['body'] = { 'regionalCode': str(header_meta['remote_main_id']), # id/code двух систем будут совпадать 'full_name': clinic_data['name'], 'short_name': clinic_data['name'], 'address': safe_traverse_attrs(clinic_data, 'actualAddress', 'addressText') or '', 'area': town_kladr, 'is_LPU': 1, }
def set_clinics(self, clinics, package, req_meta): for clinic_id in clinics: clinic_item, clinic_data = package.add_main( entity_code=TambovEntityCode.CLINIC, main_id_name='clinic', main_id=clinic_id, parents_params=req_meta['dst_parents_params'], diff_key='', ) AddressAllInfo_data = package.add_addition( parent_item=clinic_item, entity_code=TambovEntityCode.ADDRESS_ALL_INFO, main_id_name='id', main_id=safe_traverse_attrs(clinic_data, 'actualAddress', 'addressId'), )
def build_local_entities(self, header_meta, pack_entity): birth_data = pack_entity['data'] src_entity_code = header_meta['remote_entity_code'] src_operation_code = header_meta['remote_operation_code'] # сопоставление параметров родительских сущностей params_map = { TambovEntityCode.SMART_PATIENT: { 'entity': RisarEntityCode.CARD, 'param': 'card_id' }, } self.reform_remote_parents_params(header_meta, src_entity_code, params_map) entities = RequestEntities(self.reformer.stream_id) if not safe_traverse_attrs(birth_data, 'Part1', 'InDate'): # пустой ответ return entities main_item = entities.set_main_entity( dst_entity_code=RisarEntityCode.CHILDBIRTH, dst_parents_params=header_meta['local_parents_params'], dst_main_id_name='card_id', src_operation_code=src_operation_code, src_entity_code=src_entity_code, src_main_id_name=header_meta['remote_main_param_name'], src_id=header_meta['remote_main_id'], level_count=1, ) if src_operation_code != OperationCode.DELETE: dm = DiagsMatch() part1 = birth_data['Part1'] part2 = birth_data['Part2'] part3 = birth_data['Part3'] part4 = birth_data['Part4'] part5 = birth_data['Part5'] part6 = birth_data['Part6'] # days = safe_int(stk(part1, 'PregnantTimeSpan', 'Days')) main_item['body'] = { # "required": ["admission_date", "pregnancy_duration", # "delivery_date", "delivery_time", # "maternity_hospital", "diagnosis_osn", # "pregnancy_final"] 'general_info': { 'admission_date': encode(part1['InDate']), 'maternity_hospital': str(stk(part1, 'ClinicId')), 'delivery_date': encode(stk(part1, 'ChildBirth', 'Date')), 'delivery_time': encode(stk(part1, 'ChildBirth', 'Time'))[:5] or '00:00', # todo: test # 'pregnancy_final': stk(part1, 'ChildBirth', 'ChildBirthOutcome'), # rbRisarPregnancy_Final 'pregnancy_final': 'rodami', # rbRisarPregnancy_Final 'pregnancy_duration': stk(part1, 'ChildBirth', 'PregnantWeeks'), # 'pregnancy_duration': days and int(days / 7) or 0, # -- 'diagnosis_osn': dm.diag_code( stk(part1, 'ChildBirth', 'Diagnoses', 'MainDiagnoses')) or Undefined, # -- # 'diagnosis_sop': part1['Extra'] or Undefined, # 'diagnosis_osl': part1['Complication'] or Undefined, 'maternity_hospital_doctor': (lambda x: x and str(x) or Undefined)( self.get_employee_positions( stk(part1, 'ChildBirth', 'EmployeeId'))), 'curation_hospital': stk(part1, 'CuratioLpu') or Undefined, 'pregnancy_speciality': stk(part1, 'BirthSpeciality') or Undefined, 'postnatal_speciality': stk(part1, 'AfterBirthSpeciality') or Undefined, 'help': stk(part1, 'HelpProvided') or Undefined, # 'abortion': stk(part1, 'Abort') or Undefined, # rbRisarAbort # 'death': ???, }, 'complications': { # 'delivery_waters': part3['BirthWaterBreak'] or Undefined, # rbRisarDelivery_Waters 'pre_birth_delivery_waters': safe_bool_none(part3['PrenatalWaterBreak']) or Undefined, 'weakness': stk(part3, 'BirthPowerWeakness') or Undefined, # rbRisarWeakness 'meconium_color': safe_bool_none(stk(part3, 'AmiaticWater')) or Undefined, 'pathological_preliminary_period': safe_bool_none(stk(part3, 'PatologicPreliminaryPeriod')) or Undefined, 'abnormalities_of_labor': safe_bool_none(stk(part3, 'BirthActivityAnomaly')) or Undefined, 'chorioamnionitis': safe_bool_none(stk(part3, 'Horiamnionit')) or Undefined, # 'perineal_tear': part3['PerinealRupture'] or Undefined, # rbPerinealTear # 'eclampsia': part3['Nefropaty'] or Undefined, # rbRisarEclampsia 'anemia': safe_bool_none(stk(part3, 'Anemia')) or Undefined, 'infections_during_delivery': stk(part3, 'InfectionDuringBirth') or Undefined, 'infections_after_delivery': stk(part3, 'InfectionAfterBirth') or Undefined, # 'funiculus': stk(part3, 'CordPatology', 'Term') or Undefined, # rbRisarFuniculus # 'afterbirth': stk(part3, 'PlacentaPatology', 'Term') or Undefined, # rbRisarAfterbirth }, 'manipulations': { 'caul': safe_bool_none(stk(part4, 'Amniotomy')) or Undefined, 'calfbed': safe_bool_none(stk(part4, 'ManualWombSurvey')) or Undefined, 'perineotomy': stk(part4, 'Perineotomy') or Undefined, 'secundines': safe_bool_none(stk(part4, 'ManualRemovalAfterBirth')) or Undefined, 'other_manipulations': stk(part4, 'AnotherManipulations') or Undefined, }, 'operations': { # 'caesarean_section': part5['CesarianDelivery'] or Undefined, #rbRisarCaesarean_Section # 'obstetrical_forceps': part5['Forceps'] or Undefined, # rbRisarObstetrical_Forceps # 'vacuum_extraction': safe_bool_none(part5['Vacuum']), # boolean # 'indication': part5['Indicator'] or Undefined, # rbRisarIndication 'specialities': stk(part5, 'Speciality') or Undefined, # 'anesthetization': part5['Anestesia'] or Undefined, # rbRisarAnesthetization # 'hysterectomy': part5['Hysterectomy'] or Undefined, # rbRisarHysterectomy # 'complications': part5['Complication'] or Undefined, # MKB 'embryotomy': safe_bool_none(stk(part5, 'Embryotomy')) or Undefined, }, 'kids': [] } mother_death_required = [ "reason_of_death", "death_date", "death_time" ] mother_death = { 'death_date': encode(stk(part2, 'MotherDeathData', 'DeathDate')), 'death_time': (encode(stk(part2, 'MotherDeathData', 'DeathTime')) or '')[:5], 'reason_of_death': stk(part2, 'MotherDeathData', 'MotherDeathReason'), # -- # 'pat_diagnosis_osn': stk(part2, 'MotherDeathData', 'PatologicalDiagnos'), # 'pat_diagnosis_sop': stk(part2, 'MotherDeathData', 'AcompanyDiagnos'), # 'pat_diagnosis_osl': stk(part2, 'MotherDeathData', 'ComplicationDiagnos'), 'control_expert_conclusion': stk(part2, 'LkkResult') or Undefined, } if all(mother_death[x] for x in mother_death_required): main_item['body']['mother_death'] = mother_death kids = [] childs = part6['Child'] for child in childs: # "required": ["alive", "sex", "weight", "length", "date"] kids.append({ 'alive': safe_bool(stk(child, 'Alive')), 'sex': safe_int(stk(child, 'Gender')) - 1, 'weight': safe_double(stk(child, 'Weight')), 'length': safe_double(stk(child, 'Height')), 'date': encode(stk(child, 'BirthDate')), # -- 'time': '00:00' if safe_bool(stk(child, 'Alive')) else Undefined, # 'maturity_rate': stk(child, 'FullTerm') or Undefined, # rbRisarMaturity_Rate 'apgar_score_1': safe_int(stk(child, 'Apgar_1min')) or Undefined, 'apgar_score_5': safe_int(stk(child, 'Apgar_5min')) or Undefined, 'apgar_score_10': safe_int(stk(child, 'Apgar_10min')) or Undefined, 'death_date': encode(stk(child, 'DeathDate')) or Undefined, 'death_time': (encode(stk(child, 'DeathTime')) or '')[:5] or Undefined, 'death_reason': stk(child, 'DeathReason') or Undefined, # 'diseases': child['NewbornSeakness'] or Undefined, }) main_item['body']['kids'] = kids return entities
def build_local_client_body(self, main_item, sm_patient_data, patient_data): patient = sm_patient_data['patient'] gender = safe_int(patient.gender) # if gender != 2: # main_item['meta']['skip_trash'] = True main_item['body'] = { # 'client_id': None, # заполняется в set_current_id_func 'FIO': { 'middlename': patient['middleName'] or '', 'name': patient['firstName'], 'surname': patient['lastName'] }, 'birthday_date': encode(patient['birthDate']), 'gender': gender, # 'SNILS': None, # заполняется в документах } if sm_patient_data['workplaces']: workplace = sm_patient_data['workplaces'][-1] main_item['body']['job'] = { 'organisation': workplace['organization']['name'], 'post': workplace['position'] or Undefined, } if patient_data['bloodGroup']: main_item['body']['blood_type_info'] = [{ 'blood_type': patient_data['bloodGroup'], }] for document_data in sm_patient_data.identifiers: if not document_data.type: continue # Получаем код организации document_issuing_authority = Undefined for code in (safe_traverse_attrs( document_data, 'issueOrganization', 'codes') or {}): if code['type'] == 'CODE_OMS': document_issuing_authority = code['code'] break if document_data.type == '19': # SNILS main_item['body']['SNILS'] = document_data.number # elif document_data.codeType == '1' and not main_item['body']['SNILS'] is None: # SNILS # main_item['body']['SNILS'] = document_data.code elif document_data.type in ('24', '25', '26', '40'): # ENP # в insurance_document_issuing_authority приходит код, а нужно ИД continue main_item['body'].setdefault('insurance_documents', []).append( { 'insurance_document_type': document_data.type or '', 'insurance_document_number': document_data.number or '', 'insurance_document_beg_date': encode(document_data.issueDate) or '', 'insurance_document_series': document_data.series or Undefined, 'insurance_document_issuing_authority': document_issuing_authority, # — }) else: # passport ('13') и прочие документы main_item['body'].setdefault('documents', []).append({ 'document_type_code': safe_int(document_data.type), 'document_number': document_data.number, 'document_beg_date': encode(document_data.issueDate) or '2000-01-01', 'document_series': document_data.series or Undefined, 'document_issuing_authority': document_issuing_authority, }) for address_data in sm_patient_data['addresses']: if address_data['type'] == '3': addr_type_name = 'residential_address' elif address_data['type'] == '4': addr_type_name = 'registration_address' else: continue # дефолты. заполняется в entry local_addr = { 'KLADR_locality': '', 'KLADR_street': '', 'house': address_data['house'] or '0', 'locality_type': 1, # Женя: building не передаем. они корпус пишут в номер дома # 'building': 'not-implemented' or Undefined, 'flat': address_data['apartment'] or '0', } main_item['body'][addr_type_name] = local_addr for entry in sorted(address_data['entries'], key=lambda x: x['level'], reverse=True): if entry['level'] == '2': if not local_addr['KLADR_locality']: local_addr[ 'KLADR_locality'] = entry['kladrCode'][:11] + '00' elif entry['level'] == '4': if not local_addr['KLADR_locality']: local_addr[ 'KLADR_locality'] = entry['kladrCode'][:11] + '00' elif entry['level'] == '5': local_addr[ 'KLADR_locality'] = entry['kladrCode'][:11] + '00' elif entry['level'] == '6': local_addr['KLADR_street'] = entry['kladrCode'] or '' elif entry['level'] == '7' and entry['name']: local_addr['house'] = entry['name'] elif entry['level'] == '8' and entry['name']: local_addr['flat'] = entry['name']