<% =SYS(3101,65001) olddate=SET("Date") oldmark=SET("Mark") ajaxresponse=CREATEOBJECT('empty') oJSON=NEWOBJECT('json','json.prg') thepassword=orequest.form('txtpassword') IF NOT ALLTRIM(thepassword)==ALLTRIM(onlinepassword) RETURN '{"terror":"Password not correct '+onlinepassword+'"}' endif SET DATe YMD SET MARK TO [-] SET CENTURY ON m_transid=ALLTRIM(TRANSFORM(NVL(orequest.form('m_transid'),''))) m_doctor=upper(ALLTRIM(TRANSFORM(NVL(orequest.form('m_doctor'),'')))) m_patientid=ALLTRIM(TRANSFORM(NVL(orequest.form('m_patientid'),''))) m_patientname=upper(ALLTRIM(TRANSFORM(NVL(orequest.form('m_patientname'),'')))) m_date=ALLTRIM(TRANSFORM(NVL(orequest.form('m_date'),''))) m_birth=ctod(ALLTRIM(TRANSFORM(NVL(orequest.form('m_birth'),'')))) m_weight=ALLTRIM(TRANSFORM(NVL(orequest.form('m_weight'),''))) m_speciman=upper(ALLTRIM(TRANSFORM(NVL(orequest.form('m_speciman'),'')))) m_gender=ALLTRIM(TRANSFORM(NVL(orequest.form('m_gender'),''))) m_solution=ALLTRIM(TRANSFORM(NVL(orequest.form('m_solution'),''))) if m_gender='u' m_gender='' endif *deal with patients usesafe('patients') haserror=.f. if empty(m_patientid) or m_patientid==m_patientname *we need a new patientid newid=subst(TRANSFORM(year(date())),3)+padl(allt(transform(month(DATE()))),2,[0])+padl(allt(transform(day(DATE()))),2,[0]) for i=1 to 9999 m_patientid=newid+padl(allt(transform(i)),3,[0]) if not seek(m_patientid,[patients],[patientid]) exit endif endfor =seek(padr(m_patientname,len(name),[ ]),[patients],[name]) if eof() append blank replace dtime with datetime(), patientid with m_patientid,name with m_patientname, gender with m_gender, birth with m_birth endif ADDPROPERTY(ajaxresponse,'patientadded',m_patientname) endif *Now we have to put extra fields like gender, and birth if not exists =seek(padr(allt(m_patientname),len(name),[ ]),[patients],[name]) if eof() append blank endif ** tsql=[replace patientid with "]+m_patientid+[",weight with ]+transform(val(m_weight))+[, name with "]+m_patientname+[", gender with "]+m_gender+[", birth with m_birth] try &tsql catch haserror=.t. strtofile(tsql,addbs(oprop.appstartpath)+[temp\tsql.txt]) ADDPROPERTY(ajaxresponse,'terror','true') ADDPROPERTY(ajaxresponse,'tmessage','error in sql. please, check temp\tsql.txt') delete next 1 ENDTRY ** if haserror return [{"tsql":"]+ojson.stringify(tsql)+["}] else ADDPROPERTY(ajaxresponse,'m_patientid',m_patientid) ADDPROPERTY(ajaxresponse,'m_patientname',m_patientname) endif *We should check for visits. If it exists, then we will update *If no record exists, or if empty fref we will insert *if fref is empty, we will insert, but we if empty(m_transid) tsql=[select top 1 val(transid) as vtr from (']+dbclocation+[visits') order by vtr desc into cursor tempcursor] &tsql if _tally=0 m_transid=allt(transform(1)) else m_transid=allt(transform(vtr+1)) endif endif m_transid=allt(padr(m_transid,9,' ')) usesafe('visits') =seek(m_transid,[visits],[transid]) if eof() append blank replace transid with m_transid, dtime with datetime() endif replace patientid with m_patientid, speciman with m_speciman, doctor with m_doctor, solution with m_solution ADDPROPERTY(ajaxresponse,'m_transid',m_transid) ****Now we have to get data from lab usesafe('lab') delete all for allt(transid)==m_transid use (addbs(oprop.appstartpath)+[temp\labmaster]) in select([labmaster]) select [labmaster] tstr=[] scan thistest=[test]+allt(testid) newfield=upper(allt(transform(nvl(orequest.form(thistest),'')))) thegroup=g thetest=testid if not empty(newfield) tstr=tstr+thistest+[ Testname: ]+allt(testname)+[: ]+newfield+[ GroupName: ]+allt(groupname)+[ UNIT: ]+allt(unit)+[ Result: ]+newfield+[ Range: ]+allt(range)+chr(13) select 'lab' append blank replace transid with m_transid, g with thegroup, testid with thetest, result with newfield endif select [labmaster] endscan *tstr=tstr+transform(orequest.form('teststring')) strtofile(tstr,(addbs(oprop.appstartpath)+[temp\labdata.txt])) ****Now getting the medicines datalength=val(transform(orequest.form('medrecords'))) usesafe('medicine') delete all for allt(transid)==m_transid ADDPROPERTY(ajaxresponse,'medicinecount',datalength) if datalength>0 for i=1 to datalength themed='med'+allt(transform(i)) themedname=themed+'medicine' thedos='dos'+allt(transform(i)) thetim='tim'+allt(transform(i)) thedur='dur'+allt(transform(i)) themedicine=upper(allt(transform(nvl(orequest.form(themed),'')))) themedicinename=upper(allt(transform(nvl(orequest.form(themedname),'')))) if themedicine==themedicinename usesafe('itemmast') newitem=100 do while seek(padr(allt(transform(newitem)),16,[ ]),[itemmast],[itemid]) newitem=newitem+1 enddo themedicine=padr(allt(transform(newitem)),16,[ ]) append blank replace itemid with themedicine, name with themedicinename endif select [medicine] thedose=upper(allt(transform(nvl(orequest.form(thedos),'')))) thetime=upper(allt(transform(nvl(orequest.form(thetim),'')))) theduration=upper(allt(transform(nvl(orequest.form(thedur),'')))) if not empty(themedicine) append blank replace transid with m_transid, itemid with themedicine, medicine with themedicinename, dose with thedose, times with thetime, duration with theduration endif endfor endif **** oResponse.ContentType = "text/plain" *ojson.keyforcursors='xfile' *freffs=oJSON.stringify('xfile') freffs=[] oResponse.Write(oJSON.AddJSONProps(ojson.stringify(ajaxresponse),freffs)) oresponse.flush SET DATE &olddate SET MARK TO &oldmark CLOSE TABLES CLOSE DATABASES %>