Esempio n. 1
0
def generatorPdf(diagnoseId, identityPhone):
    diagnose = Diagnose.getDiagnoseById(diagnoseId)
    report = None
    if hasattr(diagnose, 'report'):
        report = diagnose.report
        if diagnose and report and report.type == constant.ReportType.Doctor:
            data = {}
            data['techDesc'] = report.techDesc
            data['imageDesc'] = report.imageDesc
            data['diagnoseDesc'] = report.diagnoseDesc
            data['seriesNumber'] = report.seriesNumber
            data['fileUrl'] = report.fileUrl
            createDate = report.createDate
            if createDate:
                createDate = createDate.strftime('%Y-%m-%d')
                data['createDate'] = createDate
            import DoctorSpring.views.data_change_service as dataChangeService
            postions = dataChangeService.getDiagnosePositonFromDiagnose(
                diagnose)
            if postions:
                data['postions'] = postions
            if hasattr(diagnose, 'patient') and diagnose.patient:
                data['gender'] = diagnose.patient.gender
                birthDate = diagnose.patient.birthDate
                if birthDate:
                    birthDate = birthDate.strftime('%Y-%m-%d')
                    data['birthDate'] = birthDate
                data['name'] = diagnose.patient.realname
            if hasattr(diagnose, 'doctor'):
                data['doctorName'] = diagnose.doctor.username

            html = render_template('diagnoseResultPdf.html', data=data)
            fileName = constant.DirConstant.DIAGNOSE_PDF_DIR + 'test.pdf'
            result = open(fileName, 'wb')  # Changed from file to filename

            url = save_pdf(html, result, diagnoseId, fileName, identityPhone)
            result.close()
            # return render_template("testpdf.html",getAvatar=getAvatar)
            return url
    return None
Esempio n. 2
0
def generatorPdf(diagnoseId):
    diagnose=Diagnose.getDiagnoseById(diagnoseId)
    report=None
    if hasattr(diagnose,'report'):
        report=diagnose.report
        if diagnose and report and report.type==constant.ReportType.Doctor:
            data={}
            data['techDesc']=report.techDesc
            data['imageDesc']=report.imageDesc
            data['diagnoseDesc']=report.diagnoseDesc
            data['seriesNumber']=report.seriesNumber
            data['fileUrl']=report.fileUrl
            createDate=report.createDate
            if createDate:
                createDate=createDate.strftime('%Y-%m-%d')
                data['createDate']=createDate
            import  DoctorSpring.views.data_change_service as dataChangeService
            postions=dataChangeService.getDiagnosePositonFromDiagnose(diagnose)
            if postions:
                data['postions']=postions
            if hasattr(diagnose,'patient') and diagnose.patient:
                data['gender']=diagnose.patient.gender
                birthDate=diagnose.patient.birthDate
                if birthDate:
                    birthDate=birthDate.strftime('%Y-%m-%d')
                    data['birthDate']=birthDate
                data['name']=diagnose.patient.realname
            if hasattr(diagnose,'doctor'):
                data['doctorName']=diagnose.doctor.username

            html =  render_template('diagnoseResultPdf.html',data=data)
            fileName=constant.DirConstant.DIAGNOSE_PDF_DIR+'test.pdf'
            result = open(fileName, 'wb') # Changed from file to filename

            url = save_pdf(html,result,diagnoseId,fileName)
            result.close()
            # return render_template("testpdf.html",getAvatar=getAvatar)
            return url
    return None
