Example #1
0
    def get(self):
        id = self.request.get('id')
        jsArray = []

        if not id:
            dptList = Department.all() 
            for one in dptList:
                jsObj = { 
                    str(one.dptCode):one.dptName
                    #'link'          :one.dptLink  
                }
                jsArray.append( jsObj )
       
        else: 
            jsArray.append( {"id": id } )
            dept = Department.all().filter('dptCode = ', int(id) ).get()
            if dept:
                jsArray.append( {"name": dept.dptName } )
                
                # searching for the clinic info:
                doctors  = []
                times    = []
                docCodes = []
                clinics = Clinic.all().filter('dept =', dept.key() ).order('date')
                for one in clinics:
                    times.append( one.date )
                    if one.doctor.docCode not in docCodes:
                        docCodes.append( one.doctor.docCode )
                        doctors.append( { one.doctor.docCode : one.doctor.docName } )

                jsArray.append( { "doctor" : doctors }) 
                jsArray.append( { "time"   : times   })
    
        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write( simplejson.dumps(jsArray) )
Example #2
0
    def post(self):
        okey = False
        errorMessage = ''
        docData   = self.request.get('doctor')
        deptData  = self.request.get('dept')
        timeData  = self.request.get('time')  
        idData    = self.request.get('id')
        firstData = self.request.get('first')
        phoneData = self.request.get('phone')
        
        if len(phoneData) == 0 and bool(firstData.lower() == 'true'):
            jsDic = { "status" : "2",  
                      "message": [{"phone":"Phone Number"}],
                    }       
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write( simplejson.dumps(jsDic) )
            return 

        # Check for rest values:
        doc  = Doctor.all().filter('docCode =', docData ).get()
        dept = Department.all().filter('dptCode =', int(deptData) ).get()
        if not doc:
            errorMessage = 'BadDoctorId'
        elif not dept:
            errorMessage = 'BadDeptId'
        elif not timeData:
            errorMessage = 'MissingTimeInfo'
        else:
            clinic = Clinic.all().filter('doctor =', doc).filter('dept =', dept).filter('date =', timeData).get()
            if not clinic:
                errorMessage = 'WrongInfo'
            else:
                okey = True 
       
         
        if okey:
            # Save the info to the db:
            reg = Register()
            reg.doc = doc
            reg.dept = dept
            reg.link = clinic.link
            reg.theId = idData
            reg.isFirst = bool(firstData.lower() == 'true')
            reg.phone = phoneData
            reg.put()
            self.redirect('/tools/register?key=%s' % str(reg.key()) )
        
        else:
            jsDic = { "status":"1",
                      "message": errorMessage,
                    }
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write( simplejson.dumps(jsDic) )
Example #3
0
    def get(self):
        departments = Department.all()
        for one in departments:
            one.delete()

        self.response.out.write('Delete all department data ...')
Example #4
0
    def post(self):
        docData  = self.request.get('doctor')
        deptData = self.request.get('dept')
        timeData = self.request.get('time') 

        doc  = Doctor.all().filter('docCode =', docData ).get()
        dept = Department.all().filter('dptCode =', int(deptData) ).get()
        
        # Check for post data:
        errorMessage = None
        if not doc:
            errorMessage = 'BadDoctorId'
        elif not dept:
            errorMessage = 'BadDeptId'
        elif not timeData:
            errorMessage = 'MissingTimeInfo'
        else:
            clinic = Clinic.all().filter('doctor =', doc).filter('dept =', dept).filter('date =', timeData).get()
            if not clinic:
                errorMessage = 'WrongInfo'
 
        if errorMessage:
            jsDic = { "status":"1",
                      "message": errorMessage,
                    }
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write( simplejson.dumps(jsDic) )
            return
       
        vals = {}
        vals['RadioButtonList1'] = '花蓮'
        vals['txtMRNo'] = 'A123123123'
        vals['btnQry'] = '查詢'
        vals['__EVENTARGUEMENT'] = ''
        vals['__EVENTTARGET'] = ''
        vals['__VIEWSTATE'] = ''

        cookie = cookielib.CookieJar()
        opener = urllib2.build_opener( urllib2.HTTPCookieProcessor(cookie))
      
        #Operation: GET ----------------------'
        req = urllib2.Request(cancelUrl)
        rsp = opener.open(req)
        soup = BeautifulSoup(rsp)

        qText = soup.find(id='lblQuestion').text
        if len(qText.split('+')) == 2:
            A = qText.split('+')[0]
            B = qText.split('+')[1].split('=')[0]
            C = int(A) + int(B)

        elif len(qText.split('-')) == 2:
            A = qText.split('-')[0]
            B = qText.split('-')[1].split('=')[0]
            C = int(A) - int(B)

        vals['txtAnswer'] = str(C)
        vals['__EVENTVALIDATION'] = soup.find(id='__EVENTVALIDATION')['value']
        vals['__VIEWSTATE'] = soup.form.find(id='__VIEWSTATE')['value']

        #Operation: POST --------------------'
        req = urllib2.Request(cancelUrl, urllib.urlencode(vals) )
        rsp = opener.open(req)

        soup = BeautifulSoup(rsp)
        error = soup.find(id='Label5')
        if error: # No Registeration
            jsDic = { "status":"1",
                      "message": error.text,
                    }
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write( simplejson.dumps(jsDic) )
            return

        rTable = soup.find(id='dgList')
        results = rTable.findAll('tr')
        row = 0
        target = None
        for one in results:
            if row != 0:
                tds = one.findAll('td')
                col = 0
                for td in tds:
                    if col == 0:
                        script = td.find('a')['href']
                    elif col == 1:
                        date = td.text
                    elif col == 2:
                        time = td.text
                    elif col == 4:
                        docInfo = td.text
                    col = col + 1
            
                year  = str(int(date[:3]) + 1911)
                month = date[3:5]
                day   = date[5:]

                if time == u'早上':
                    time = 'A'
                elif time == u'下午':
                    time = 'B'
                elif time == u'晚上':
                    time = 'C'
            
                datetime = year + '-' + month + '-' + day + '-' + time
                docCode  = docInfo.split('(')[1].split(')')[0].split(' ')[0]

                if doc.docCode == docCode and clinic.date == datetime:
                    target = script.split('\'')[1].split('\'')[0]
                    break

            row = row + 1

        if target:
            vals['__EVENTTARGET'] = target
            vals['__EVENTVALIDATION'] = soup.find(id='__EVENTVALIDATION')['value']
            vals['__VIEWSTATE'] = soup.form.find(id='__VIEWSTATE')['value'] 
            del vals['btnQry']

            req = urllib2.Request(cancelUrl, urllib.urlencode(vals) )
            rsp = opener.open(req)
            jsDic = { "status": "0" }
        
        else: 
            jsDic = { "status":"1",
                      "message": "RecordNotFound",
                    }

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write( simplejson.dumps(jsDic) )
Example #5
0
 def get(self):
     depts = Department.all()
     for one in depts:
         one.delete()
     return