Ejemplo n.º 1
0
    def fillStatEventSteps(self, event, eventId):
        statStepRecordsList = self.db.getRecordList(stmt=STAT_STEPS_STMT %
                                                    eventId)
        if not statStepRecordsList:
            return False

        event.Steps = self.emk.factory.create('ns9:ArrayOfStepStat')
        event.Steps.StepStat = []
        for r in statStepRecordsList:
            step = self.emk.factory.create('ns9:StepStat')
            step.DateStart = forceDateTuple(r.value('DateStart'))
            step.DateEnd = forceDateTuple(r.value('DateEnd'))
            step.IdPaymentType = forceRef(r.value('IdPaymentType'))
            step.Doctor = self.getMedicalStaff(record=r)
            step.IdStepMis = forceStringEx(r.value('IdStepMis'))
            step.HospitalDepartmentName = forceStringEx(
                r.value('HospitalDepartmentName'))
            step.IdHospitalDepartment = forceStringEx(
                r.value('IdHospitalDepartment'))
            step.IdRegimen = forceRef(r.value('IdRegimen'))
            step.WardNumber = forceStringEx(r.value('WardNumber'))
            step.BedNumber = forceStringEx(r.value('BedNumber'))
            step.BedProfile = forceRef(r.value('BedProfile'))
            step.DaySpend = forceRef(r.value('DaySpend'))

            event.Steps.StepStat.append(step)

        return True
Ejemplo n.º 2
0
    def getDispensaryOneRecommendations(self, eventId):
        recommendations = self.emk.factory.create('ns8:ArrayOfRecommendation')
        recommendations.Recommendation = []

        for rec in getDispensaryOneRecommendationRecords(self.db, eventId):
            actionId = forceRef(rec.value('id'))
            personId = forceRef(rec.value('person_id'))
            templateId = forceRef(rec.value('templateId'))
            endDate = forceDate(rec.value('endDate'))

            try:
                tname, template, tt = getTemplate(templateId)
                data = {'action': CActionInfo(CInfoContext(), actionId)}
                res = compileAndExecTemplate(template, data)
                html = res[0].encode('utf8')
            except Exception as e:
                self.logExceptionExtra(e, {'event_id': eventId})
                html = ''

            recommendation = self.emk.factory.create('ns8:Recommendation')
            recommendation.Date = forceDateTuple(endDate)
            recommendation.Doctor = self.getMedicalStaff(personId=personId)
            recommendation.Text = html

            recommendations.Recommendation.append(recommendation)

        return recommendations
Ejemplo n.º 3
0
    def fillMainDiagnosis(self, event, eventId):
        diagnosisRecord = self.db.getRecordEx(stmt=MAIN_DIAGNOSIS_STMT %
                                              eventId)
        if diagnosisRecord is None:
            return False

        event.MedRecords = self.emk.factory.create('ns6:ArrayOfMedRecord')
        event.MedRecords.MedRecord = []

        diagnosis = self.emk.factory.create('ns7:ClinicMainDiagnosis')
        diagnosis.DiagnosisInfo = self.emk.factory.create('ns7:DiagnosisInfo')
        diagnosis.DiagnosisInfo.IdDiseaseType = forceRef(
            diagnosisRecord.value('IdDiseaseType'))
        diagnosis.DiagnosisInfo.DiagnosedDate = forceDateTuple(
            diagnosisRecord.value('DiagnosedDate'))
        diagnosis.DiagnosisInfo.IdDiagnosisType = forceRef(
            diagnosisRecord.value('IdDiagnosisType'))
        diagnosis.DiagnosisInfo.MkbCode = forceStringEx(
            diagnosisRecord.value('MkbCode'))
        diagnosis.DiagnosisInfo.DiagnosisStage = forceRef(
            diagnosisRecord.value('DiagnosisStage'))
        diagnosis.DiagnosisInfo.IdDispensaryState = forceRef(
            diagnosisRecord.value('IdDispensaryState'))
        diagnosis.Doctor = self.getMedicalStaff(record=diagnosisRecord)

        event.MedRecords.MedRecord.append(diagnosis)

        return True
