<% olddate=SET("Date") oldmark=SET("Mark") SET DATe YMD SET MARK TO [-] SET CENTURY ON ajaxresponse=CREATEOBJECT('empty') oJSON=NEWOBJECT('json','json.prg') taction=orequest.form('taction') if taction='getpatient' thepatientid=allt(orequest.form('m_patientid')) tsql=[select * from (']+dbclocation+[patients') where patientid==']+thepatientid+[' into cursor patientcursor ] &tsql returnresponse=[] oResponse.ContentType = "text/plain" if reccount()=0 ADDPROPERTY(ajaxresponse,'patientrecs',0) oresponse.write(ojson.stringify(ajaxresponse)) else ADDPROPERTY(ajaxresponse,'patientrecs',reccount()) ADDPROPERTY(ajaxresponse,'birth',iif(empty(birth),'',dtoc(birth))) ADDPROPERTY(ajaxresponse,'gender',gender) ADDPROPERTY(ajaxresponse,'weight',weight) oresponse.write(ojson.stringify(ajaxresponse)) endif oresponse.flush return '' endif if taction='calculateAge' thedate=ctod(orequest.form('fromvalue')) if empty(thedate) return '{"days":0,"months":0,"years":0}' else currentdate=date() totaldays=day(currentdate)-day(thedate) if totaldays<0 totaldays=currentdate-GOMONTH(currentdate,-1) totalmonths=month(GOMONTH(currentdate,-1))-MONTH(thedate) totalyears=YEAR(GOMONTH(currentdate,-1))-YEAR(thedate) IF totalmonths<0 totalmonths=totalmonths+12 totalyears=totalyears-1 ENDIF ELSE totalmonths=month(currentdate)-MONTH(thedate) totalyears=YEAR(GOMONTH(currentdate,-1))-YEAR(thedate) IF totalmonths<0 totalmonths=totalmonths+12 totalyears=totalyears-1 ENDIF ENDIF return [{"days":]+transform(totaldays)+[,"months":]+transform(totalmonths)+[,"years":]+transform(totalyears)+[}] endif endif if taction='calculateBirth' thedays=val(orequest.form("days")) themonths=val(orequest.form("months")) theyears=val(orequest.form("years")) thedate=GOMONTH(DATE(),-(themonths+theyears*12))-thedays return [{"birth":"]+transform(thedate)+["}] endif if taction='visitdata' m_transid=ALLTRIM(TRANSFORM(NVL(orequest.form('m_transid'),''))) ADDPROPERTY(ajaxresponse,'m_transid',m_transid) store 0 to visitcount, patientcount, labcount if empty(m_transid) ADDPROPERTY(ajaxresponse,'labrecs',0) ADDPROPERTY(ajaxresponse,'patientrecs',0) ADDPROPERTY(ajaxresponse,'visitrecs',0) ADDPROPERTY(ajaxresponse,'medicinerecs',0) else tsql=[select * from (']+dbclocation+[visits') where allt(transid)==']+m_Transid+[' into cursor visitcursor readwrite ] &tsql m_patientid=allt(patientid) tsql=[select * from (']+dbclocation+[patients') where allt(patientid)==']+m_patientid+[' into cursor patientcursor readwrite ] &tsql tsql=[select * from (']+dbclocation+[lab') where allt(transid)==']+m_Transid+[' into cursor labcursor readwrite ] &tsql tsql=[select * from (']+dbclocation+[medicine') where allt(transid)==']+m_Transid+[' into cursor medicinecursor readwrite ] &tsql ADDPROPERTY(ajaxresponse,'labrecs',reccount('labcursor')) ADDPROPERTY(ajaxresponse,'patientrecs',reccount('patientcursor')) ADDPROPERTY(ajaxresponse,'visitrecs',reccount('visitcursor')) ADDPROPERTY(ajaxresponse,'medicinerecs',reccount('medicinecursor')) visitcount=reccount('visitcursor') patientcount=reccount('patientcursor') labcount=reccount('labcursor') medicinecount=reccount('medicinecursor') endif oResponse.ContentType = "text/plain" returnresponse=[] *** if not empty(visitcount) select 'visitcursor' ojson.keyforcursors='visitcursor' returnresponse=oJSON.stringify('visitcursor') endif *** if not empty(patientcount) select 'patientcursor' ojson.keyforcursors='patientcursor' patientref=oJSON.stringify('patientcursor') returnresponse=oJSON.AddJSONProps(returnresponse,patientref) endif *** if not empty(labcount) select 'labcursor' ojson.keyforcursors='labcursor' labref=oJSON.stringify('labcursor') returnresponse=oJSON.AddJSONProps(labref,returnresponse) endif *** if not empty(medicinecount) select 'medicinecursor' ojson.keyforcursors='medicinecursor' medref=oJSON.stringify('medicinecursor') returnresponse=oJSON.AddJSONProps(medref,returnresponse) endif oResponse.Write(oJSON.AddJSONProps(ojson.stringify(ajaxresponse),returnresponse)) oresponse.flush SET DATE &olddate SET MARK TO &oldmark CLOSE TABLES CLOSE DATABASES endif %>