Esempio n. 3
0
def generatorHtml(diagnoseId, identityPhone):
    diagnose=Diagnose.getDiagnoseById(diagnoseId)
    report=None
    if hasattr(diagnose,'report'):
        report=diagnose.report
        if diagnose and report and report.type==constant.ReportType.Doctor:
            data={}
            data['techDesc']=report.techDesc
            data['imageDesc']=report.imageDesc
            data['diagnoseDesc']=report.diagnoseDesc
            data['seriesNumber']=report.seriesNumber
            data['fileUrl']=report.fileUrl
            if hasattr(diagnose,'diagnoseSeriesNumber'):
                data['diagnoseSN'] = diagnose.diagnoseSeriesNumber
            createDate=report.createDate
            if createDate:
                createDate=createDate.strftime('%Y-%m-%d')
                data['createDate']=createDate
            import  DoctorSpring.views.data_change_service as dataChangeService
            postions=dataChangeService.getDiagnosePositonFromDiagnose(diagnose)
            if postions:
                data['postions']=postions
            if hasattr(diagnose,'patient') and diagnose.patient:
                data['gender']=diagnose.patient.gender
                birthDate=diagnose.patient.birthDate
                if birthDate:
                    birthDate=birthDate.strftime('%Y-%m-%d')
                    data['birthDate']=getAge(birthDate)
                data['name']=diagnose.patient.realname
            if hasattr(diagnose,'doctor'):
                data['doctorName']=diagnose.doctor.username

            if hasattr(diagnose,'adminId'):
                adminUser = User.getById(diagnose.adminId)
                if adminUser.name:
                    data['adminName']= adminUser.name

            html =  render_template('diagnoseResultPdf.html',data=data)
            fileName=constant.DirConstant.DIAGNOSE_PDF_DIR+'diagnose'+str(diagnoseId)+'Html.html'
            result = open(fileName, 'w+b') # Changed from file to filename
            result.write(html)
            result.close()

            fileLink = 'file://'+fileName
            pdfLink = constant.DirConstant.DIAGNOSE_PDF_DIR+'diagnose'+str(diagnoseId)+'Pdf.pdf'
            print fileLink
            print pdfLink
            returnCode = generate_pdf_from_html(fileLink,pdfLink)
            # return render_template("testpdf.html",getAvatar=getAvatar)
            if(returnCode == 0):
                #add encrypt for pdf
                output = PdfFileWriter()
                with open(pdfLink, "r+") as f1:
                    input1 = PdfFileReader(f1)

                    for i in range(input1.getNumPages()):
                        output.addPage(input1.getPage(i))
                    #print(identityPhone)
                    password = str(int(identityPhone))
                    owner_pwd = ''.join(random.choice(string.letters + string.digits) for _ in range(64))
                    #print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + owner_pwd)
                    output.encrypt(password, owner_pwd)
                    f1.seek(0)
                    output.write(f1)
                    f1.truncate()
                    fileUrl=upload_pdf(pdfLink,diagnoseId)
                    return fileUrl
            else:
                return None
    return None
Esempio n. 4
0
def generatorHtml(diagnoseId, identityPhone):
    diagnose = Diagnose.getDiagnoseById(diagnoseId)
    report = None
    if hasattr(diagnose, 'report'):
        report = diagnose.report
        if diagnose and report and report.type == constant.ReportType.Doctor:
            data = {}
            data['techDesc'] = report.techDesc
            data['imageDesc'] = report.imageDesc
            data['diagnoseDesc'] = report.diagnoseDesc
            data['seriesNumber'] = report.seriesNumber
            data['fileUrl'] = report.fileUrl
            if hasattr(diagnose, 'diagnoseSeriesNumber'):
                data['diagnoseSN'] = diagnose.diagnoseSeriesNumber
            createDate = report.createDate
            if createDate:
                createDate = createDate.strftime('%Y-%m-%d')
                data['createDate'] = createDate
            import DoctorSpring.views.data_change_service as dataChangeService
            postions = dataChangeService.getDiagnosePositonFromDiagnose(
                diagnose)
            if postions:
                data['postions'] = postions
            if hasattr(diagnose, 'patient') and diagnose.patient:
                data['gender'] = diagnose.patient.gender
                birthDate = diagnose.patient.birthDate
                if birthDate:
                    birthDate = birthDate.strftime('%Y-%m-%d')
                    data['birthDate'] = getAge(birthDate)
                data['name'] = diagnose.patient.realname
            if hasattr(diagnose, 'doctor'):
                data['doctorName'] = diagnose.doctor.username

            if hasattr(diagnose, 'adminId'):
                adminUser = User.getById(diagnose.adminId)
                if adminUser.name:
                    data['adminName'] = adminUser.name

            html = render_template('diagnoseResultPdf.html', data=data)
            fileName = constant.DirConstant.DIAGNOSE_PDF_DIR + 'diagnose' + str(
                diagnoseId) + 'Html.html'
            result = open(fileName, 'w+b')  # Changed from file to filename
            result.write(html)
            result.close()

            fileLink = 'file://' + fileName
            pdfLink = constant.DirConstant.DIAGNOSE_PDF_DIR + 'diagnose' + str(
                diagnoseId) + 'Pdf.pdf'
            print fileLink
            print pdfLink
            returnCode = generate_pdf_from_html(fileLink, pdfLink)
            # return render_template("testpdf.html",getAvatar=getAvatar)
            if (returnCode == 0):
                #add encrypt for pdf
                output = PdfFileWriter()
                with open(pdfLink, "r+") as f1:
                    input1 = PdfFileReader(f1)

                    for i in range(input1.getNumPages()):
                        output.addPage(input1.getPage(i))
                    #print(identityPhone)
                    password = str(int(identityPhone))
                    owner_pwd = ''.join(
                        random.choice(string.letters + string.digits)
                        for _ in range(64))
                    #print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + owner_pwd)
                    output.encrypt(password, owner_pwd)
                    f1.seek(0)
                    output.write(f1)
                    f1.truncate()
                    fileUrl = upload_pdf(pdfLink, diagnoseId)
                    return fileUrl
            else:
                return None
    return None