Ejemplo n.º 4
0
    def getPersonWithIdentity(self, record=None, personId=None):
        if record is None:
            record = getMedicalStaffRecord(self.db, personId)

        person = self.emk.factory.create('ns3:PersonWithIdentity')
        person.HumanName = self.emk.factory.create('ns3:HumanName')
        person.HumanName.GivenName = forceStringEx(record.value('GivenName'))
        person.HumanName.MiddleName = forceStringEx(record.value('MiddleName'))
        person.HumanName.FamilyName = forceStringEx(record.value('FamilyName'))
        person.Sex = forceRef(record.value('Sex'))
        person.Birthdate = forceDateTuple(record.value('Birthdate'))
        person.IdPersonMis = forceStringEx(record.value('IdPersonMis'))
        return person
Ejemplo n.º 5
0
    def sendClient(self, clientId):
        logExtra = {'client_id': clientId}

        clientRecord = self.db.getRecordEx(stmt=CLIENT_STMT % clientId)
        if clientRecord is None:
            self.logger.error(
                u'Клиент с id == %i не найден или помечен, как удалённый' %
                clientId,
                extra=logExtra)
            return False

        client = self.pix.factory.create('ns0:PatientDto')

        client.BirthDate = forceDateTuple(clientRecord.value('BirthDate'))
        client.FamilyName = forceStringEx(clientRecord.value('FamilyName'))
        client.GivenName = forceStringEx(clientRecord.value('GivenName'))
        client.MiddleName = forceStringEx(clientRecord.value('MiddleName'))
        client.IdPatientMIS = forceStringEx(clientRecord.value('IdPatientMIS'))
        client.Sex = forceRef(clientRecord.value('Sex'))
        client.IdBloodType = forceRef(clientRecord.value('IdBloodType'))

        clientSocStatusRecord = self.db.getRecordEx(
            stmt=CLIENT_SOC_STATUS_STMT % clientId)
        if clientSocStatusRecord:
            client.SocialGroup = forceRef(
                clientSocStatusRecord.value('SocialGroup'))
            client.SocialStatus = forceStringEx(
                clientSocStatusRecord.value('SocialStatus'))

        clientDocumentRecordList = self.db.getRecordList(
            stmt=CLIENT_DOCUMENTS_STMT.format(clientId=clientId))
        if clientDocumentRecordList:
            client.Documents = self.pix.factory.create(
                'ns0:ArrayOfDocumentDto')
            client.Documents.DocumentDto = []
            for docRecord in clientDocumentRecordList:
                if not forceStringEx(docRecord.value('ProviderName')):
                    continue  # не заполнено
                doc = self.pix.factory.create('ns0:DocumentDto')
                doc.IdDocumentType = forceRef(
                    docRecord.value('IdDocumentType'))
                doc.DocS = forceStringEx(docRecord.value('DocS')).replace(
                    ' ', '').replace('\t', '')
                doc.DocN = forceStringEx(docRecord.value('DocN')).replace(
                    ' ', '').replace('\t', '')
                if forceDateTuple(docRecord.value('ExpiredDate')):
                    doc.ExpiredDate = forceDateTuple(
                        docRecord.value('ExpiredDate'))
                if forceDateTuple(docRecord.value('IssuedDate')):
                    doc.IssuedDate = forceDateTuple(
                        docRecord.value('IssuedDate'))
                doc.ProviderName = forceStringEx(
                    docRecord.value('ProviderName'))
                doc.IdProvider = forceStringEx(
                    docRecord.value('IdProvider')) or None
                client.Documents.DocumentDto.append(doc)

        clientAddressRecordList = self.db.getRecordList(
            stmt=CLIENT_ADDRESSES_STMT % clientId)
        if clientAddressRecordList:
            client.Addresses = self.pix.factory.create('ns0:ArrayOfAddressDto')
            client.Addresses.AddressDto = []
            for addrRecord in clientAddressRecordList:
                if not forceStringEx(addrRecord.value('StringAddress')):
                    continue  # не заполнено
                addr = self.pix.factory.create('ns0:AddressDto')
                addr.IdAddressType = forceRef(
                    addrRecord.value('IdAddressType'))
                addr.StringAddress = forceStringEx(
                    addrRecord.value('StringAddress'))
                client.Addresses.AddressDto.append(addr)

        clientContactRecordList = self.db.getRecordList(
            stmt=CLIENT_CONTACTS_STMT % clientId)
        if clientContactRecordList:
            client.Contacts = self.pix.factory.create('ns0:ArrayOfContactDto')
            client.Contacts.ContactDto = []
            for contactRecord in clientContactRecordList:
                if not forceStringEx(contactRecord.value('ContactValue')):
                    continue  # не заполнено
                contact = self.pix.factory.create('ns0:ContactDto')
                contact.IdContactType = forceRef(
                    contactRecord.value('IdContactType'))
                contact.ContactValue = forceStringEx(
                    contactRecord.value('ContactValue'))
                client.Contacts.ContactDto.append(contact)

        clientWorkRecord = self.db.getRecordEx(stmt=CLIENT_WORKS_STMT %
                                               clientId)
        if clientWorkRecord and forceStringEx(
                clientWorkRecord.value('CompanyName')):
            client.Job = self.pix.factory.create('ns0:JobDto')
            client.Job.CompanyName = forceStringEx(
                clientWorkRecord.value('CompanyName'))
            client.Job.Position = forceStringEx(
                clientWorkRecord.value('Position'))

        # TODO: skkachaev: Здесь должно быть заполнение льгот, но wsdl очень сильно отличается от доков API в этой части

        currLogStatus = getClientLogStatus(self.db, clientId)
        try:
            result = self.pix.service.AddPatient(
                self.GUID, self.orgStructureIdLPU
                if self.orgStructureIdLPU is not None else getIdLPU(
                    self.db, self.idLPU, QtGui.qApp.currentOrgStructureId()),
                client)
            # result = self.pix.service.AddPatient(self.GUID, getIdLPU(self.db, self.idLPU, QtGui.qApp.currentOrgStructureId()), client)
            setClientLogStatus(self.db, clientId, LogStatus.Success)
            self.logger.debug(
                u'Пациент с id={0} успешно отправлен'.format(clientId))
            return True

        except ValueError as err:
            self.logger.error(err.message, extra=logExtra)
            return False

        except WebFault as err:
            errList = err.fault.detail.ArrayOfRequestFault.RequestFault if hasattr(err.fault.detail,
                                                                                   'ArrayOfRequestFault') \
                else [err.fault.detail.RequestFault]
            if hasattr(errList[0], 'ErrorCode'
                       ) and errList[0].ErrorCode == ERR_DUPLICATE_CLIENT:
                setClientLogStatus(self.db, clientId, LogStatus.Success)
                self.logger.debug(
                    u'Пациент с id={0} успешно отправлен'.format(clientId))
                return True
            else:
                if currLogStatus != LogStatus.Failed:
                    setClientLogStatus(self.db, clientId, LogStatus.Failed)
                self.logger.error(errList, extra=logExtra)
            return False

        except Exception as e:
            self.logger.error(e, extra=logExtra)
            return False
