def recordAcceptable(specialityId, sex, age): if specialityId: if specialityId != self.personSpecialityId: return False if sex: if sex != self.clientSex: return False if age: if self.clientAge == None: return False ageSelector = parseAgeSelector(age) return checkAgeSelector(ageSelector, self.clientAge) return True
def loadChildren(self): result = [] db = QtGui.qApp.db table = db.table('ActionTemplate') tableAction = db.table('Action') cond = [table['group_id'].eq(self._id), table['deleted'].eq(0)] if self._filter.actionTypeId: cond.append( db.joinOr([ tableAction['actionType_id'].eq(self._filter.actionTypeId), table['action_id'].isNull() ])) if self._filter.personId: cond.append( db.joinOr([ table['owner_id'].eq(self._filter.personId), table['owner_id'].isNull() ])) if self._filter.specialityId: cond.append( db.joinOr([ table['speciality_id'].eq(self._filter.specialityId), table['speciality_id'].isNull() ])) if self._filter.clientSex: cond.append(table['sex'].inlist([self._filter.clientSex, 0])) query = db.query( db.selectStmt(table.leftJoin( tableAction, tableAction['id'].eq(table['action_id'])), [ table['id'].name(), table['name'].name(), table['action_id'].name(), table['age'].name() ], where=cond, order=table['name'].name())) while query.next(): record = query.record() age = forceString(record.value('age')) if age and self._filter.clientAge: if not checkAgeSelector(parseAgeSelector(age), self._filter.clientAge): continue id = forceInt(record.value('id')) name = forceString(record.value('name')) actionId = forceRef(record.value('action_id')) child = CActionTemplateTreeItem(self, name, id, self.model, actionId, self._filter) if not self._filter.removeEmptyNodes or not child.isEmpty(): result.append(child) return result
def _isEnabled(self, item): actionTypeId = self.actionCol.getActionTypeId( forceRef(item.value('action_id'))) sex = forceInt(item.value('sex')) age = forceString(item.value('age')) personId = forceRef(item.value('owner_id')) specialityId = forceRef(item.value('speciality_id')) if self.filter.actionTypeId and ( actionTypeId is None or (actionTypeId and self.filter.actionTypeId != actionTypeId)): return False if self.filter.personId and personId and self.filter.personId != personId: return False if self.filter.specialityId and specialityId and self.filter.specialityId != specialityId: return False if self.filter.clientSex and sex and self.filter.clientSex != sex: return False if self.filter.clientAge and age and not checkAgeSelector( parseAgeSelector(age), self.filter.clientAge): return False return True
def getMasterIdOrganisationId(self, houseIdList, houseId, ageTuple, sex): masterId = None organisationId = None #netCodeClient = 1 if clientAge >= 18 else 2 houseMasterInfoList = houseIdList.get(houseId, {}) if len(houseMasterInfoList) > 1: if self.attachByNet: for masterInfoList in houseMasterInfoList.values(): netId = masterInfoList.get('netId', None) if netId: net = self.nets[netId] if (not net['sex'] or net['sex'] == sex) and ( not net['ageSelector'] or checkAgeSelector( net['ageSelector'], ageTuple)): masterId = masterInfoList.get('masterId', None) organisationId = masterInfoList.get( 'organisationId', None) break if self.attachByAreaType: preferableAreaType = 2 if ageTuple[ 3] < 18 else 1 # Педиатрический для детей, Терапевтический для взрослых defaultAreaType = 4 # Общей практики for areaType in [preferableAreaType, defaultAreaType]: if not masterId: for masterInfoList in houseMasterInfoList.values(): if masterInfoList.get('isArea', 0) == areaType: masterId = masterInfoList.get('masterId', None) organisationId = masterInfoList.get( 'organisationId', None) break if not masterId: masterInfoList = houseMasterInfoList.values() if masterInfoList: masterInfo = masterInfoList[0] masterId = masterInfo.get('masterId', None) organisationId = masterInfo.get('organisationId', None) return masterId, organisationId
def applicable(self, clientSex, clientAge): if self.sex and clientSex != self.sex: return False if self.age and not checkAgeSelector(self.age, clientAge): return False return True
def checkDatesRegardToClientLife(widget, clientId, eventSetDate, eventDate, eventTypeId): result = True if clientId: db = QtGui.qApp.db birthDate = forceDate( db.translate('Client', 'id', clientId, 'birthDate')) deathDate = getDeathDate(clientId) possibleDeathDate = birthDate.addYears(QtGui.qApp.maxLifeDuration) if birthDate: postmortem = isEventDeath(eventTypeId) if eventSetDate: result = result and (eventSetDate >= birthDate or confirmTrouble( widget, u'Дата назначения %s не должна быть раньше даты рождения пациента %s' % (forceString(eventSetDate), forceString(birthDate)))) if deathDate: result = result and ( eventSetDate <= deathDate or postmortem or confirmTrouble( widget, u'Дата назначения %s не должна быть позже имеющейся даты смерти пациента %s' % (forceString(eventSetDate), forceString(deathDate)))) else: result = result and ( eventSetDate <= possibleDeathDate or postmortem or confirmTrouble( widget, u'Дата назначения %s не должна быть позже возможной даты смерти пациента %s' % (forceString(eventSetDate), forceString(possibleDeathDate)))) ageConstraint = forceString( db.translate('EventType', 'id', eventTypeId, 'age')) ageConstraint = parseAgeSelector(ageConstraint, isExtend=True) clientAge = calcAgeTuple(birthDate, eventSetDate) ageResult = False if QtGui.qApp.region() == u'91': eventTypeCode = getEventCode(eventTypeId) ageResult = (QtGui.qApp.region() == u'91' and eventTypeCode.lower() in [u'дв1', u'дв2'] and hasSocStatus( clientId, {'specialCase': ['10', '11', '12']})) if not ageResult: for ageSelector in ageConstraint: begUnit, begCount, endUnit, endCount, step, useCalendarYear, useExclusion = ageSelector checkClientAge = clientAge if useCalendarYear and isinstance( checkClientAge, CAgeTuple): checkClientAge = CAgeTuple( (checkClientAge[0], checkClientAge[1], checkClientAge[2], eventSetDate.year() - birthDate.year()), birthDate, eventSetDate) ageResult = checkAgeSelector( (begUnit, begCount, endUnit, endCount), checkClientAge) if ageResult: if step: unit = begUnit if begUnit else endUnit if (checkClientAge[unit - 1] - begCount) % step != 0: ageResult = False if ageResult: ageResult = not useExclusion break if clientAge and ageConstraint and not ageResult: result = result and confirmTrouble( widget, u'Возраст пациента не подходит для создания обращения данного типа' ) if eventDate: result = result and (eventDate >= birthDate or confirmTrouble( widget, u'Дата выполнения (окончания) %s не должна быть раньше даты рождения пациента %s' % (forceString(eventDate), forceString(birthDate)))) if deathDate: result = result and ( eventDate <= deathDate or postmortem or confirmTrouble( widget, u'Дата выполнения (окончания) %s не должна быть позже имеющейся даты смерти пациента %s' % (forceString(eventDate), forceString(deathDate)))) else: result = result and ( eventDate <= possibleDeathDate or postmortem or confirmTrouble( widget, u'Дата выполнения (окончания) %s не должна быть позже возможной даты смерти пациента %s' % (forceString(eventDate), forceString(possibleDeathDate)))) return result
def checkActions(self, eventId, sex, setDate, execDate, eventTypeId, clientAge): selectionGroups=self.get_Action_selectionGroups(eventTypeId) mnogo=False malo=False for selectionGroup in selectionGroups: stmt=''' select ActionType.name, Action.actionType_id, Action.begDate, Action.endDate, EventType_Action.sex as EventType_Action_sex, EventType_Action.age, EventType_Action.actuality from Action join ActionType on ActionType.id=Action.actionType_id join EventType_Action on EventType_Action.actionType_id=Action.actionType_id where Action.event_id=%d and EventType_Action.eventType_id=%d and EventType_Action.selectionGroup=%d ''' % (eventId, eventTypeId, selectionGroup) query=QtGui.qApp.db.query(stmt) act_num=0 while query.next(): act_num+=1 record=query.record() begDate=forceDate(record.value('begDate')) endDate=forceDate(record.value('endDate')) name=forceString(record.value('name')) EventType_Action_sex=forceInt(record.value('EventType_Action_sex')) age=forceString(record.value('age')) actuality=forceInt(record.value('actuality')) if age and clientAge: ageSelector = parseAgeSelector(age) if not checkAgeSelector(ageSelector, clientAge): self.err2log(u'исслед. '+name+u' не подходит по возрасту') beg=setDate.addMonths(-actuality) if not endDate: self.err2log(u'исслед. '+name+u' без даты') # if begDate and begDate<beg: # self.err2log(u'исслед. '+name+u' раньше начала ДД') if endDate and endDate>execDate: self.err2log(u'исслед. '+name+u' позже окончания ДД') if EventType_Action_sex and EventType_Action_sex!=sex: self.err2log(u'исслед. '+name+u' не подходит по полу') cond='eventType_id=%d and selectionGroup=%d' % (eventTypeId, selectionGroup) EventType_Action=QtGui.qApp.db.getRecordEx('EventType_Action', cols='sex, age', where=cond) if EventType_Action: EventType_Action_sex=forceString(EventType_Action.value('sex')) if EventType_Action_sex and EventType_Action_sex!=sex: continue age=forceString(EventType_Action.value('age')) if age and clientAge: ageSelector = parseAgeSelector(age) if not checkAgeSelector(ageSelector, clientAge): continue if selectionGroup>1: if act_num>1: mnogo=True elif not act_num: malo=True elif selectionGroup==1: if not act_num: malo=True elif selectionGroup==0: if act_num: mnogo=True else: if act_num>1: mnogo=True if mnogo: self.err2log(u'лишние исслед.') if malo: self.err2log(u'не хватает исслед.')
def checkDiags(self, eventId, sex, setDate, execDate, eventTypeId, clientAge): db=QtGui.qApp.db selectionGroups=self.get_Diag_selectionGroups(eventTypeId) if not selectionGroups: self.err2log(u'проверка диагнозов пропущена, так как не реализована') return # skip check mnogo=False malo=False zak_diags=0 zak_gz=0 gz_max=0 no_person=False person_0=False person_null=False for selectionGroup in selectionGroups: stmt=u''' select Diagnostic.endDate, Diagnostic.diagnosisType_id, Diagnostic.stage_id, Diagnostic.person_id, Diagnosis.MKB, Diagnostic.healthGroup_id, rbSpeciality.code as speciality, rbSpeciality.name as sname, EventType_Diagnostic.sex as EventType_Diagnostic_sex, EventType_Diagnostic.age, EventType_Diagnostic.actuality, Person.code as person_code, Person.federalCode from Diagnostic left join Person on Diagnostic.person_id=Person.id left join Diagnosis on Diagnosis.id=Diagnostic.diagnosis_id left join rbSpeciality on rbSpeciality.id=Diagnostic.speciality_id left join Event on Event.id=Diagnostic.event_id left join EventType_Diagnostic on (EventType_Diagnostic.eventType_id=Event.eventType_id and EventType_Diagnostic.speciality_id=Diagnostic.speciality_id) where Diagnostic.event_id=%d and Diagnostic.deleted = 0 and EventType_Diagnostic.eventType_id=%d and EventType_Diagnostic.selectionGroup=%d order by Diagnostic.diagnosisType_id ''' % (eventId, eventTypeId, selectionGroup) query=QtGui.qApp.db.query(stmt) diag_num=0 diag_osn={} # количество осн./закл. диагнозов while query.next(): diag_num+=1 record=query.record() speciality=forceString(record.value('speciality')) osn_num=diag_osn.get(speciality, 0) sname=forceString(record.value('sname')) MKB=forceStringEx(record.value('MKB')) if not MKB: self.err2log(u'отсутствует МКБ') continue if MKB != MKB.upper(): self.err2log(u'неправильный МКБ') continue if not db.getRecordEx('MKB', '*', 'DiagID="%s"' % MKBwithoutSubclassification(MKB)): self.err2log(u'неправильный МКБ') continue person_code=forceString(record.value('person_code')) federalCode=forceString(record.value('federalCode')) if person_code=='' and federalCode=='': no_person=True elif person_code in ['', '0'] and federalCode in ['', '0']: person_0=True endDate=forceDate(record.value('endDate')) diagnosisTypeId=forceInt(record.value('diagnosisType_id')) healthGroupId=forceInt(record.value('healthGroup_id')) personId=forceInt(record.value('person_id')) if not personId: person_null=True if MKB[:1] in ['Z', 'z']: # if diagnosisTypeId not in [1, 2]: # #z0-z13.9 # mkb_num=MKB[1:].split('.') # if len(mkb_num): # num1=int(mkb_num[0]) # if num1<13 or (num1==13 and (len(mkb_num)>1 and int(mkb_num[1])<=9)): # self.err2log(u'диагноз Z назначен сопутствующим') if healthGroupId>1 and diagnosisTypeId>1: #z0-z13.9 mkb_num=MKB[1:].split('.') if len(mkb_num): num1=int(mkb_num[0]) if num1<14: self.err2log(u'группа>1 диагноз Z') else: if healthGroupId==1: self.err2log(u'группа=1 диагноз не Z') if diagnosisTypeId==1: zak_diags+=1 zak_gz=healthGroupId if healthGroupId<1 or healthGroupId>6: self.err2log(u'неправильная группа заключительного диагноза') if diagnosisTypeId in [1, 2]: gz_max=max(gz_max, healthGroupId) diag_osn[speciality]=osn_num+1 else: diag_osn[speciality]=osn_num EventType_Diagnostic_sex=forceInt(record.value('EventType_Diagnostic_sex')) age=forceString(record.value('age')) actuality=forceInt(record.value('actuality')) if age and clientAge: ageSelector = parseAgeSelector(age) if not checkAgeSelector(ageSelector, clientAge): self.err2log(u'осмотр спец. '+sname+u' не подходит по возрасту') beg=setDate.addMonths(-actuality) if not endDate: self.err2log(u'осмотр спец. '+sname+u' без даты') if endDate and endDate<beg: self.err2log(u'осмотр спец. '+sname+u' раньше начала ДД') if endDate and endDate>execDate: self.err2log(u'осмотр спец. '+sname+u' позже окончания ДД') if EventType_Diagnostic_sex and EventType_Diagnostic_sex!=sex: self.err2log(u'осмотр спец. '+sname+u' не подходит по полу') cond='eventType_id=%d and selectionGroup=%d' % (eventTypeId, selectionGroup) EventType_Diagnostic=QtGui.qApp.db.getRecordEx( 'EventType_Diagnostic', cols='sex, age', where=cond) if EventType_Diagnostic: EventType_Diagnostic_sex=forceString(EventType_Diagnostic.value('sex')) if EventType_Diagnostic_sex and EventType_Diagnostic_sex!=sex: continue age=forceString(EventType_Diagnostic.value('age')) if age and clientAge: ageSelector = parseAgeSelector(age) if not checkAgeSelector(ageSelector, clientAge): continue for (spec, num) in diag_osn.iteritems(): sname=forceString(db.translate('rbSpeciality', 'code', spec, 'name')) if num==0: self.err2log(u'нет основного диагноза у спец. '+sname) if num>1: self.err2log(u'несколько основных диагнозов у спец. '+sname) if selectionGroup>1: if diag_num>1: mnogo=True elif not diag_num: malo=True elif selectionGroup==1: if not diag_num: malo=True elif selectionGroup==0: if diag_num: mnogo=True else: if diag_num>1: mnogo=True if mnogo: self.err2log(u'лишние диагнозы') if malo: self.err2log(u'не хватает диагнозов') if zak_diags==0: self.err2log(u'нет заключительного диагноза') elif zak_diags>1: self.err2log(u'несколько заключительных диагнозов') if zak_gz<gz_max: self.err2log(u'у заключительного диагноза не самая высокая группа здоровья') if person_null: self.err2log(u'нет врача') elif no_person: self.err2log(u'нет кода врача') elif person_0: self.err2log(u'код врача 0')