Ejemplo n.º 6
0
    def fillMedDocument(self, eventId, event, documentCode, html=None):
        clientId = forceRef(
            self.db.translateEx(table=u'Event',
                                keyCol=u'id',
                                keyVal=eventId,
                                valCol=u'client_id'))
        medRecord = self.db.getRecordEx(stmt=MED_DOCUMENT_STMT % eventId)
        tname = u'Эпикриз'
        if html is None:  # Заполняем документ по шаблонам печати
            medDocumentPrintTemplateId = forceRef(
                self.db.getIdList(stmt=MED_DOCUMENT_PRINT_TEMPLATE_STMT %
                                  documentCode))
            if not medDocumentPrintTemplateId:
                return False
            medDocumentPrintTemplateId = medDocumentPrintTemplateId[0]
            tname, template, tt = getTemplate(medDocumentPrintTemplateId)

            data = {
                'client': CClientInfo(CInfoContext(), clientId),
                'event': CEventInfo(CInfoContext(), eventId)
            }
            try:
                res = compileAndExecTemplate(template, data)
                html = res[0].encode('utf8')
            except Exception as e:
                self.logExceptionExtra(e, {'event_id': eventId})
                html = ''

        data1 = base64.b64encode(html)
        data2 = base64.b64encode(SIGN_DATA % data1)

        medDocument = self.emk.factory.create('ns8:%s' % documentCode)
        medDocument.CreationDate = forceDateTuple(
            medRecord.value('CreationDate'))
        medDocument.IdDocumentMis = forceRef(medRecord.value('IdDocumentMis'))
        medDocument.Header = tname
        medDocument.Attachment.Data = data2
        medDocument.Attachment.MimeType = MIME_TYPE
        medDocument.Author = self.getMedicalStaff(record=medRecord)

        if documentCode == 'SickList':
            tempInvRecord = getTempInvalidRecord(self.db, eventId)
            if tempInvRecord:
                medDocument.SickListInfo = self.emk.factory.create(
                    'ns8:SickListInfo')
                medDocument.SickListInfo.Number = forceStringEx(
                    tempInvRecord.value('number'))
                medDocument.SickListInfo.DateStart = forceDateTuple(
                    tempInvRecord.value('begDate'))
                medDocument.SickListInfo.DateEnd = forceDateTuple(
                    tempInvRecord.value('endDate'))
                medDocument.SickListInfo.IsPatientTaker = True
            else:
                return False

        elif documentCode == 'DispensaryOne':
            dispensaryInfo = getDispensaryOneInfo(self.db, eventId)
            if dispensaryInfo:
                medDocument.IsGuested = dispensaryInfo['IsGuested']
                medDocument.IsUnderObservation = dispensaryInfo[
                    'IsUnderObservation']
                medDocument.HasExpertCareRefferal = dispensaryInfo[
                    'HasExtraResearchRefferal']
                medDocument.HasHealthResortRefferal = dispensaryInfo[
                    'HasHealthResortRefferal']
                medDocument.HasSecondStageRefferal = dispensaryInfo[
                    'HasSecondStageRefferal']
                medDocument.HasPrescribeCure = dispensaryInfo[
                    'HasPrescribeCure']
                medDocument.HasExtraResearchRefferal = dispensaryInfo[
                    'HasExtraResearchRefferal']
                medDocument.HealthGroup = self.emk.factory.create(
                    'ns8:HealthGroup')
                medDocument.HealthGroup.Doctor = self.getMedicalStaff(
                    record=medRecord)
                medDocument.HealthGroup.HealthGroupInfo = self.emk.factory.create(
                    'ns8:HealthGroupInfo')
                medDocument.HealthGroup.HealthGroupInfo.IdHealthGroup = dispensaryInfo[
                    'IdHealthGroup']
                medDocument.HealthGroup.HealthGroupInfo.Date = forceDateTuple(
                    dispensaryInfo['Date'])
                medDocument.Recommendations = self.getDispensaryOneRecommendations(
                    eventId)
            else:
                return False

        elif documentCode == 'Referral':
            referralRecord = getReferralRecord(self.db, eventId)
            if referralRecord:
                medDocument.IdSourceLpu = forceStringEx(
                    referralRecord.value('IdSourceLpu'))
                medDocument.IdTargetLpu = forceStringEx(
                    referralRecord.value('IdTargetLpu'))
                medDocument.DepartmentHead = self.getMedicalStaff(
                    personId=forceRef(referralRecord.value('personId')))
                medDocument.ReferralInfo = self.emk.factory.create(
                    'ns8:ReferralInfo')
                medDocument.ReferralInfo.Reason = forceStringEx(
                    referralRecord.value('Reason'))
                medDocument.ReferralInfo.IdReferralMis = forceStringEx(
                    referralRecord.value('IdReferralMis'))
                medDocument.ReferralInfo.IdReferralType = forceInt(
                    referralRecord.value('IdReferralType'))
                medDocument.ReferralInfo.IssuedDateTime = forceDateTuple(
                    referralRecord.value('IssuedDateTime'))
                medDocument.ReferralInfo.HospitalizationOrder = forceInt(
                    referralRecord.value('HospitalizationOrder'))
                medDocument.ReferralInfo.MkbCode = forceStringEx(
                    referralRecord.value('MkbCode'))
            else:
                return False

        elif documentCode == 'ConsultNote':
            if getEventTypeCode(self.db, eventId) in ('211', '261'):
                return False

        event.MedRecords.MedRecord.append(medDocument)
        return True
Ejemplo n.º 7
0
    def fillAmbEventSteps(self, event, eventId):
        def addMedRecord(currentStep, medRecord):
            if hasattr(currentStep, 'MedRecords'):
                currentStep.MedRecords.MedRecord.append(medRecord)
            else:
                currentStep.MedRecords = self.emk.factory.create(
                    'ns6:ArrayOfMedRecord')
                currentStep.MedRecords.MedRecord = [medRecord]

        ambStepRecordsList = self.db.getRecordList(stmt=VISIT_AMB_STEPS_STMT %
                                                   eventId)
        if not ambStepRecordsList:
            return False

        event.Steps = self.emk.factory.create('ns9:ArrayOfStepAmb')
        event.Steps.StepAmb = []
        for r in ambStepRecordsList:
            step = self.emk.factory.create('ns9:StepAmb')
            step.DateStart = forceDateTuple(r.value('DateStart'))
            step.DateEnd = forceDateTuple(r.value('DateEnd'))
            step.IdPaymentType = forceRef(r.value('IdPaymentType'))
            step.Doctor = self.getMedicalStaff(record=r)
            step.IdStepMis = forceStringEx(r.value('IdStepMis'))
            step.IdVisitPlace = forceRef(r.value('IdVisitPlace'))
            step.IdVisitPurpose = forceRef(r.value('IdVisitPurpose'))

            serviceRec = getVisitServiceRecord(self.db,
                                               forceRef(r.value('visitId')))
            if serviceRec:
                service = self.emk.factory.create('ns6:Service')
                service.DateStart = forceDateTuple(
                    serviceRec.value('DateStart'))
                service.DateEnd = forceDateTuple(serviceRec.value('DateEnd'))
                service.IdServiceType = forceString(
                    serviceRec.value('IdServiceType'))
                service.ServiceName = forceString(
                    serviceRec.value('ServiceName'))
                service.PaymentInfo = self.emk.factory.create(
                    'ns6:PaymentInfo')
                service.PaymentInfo.HealthCareUnit = forceString(
                    serviceRec.value('HealthCareUnit'))
                service.PaymentInfo.IdPaymentType = forceString(
                    serviceRec.value('IdPaymentType'))
                service.PaymentInfo.PaymentState = forceInt(
                    serviceRec.value('PaymentState'))
                service.PaymentInfo.Quantity = forceInt(
                    serviceRec.value('Quantity'))
                service.PaymentInfo.Tariff = forceDecimal(
                    serviceRec.value('Tariff'))
                service.Performer = self.emk.factory.create('ns6:Performer')
                service.Performer.Doctor = self.getMedicalStaff(record=r)
                service.Performer.IdRole = 3

                # addMedRecord(step, service)

            drugRecipeRecList = getDrugRecipeRecordList(self.db, eventId)
            for recipeRec in drugRecipeRecList:
                recipe = self.emk.factory.create('ns835:AppointedMedication')
                recipe.AnatomicTherapeuticChemicalClassification = forceString(
                    recipeRec.value('ATCC'))
                recipe.CourseDose = self.emk.factory.create('ns835:CourseDose')
                recipe.CourseDose.IdUnit = forceInt(
                    recipeRec.value('CourseDoseIdUnit'))
                recipe.CourseDose.Value = forceDecimal(
                    recipeRec.value('CourseDoseValue'))
                recipe.DayDose = self.emk.factory.create('ns835:DayDose')
                recipe.DayDose.IdUnit = forceInt(
                    recipeRec.value('DayDoseIdUnit'))
                recipe.DayDose.Value = forceDecimal(
                    recipeRec.value('DayDoseValue'))
                recipe.DaysCount = forceInt(recipeRec.value('DaysCount'))
                recipe.Doctor = self.getMedicalStaff(
                    personId=forceInt(recipeRec.value('IdPersonMis')))
                recipe.IssuedDate = forceDateTuple(
                    recipeRec.value('IssuedDate'))
                recipe.MedicineIssueType = forceString(
                    recipeRec.value('MedicineIssueType'))
                recipe.MedicineName = forceString(
                    recipeRec.value('MedicineName'))
                recipe.MedicineType = forceInt(recipeRec.value('MedicineType'))
                recipe.MedicineUseWay = forceInt(
                    recipeRec.value('MedicineUseWay'))
                recipe.Number = forceString(recipeRec.value('Number'))
                recipe.OneTimeDose = self.emk.factory.create(
                    'ns835:OneTimeDose')
                recipe.OneTimeDose.IdUnit = forceInt(
                    recipeRec.value('DayDoseIdUnit'))
                recipe.OneTimeDose.Value = forceDecimal(
                    recipeRec.value('DayDoseValue'))
                recipe.Seria = forceString(recipeRec.value('Seria'))
                addMedRecord(step, recipe)

            event.Steps.StepAmb.append(step)

        return True
Ejemplo n.º 8
0
    def fillBaseEvent(self, baseEventRecord, event):
        """
        :param baseEventRecord: 
        :type baseEventRecord: PyQt4.QtSql.QSqlRecord
        """
        event.OpenDate = forceDateTuple(baseEventRecord.value('OpenDate'))
        event.CloseDate = forceDateTuple(baseEventRecord.value('CloseDate'))
        event.HistoryNumber = forceStringEx(
            baseEventRecord.value('HistoryNumber'))
        event.IdCaseMis = forceStringEx(baseEventRecord.value('IdCaseMis'))
        event.IdCaseAidType = forceRef(baseEventRecord.value('IdCaseAidType'))
        event.IdPaymentType = forceRef(baseEventRecord.value('IdPaymentType'))
        event.Confidentiality = forceRef(
            baseEventRecord.value('Confidentiality'))
        event.DoctorConfidentiality = forceRef(
            baseEventRecord.value('DoctorConfidentiality'))
        event.CuratorConfidentiality = forceRef(
            baseEventRecord.value('CuratorConfidentiality'))
        event.IdLpu = forceStringEx(baseEventRecord.value('IdLpu'))
        event.IdCaseResult = forceRef(baseEventRecord.value('IdCaseResult'))
        event.IdPatientMis = forceStringEx(
            baseEventRecord.value('IdPatientMis'))
        event.Comment = 'No comments'

        event.DoctorInCharge = self.getMedicalStaff(record=baseEventRecord)

        event.Authenticator = self.emk.factory.create('ns3:Participant')
        event.Authenticator.Doctor = self.getMedicalStaff(
            record=baseEventRecord)
        event.Authenticator.IdRole = forceRef(baseEventRecord.value('IdRole'))

        event.Author = self.emk.factory.create('ns3:Participant')
        event.Author.Doctor = self.getMedicalStaff(record=baseEventRecord)
        event.Author.IdRole = forceRef(baseEventRecord.value('IdRole'))

        event.LegalAuthenticator = self.emk.factory.create('ns3:Participant')
        event.LegalAuthenticator.Doctor = self.getMedicalStaff(
            record=baseEventRecord)
        event.LegalAuthenticator.IdRole = forceRef(
            baseEventRecord.value('IdRole'))

        isHospWithParent = forceRef(baseEventRecord.value('isHospWithParent'))
        if isHospWithParent:
            guardianRecord = self.db.getRecordEx(
                stmt=GUARD_STMT %
                forceRef(baseEventRecord.value('IdPatientMis')))
            if guardianRecord is not None:
                event.Guardian = self.emk.factory.create('ns3:Guardian')
                event.Guardian.Person = self.getPersonWithIdentity(
                    record=guardianRecord)
                event.Guardian.IdRelationType = forceRef(
                    guardianRecord.value('IdRelationType'))

                guardDocList = self.db.getRecordList(
                    stmt=CLIENT_DOCUMENTS_STMT.format(
                        clientId=event.Guardian.Person.IdPersonMis))
                if guardDocList:
                    event.Guardian.UnderlyingDocument = forceStringEx(
                        guardDocList[-1].value('IdDocumentType'))
                else:
                    event.Guardian.UnderlyingDocument = u'Нет документа'  # TODO: skkachaev: Что-то передавать надо
        else:
            event.Guardian = None