{
    "pluginname": "CMCH APP",
    "systemplugin": "0",
    "version": "1.0",
    "icon": "mif-medkit",
    "table_def": [{
            "name": "nbbi_asset",
            "importtabledef": {
                "pluginname": "NBBI Management"
            }
        },
		{
            "name": "cmch_doctors",
            "saveid": "1sv",
            "delid": "1dt",
            "getid": "1gt",
            "form": {
                "0": {
                    "title": "Doctor",
                    "icon": "mif-medkit",
                    "type": "Inline",
                    "fields": "name,qualification,specialization,daystime,mobilenum,email,mcireg,availability"
                }
            },
            "list": {
                "1lt": {
                    "tbl": "||thistbl||",
                    "getform": "||thistbl|| 0",
                    "output": "#workareaTablebox",
                    "elem": {
                        "parent": "div",
                        "output": "#workareaFilter",
                        "elem": [{
                                "name": "f4",
                                "type": "button",
                                "value": "Doctors Attendance Details",
                                "onclick": "Eirene.runStmt('2lt')",
                                "title": "Doctors Attendance"
                            }
                        ]
                    },
                    "fld": "name,qualification,specialization,daystime,mobilenum,in_out_status",
                    "editablefields": "in_out_status",
                    "includeeditdelete": true,
                    "header": "Doctor,Qualification,Specialization,Days_Time,Mobile,IN/OUT",
                    "whr": "recordstatus=1",
                    "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:hide;#workareaFilter1;slow-cmd:dom,fun:hide;#workareaAppendix;slow"
                }
            },
            "fields": [{
                    "name": "name varchar(50) NOT NULL",
                    "label": "Doctor Name"
                }, {
                    "name": "qualification varchar(50) NOT NULL",
                    "label": "Qualification",
                    "required": true
                }, {
                    "name": "specialization varchar(50)",
                    "label": "Specialization"
                }, {
                    "name": "daystime varchar(50) NOT NULL",
                    "label": "Visit Days",
                    "required": true
                }, {
                    "name": "mobilenum varchar(20) NOT NULL",
                    "label": "Mobile Number",
                    "required": true
                }, {
                    "name": "email varchar(50)",
                    "label": "Email"
                }, {
                    "name": "in_out_status tinyint NOT NULL DEFAULT 0",
                    "fieldtype": "switch",
                    "label": "In Out Status",
                    "dataon": "IN",
                    "dataoff": "Out"
                }, {
                    "name": "mbbscertficate varchar(50)",
                    "label": "MBBS Certificate"
                }, {
                    "name": "mcireg varchar(50)",
                    "label": "Registration No.",
                    "required": true
                }, {
                    "name": "othercert1 varchar(50)",
                    "label": "Other Certificate 1"
                }, {
                    "name": "othercert2 varchar(50)",
                    "label": "Other Certificate 2"
                }, {
                    "name": "availability varchar(20) NOT NULL",
                    "fieldtype": "select",
                    "option": "Available,Not Available",
                    "label": "Availability"
                }, {
                    "name": "image",
                    "label": "Image",
                    "type": "file",
                    "maxsize": "200kb",
                    "uploadstmt": "6upim"
                }
            ]
        }, {
            "name": "cmch_doctorsattendance",
            "saveid": "2sv",
            "delid": "2dt",
            "getid": "2gt",
            "form": {
                "0": {
                    "title": "Doctor Attendance",
                    "icon": "mif-medkit",
                    "type": "Inline",
                    "fields": "*"
                }
            },
			"joindef":{
				"cmch_doctors":"||thistbl||.docid=cmch_doctors.id"
			},
            "list": {
                "2lt": {
                    "tbl": "||thistbl|| a","usejoin":"cmch_doctors b",
                    "getform": "||thistbl|| 0",
                    "filter": "docid,intime,outtime,rounds",
                    "fld": "b.name,a.intime,a.outtime,a.rounds",                    
                    "header": "Doctor,In,Out,Rounds",
                    "limit": "100",
                    "defaultwhr": "a.recordstatus=1"
                }
            },
            "fields": [{
                    "name": "docid",
                    "type": "lookup",
                    "other": "NOT NULL",
                    "label": "Doctor",
                    "lookup": {
                        "sqlid": "1dalkp",
                        "tbl": "cmch_doctors",
                        "fld": "name"
                    }
                }, {
                    "name": "intime",
                    "type": "datetime",
                    "other": "NOT NULL",
                    "label": "Intime"
                }, {
                    "name": "outtime",
                    "type": "datetime",
                    "other": "",
                    "label": "Outtime"
                }, {
                    "name": "rounds",
                    "type": "tinyint",
                    "other": "NOT NULL",
                    "label": "Is Rounds"
                }
            ]
        }, {
            "name": "cmch_patient",
            "saveid": "svpat","delid": "delpat","getid": "gtpat",
            "form": {
                "0": {
                    "title": "Patient","icon": "mif-medkit",
                    "type": "2 Columns","fields": "*"
                }
            },
            "list": {
                "3": {
                    "getform": "||thistbl|| 0",
                    "output": "#workareaTablebox",
                    "limit": 100,
                    "filter": "pname,pid,pmobile",					
                    "fld": "pname,pid,pgender,pmobile,(YEAR(CURDATE())-pyob) as page,pememobile1",
                    "includeeditdelete": true,
					"elem":{
						"output":"#workareaFilter",
						"elem":[
							{"name":"3btn","type":"button","value":"QRCode","onclick":"Eirene.runStmt('3pdf1');"}
						]
					},
                    "srt": "createdon DESC",
                    "header": "Patient Name,Patient ID,Gender,Mobile,Age,Emergency Num",
                    "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:hide;#workareaAppendix;slow-cmd:dom,fun:hide;#workareaFilter1;slow"
                },
				"3pdf":{
					"action":"Return",
					"output":"#workareaFilter1",
					"value":["Patient ID(seperated by comma):",
						"<input id='pidforpdf'/> <button onclick='Eirene.runStmt(&apos;3pdf1&apos;,{pidtext:$(&apos;#pidforpdf&apos;).val(),startrow:$(&apos;#startrow&apos;).val(),startcol:$(&apos;#startcol&apos;).val(),copies:$(&apos;#copies&apos;).val()});'>QRCode</button>",
						"<br>Row Start: <select class='select0' id='startrow' values='1,2,3,4,5,6'></select>",
						"<br>Col Start: <select class='select0' id='startcol' values='1,2'></select>",
						"<br>Copies: <select class='select0' id='copies' values='1,2,3'></select>",
						"<script>convertSelect('#workareaFilter1');</script>"
					]
				},
				"3pdf1":{
					"action":"GetPDF",
					"output":"#workareaTablebox","filter":[{"type":"text","name":"pidtext","id":"pidtext","label":"Patient ID (Seperated by Comma) "}],
					"tbl":"cmch_patient",
					"fld":"pid,pname,pgender,pcity,pdistrict,pstate",
					"whr":"recordstatus=1 and FIND_IN_SET(pid,'||pidtext||') > 0",
					"islabel":1,					
					"colspace":5,
					"rowspace":5,
					"rowheight":[45,45,45,45,45,45],
					"colwidth":[100,100],
					"template":[
						{"x":"10","y":"10","text":"https://cmch.niea.in/cmchapp.php?pid=||pid||&plugin=CMCH%20APP&stmt=patser&needlogin=false","width":20,"height":20,"qrcode":true},
						{"x":"12","y":"30","text":"||pidtext||"},
						{"x":"32","y":"10","text":"Name: ||pname||"},
						{"x":"32","y":"16","text":"Gender: ||pgender||"},
						{"x":"32","y":"22","text":"Address: ||pcity||, ||pdistrict||, ||pstate||"}
					]
				}
            },
            "fields": [{
                    "name": "pname varchar(50) NOT NULL","filterop":"like",
                    "label": "Name","required": true
                }, {
                    "name": "pid char(6) UNIQUE NOT NULL",
                    "label": "Patient ID","required": true
                }, {
                    "name": "pgender enum('Male','Female')",
                    "label": "Gender",  "required": true
                }, {
                    "name": "pmaritalstatus enum('Single','Married','Widowed','Divorced')",
                    "label": "Marital Status", "required": true
                }, {
                    "name": "pmobile varchar(30) NOT NULL",
                    "label": "Mobile Number","required": true                    
                }, {
                    "name": "paadhaar varchar(20)",
                    "label": "Aadhar Number"
                }, {
                    "name": "pyob int NOT NULL",
                    "label": "Year of Birth",
                    "required": true,
                    "onblur": "if($(this).val()<100){let yr=new Date().getFullYear();let yob=yr-$(this).val();$(this).val(yob);}",
                    "saveif": {
                        "if": "||this|| > 1920"
                    }
                }, {
                    "name": "pemail varchar(30) NOT NULL",
                    "label": "Email"
                }, {
                    "name": "pguardian varchar(30) NOT NULL",
                    "label": "Guardian"
                }, {
                    "name": "pward varchar(30) NOT NULL",
                    "label": "Ward No."
                }, {
                    "name": "pcity varchar(30) NOT NULL",
                    "label": "City/Town",
                    "required": true
                }, {
                    "name": "pdistrict varchar(30) NOT NULL",
                    "label": "District",
                    "required": true
                }, {
                    "name": "pstate varchar(30) NOT NULL",
                    "label": "State",
                    "required": true
                }, {
                    "name": "pememobile1 varchar(30)",
                    "label": "Emergency Mobile Number 1"
                }, {
                    "name": "pememobile2 varchar(30)",
                    "label": "Emergency Mobile Number 2"
                }, {
                    "name": "pasthistory varchar(1000) NOT NULL DEFAULT 'NIL'",
                    "label": "Medical History"
                }, {
                    "name": "pastsurgery varchar(1000) NOT NULL DEFAULT 'NIL'",
                    "label": "Surgery History"
                }, {
                    "name": "familyhistory varchar(1000) NOT NULL DEFAULT 'NIL'",
                    "label": "Family History"
                }, {
                    "name": "department varchar(40) NOT NULL DEFAULT 'NIL'",
                    "label": "Department (for Pending Payments)",
                    "fieldtype": "select",
                    "option": "Get Array CMCH Department (Bills)",
                    "commaseperatedvalue": true
                }
            ]
        }, {
            "name": "cmch_appointment",
            "saveid": "4sv",
            "getid": "4gt",
            "delid": "4dt",
			"joindef":{
				"cmch_patient":"||thistbl||.pid=cmch_patient.pid",
				"cmch_doctors":"||thistbl||.doctor=cmch_doctors.id"	
			},
			"trigger": {
				"insert": {
					"sqlstatement": {
					"a": "INSERT INTO cmch_op(id, appid,opdate, createdby) SELECT UUID(), '||lastinsertid||','||CURDATETIME||','||userid||'"
					}
				}
			},
			 "form": {
                "0": {
                    "title": "Appointment",
                    "icon": "mif-delicious",
                    "type": "2 Columns",
                    "fields": "pid,pcase,pdate,doctor"
                }
            },
            "list": {
				"4chrt":{
					"name":"Daily Report",
					"action":"Get Chart New","usejoin":"cmch_patient b,cmch_doctors c",
					"tbl":"cmch_appointment a","filter":"pcase,doctor,pdate",
					"defaultwhr":"a.recordstatus=1",
					"fld": "DATE_FORMAT(a.pdate,'%d-%m') as adate,c.name as doctor,count(*) as cnt",                    
					"grp":"a.pdate,c.name",
					"title":"Appointment Daily Report",
					"label":"adate",
					"secondarylabel":"doctor",
					"value":"cnt",
					"type":"bar"
				},"4chrt1":{
					"name":"Monthly Report",
					"action":"Get Chart New","usejoin":"cmch_patient b,cmch_doctors c",
					"tbl":"cmch_appointment a","filter":"pcase,doctor,pdate",
					"defaultwhr":"a.recordstatus=1",
					"fld": "DATE_FORMAT(a.pdate,'%M') as adate,c.name as doctor,count(*) as cnt",                    
					"grp":"adate,c.name",
					"title":"Appointment Monthly Report",
					"label":"adate",
					"secondarylabel":"doctor",
					"value":"cnt",
					"type":"bar"
				},
                "4": {
                    "action": "Get Table","usejoin":"cmch_patient b,cmch_doctors c",
                    "name": "Appointment List","getchart":"4chrt,4chrt1",
                    "getform": "||thistbl|| 0",
                    "outputto": "html",
                    "output": "table",
                    "tbl": "cmch_appointment a",
                    "filter": "pid,pcase,pdate,doctor",
                    "fld": "a.pid,b.pname,a.pcase,a.pdate,c.name",                    
                    "functionfield":[
						{"name":"appbtn","type":"button","value":"Admit","onclick":"$(this).hide();Eirene.runStmt('19sv',{pid:'<a.pid>',docid:'<a.doctor>',ipcase:'<a.pcase>',appid:'<a.id>',ward:'b6ff8afa-e206-11ee-b32b-525400a09ba1'})"}
						],
					"header": "Patient ID,Patient,Case,Appointment Date,Doctor,IP",
					"includeeditdelete":true,
                    "defaultwhr":"a.recordstatus=1",
					"srt":"a.createdon DESC",
                    "prepend": "<div><button onclick='Eirene.runStmt(&apos;4&apos;)'>Today</button><button onclick='Eirene.runStmt(&apos;4a-4aflt&apos;)'>Treatment Protocol</button></div>",
                    "onsuccess": "cmd:dom,fun:function;convertSelect;#workareaTablebox-cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:hide;#workareaFilter1;slow-cmd:dom,fun:hide;#workareaAppendix;slow"
                }
            },
            "fields": [
				{
                    "name": "pid char(6) NOT NULL",
                    "required": 1,
                    "label": "Patient ID",
					"fieldtype": "lookup",
					"lookup": {
						"sqlid": "plkup",
						"tbl": "cmch_patient",
						"fld": "pid,CONCAT(pid,' / ',pname)AS pid",
						"whr": "recordstatus=1 AND (pname LIKE '%||searchtext||%' or pid LIKE '%||searchtext||%')"
					}
                }, {
                    "name": "pcase varchar(20) NOT NULL",
                    "required": 1,
                    "fieldtype": "select",
                    "label": "Case",
                    "option": "SELECT pdata FROM eirene_meta WHERE pname='Appointment Cases'",
                    "commaseperatedvalue": true
                }, {
                    "name": "pdate datetime NOT NULL",
                    "required": 1,
                    "label": "Appointment Date"
                }, {
                    "name": "doctor char(36) NOT NULL",
                    "required": 1,
                    "label": "Doctor",
                    "fieldtype": "select",
                    "option": "select id,name from cmch_doctors where recordstatus=1"
                }, {
                    "name": "status tinyint NOT NULL",
                    "label": "Status"
                }, {
                    "name": "primarycomplaint varchar(1000) NOT NULL",
                    "label": "Primary Complain"
                }, {
                    "name": "test varchar(1000) NOT NULL",
                    "label": "Lab Tests"
                }, {
                    "name": "diagnosis varchar(1000) NOT NULL",
                    "label": "Diagnosis"
                }, {
                    "name": "medicare varchar(1000) NOT NULL",
                    "label": "Medical Care Adviced"
                }, {
                    "name": "nextvisit datetime",
                    "label": "Next Visit Date"
                }
            ]
        },{
			"name":"cmch_ayushman",
			"saveid":"ayusv","getid":"ayugt","delid":"ayudt",
			"form":{
				"0":{"title":"Ayushman","icon":"mif-medicare","fields":"*"}
			},
			"joindef":{
				"cmch_ip":"cmch_ayushman.ipid=cmch_ip.id",
				"cmch_patient":"cmch_ip.pid=cmch_patient.pid"
			},
			"list":{
				"ayubtn":{
					"action":"Return","output":"res","outputto":"php",
					"elem":{
						"output":"#workareaFilter","parent":"div",
						"elem":[
							{"name":"ayub1","type":"button","value":"General","onclick":"Eirene.runStmt('ayugen')"},
							{"name":"ayub2","type":"button","value":"PreAuth List","onclick":"Eirene.runStmt('ayupau')"},
							{"name":"ayub3","type":"button","value":"Enhancement List","onclick":"Eirene.runStmt('ayuenh')"},
							{"name":"ayub4","type":"button","value":"PPD Query List","onclick":"Eirene.runStmt('ayuppd')"},
							{"name":"ayub5","type":"button","value":"Claim Query List","onclick":"Eirene.runStmt('ayucqr')"},
							{"name":"ayub6","type":"button","value":"Discharge List","onclick":"Eirene.runStmt('ayudis')"}
						]
					},
					"value":"",
					"onsuccess":"cmd:dom,fun:show;#workareaFilter-cmd:dom,fun:hide;#workareaFilter1"
				},
				"ayugen":{
					"output":"#workareaTablebox","getform":"cmch_ayushman 0",
					"tbl":"cmch_ayushman a","usejoin":"cmch_ip b,cmch_patient c",
					"fld":"c.pid,c.pname,a.ayushmanadmissiondate,a.preauthdate,a.lastenhancementdate,a.ayushmandischargedate",
					"includeeditdelete":true,"filter":"a.ayushmanadmissiondate,c.pid",
					"defaultwhr":"a.recordstatus=1",
					"header":"PID,Name,Ayushman Admission,Preauth,Last Enhancement,Discharge"
				},
				"ayupau":{
					"output":"#workareaTablebox",
					"tbl":"cmch_ayushman a","usejoin":"cmch_ip b,cmch_patient c",
					"fld":"c.pid,c.pname,a.ayushmanadmissiondate,a.preauthdate,a.lastenhancementdate,a.ayushmandischargedate",
					"filter":"a.ayushmanadmissiondate,c.pid",
					"defaultwhr":"a.recordstatus=1 and a.preauthdate is null",
					"header":"PID,Name,Ayushman Admission,Preauth,Last Enhancement,Discharge"
				},
				"ayuenh":{
					"output":"#workareaTablebox",
					"tbl":"cmch_ayushman a","usejoin":"cmch_ip b,cmch_patient c",
					"fld":"c.pid,c.pname,a.ayushmanadmissiondate,a.preauthdate,a.lastenhancementdate,a.ayushmandischargedate",
					"filter":"a.ayushmanadmissiondate,c.pid",
					"defaultwhr":"a.recordstatus=1 and (a.ayushmandischargedate is null or a.lastenhancementdate is null or DATE(a.ayushmanadmissiondate)!=DATE(a.lastenhancementdate))",
					"header":"PID,Name,Ayushman Admission,Preauth,Last Enhancement,Discharge"
				},
				"ayuppd":{
					"output":"#workareaTablebox",
					"tbl":"cmch_ayushman a","usejoin":"cmch_ip b,cmch_patient c",
					"fld":"c.pid,c.pname,a.ayushmanadmissiondate,a.preauthdate,a.lastenhancementdate,a.ayushmandischargedate",
					"filter":"a.ayushmanadmissiondate,c.pid",
					"defaultwhr":"a.recordstatus=1 and (a.ppdquery is not null or a.ppdquery !='')",
					"header":"PID,Name,Ayushman Admission,Preauth,Last Enhancement,Discharge"
				},
				"ayucqr":{
					"output":"#workareaTablebox",
					"tbl":"cmch_ayushman a","usejoin":"cmch_ip b,cmch_patient c",
					"fld":"c.pid,c.pname,a.ayushmanadmissiondate,a.preauthdate,a.lastenhancementdate,a.ayushmandischargedate",
					"filter":"a.ayushmanadmissiondate,c.pid",
					"defaultwhr":"a.recordstatus=1 and (a.claimquery is not null or a.claimquery !='')",
					"header":"PID,Name,Ayushman Admission,Preauth,Last Enhancement,Discharge"
				},
				"ayudis":{
					"output":"#workareaTablebox",
					"tbl":"cmch_ayushman a","usejoin":"cmch_ip b,cmch_patient c",
					"fld":"c.pid,c.pname,a.ayushmanadmissiondate,a.preauthdate,a.lastenhancementdate,a.ayushmandischargedate",
					"filter":"a.ayushmanadmissiondate,c.pid","srt":"a.ayushmandischargedate DESC",
					"defaultwhr":"a.recordstatus=1 and a.ayushmandischargedate is not null",
					"header":"PID,Name,Ayushman Admission,Preauth,Last Enhancement,Discharge"
				}
			},
			"fields":[
				{"name":"ipid varchar(36)","label":"IP ID","fieldtype":"lookup","lookup":{"sqlid":"ayulk","tbl":"cmch_ip a","whr":"a.ayushman=1 and a.didate is null and a.pid='||searchtext||'","join":"INNER JOIN cmch_patient b ON a.pid=b.pid","fld":"CONCAT(a.pid,'-',b.pname)"}},
				{"name":"ayushmanadmissiondate date","label":"Ayushman Admission Date"},
				{"name":"preauthdate date","label":"PreAuth Completed Date"},
				{"name":"ayushmandischargedate date","label":"Ayushman Discharge Date"},
				{"name":"lastenhancementdate date","label":"Last Enhancement Date"},
				{"name":"ppdquery varchar(500)","fieldtype":"textarea","label":"PPD Query"},
				{"name":"claimquery varchar(500)","fieldtype":"textarea","label":"Claim Query"},				
				{"name":"claimdate date","label":"Claim Amount"},
				{"name":"claimamount int","label":"Claim Amount"},
				{"name":"settledamount int","label":"Settled Amount"},
				{"name":"settleddate int","label":"Settled Date"}
			]
		},{
            "name": "cmch_ip",
            "saveid": "19sv",
            "getid": "19gt",
            "delid": "19dt",
			"trigger":{
				"insert":{
					"sqlstatement":{
						"a":"SELECT pid FROM cmch_ip WHERE id='||LASTINSERTID||'",
						"ipid":"SELECT id FROM cmch_ip WHERE id='||LASTINSERTID||'",
						"b":"INSERT INTO cmch_iptreatment (id,ipid,createdby) VALUES (uuid(),'||GET_ipid||','||userid||')",						
						"c":"INSERT INTO cmch_ipdischarge (id,createdby,ipid,pid) values (UUID(),'||USERID||','||GET_ipid||','||GET_a||')"
					}
				}
			},
			"joindef":{
				"cmch_wardrooms":"||thistbl||.ward=cmch_wardrooms.id",
				"cmch_doctors":"cmch_doctors.id=||thistbl||.docid",
				"cmch_patient":"cmch_patient.pid=||thistbl||.pid"				
			},
            "form": {
                "1": {
                    "title": "IP",
                    "type": "Inline",
                    "icon": "mif-dashboard",
                    "clearButton": true,
                    "cancelButton": false,
                    "fields": "pid,addate,didate,ipcase,docid,nurid,ward,bed,ayushman,isdischarged"
                }
            },
            "list": {
                "5": {
                    "action": "Get Table",
                    "getform": "cmch_ip 1",
                    "outputto": "html",
                    "output": "#workareaTablebox",
                    "tbl": "cmch_ip a",
                    "serialno": 1,"usejoin":"cmch_doctors c,cmch_patient d",					
                    "includeeditdelete": true,
                    "editablefields": "a.ayushman,a.status,a.ward",
                    "elem": {
                        "parent": "div",
                        "output": "#workareaFilter",
                        "elem": [{
                                "name": "f1",
                                "value": "IP List",
                                "type": "button",
                                "onclick": "Eirene.runStmt('5')",
                                "title": "List of Patient"
                            }, {
                                "name": "f2",
                                "value": "Room Availability",
                                "type": "button",
                                "onclick": "Eirene.runStmt('wrdmsm')",
                                "title": "Ward Details"
							}, {
                                "name": "f3",
                                "value": "Treatment Protocol",
                                "type": "button",
                                "onclick": "Eirene.runStmt('5tp')",
                                "title": "Treatment Protocol"
							}, {
                                "name": "f4",
                                "value": "Death Certificate",
                                "onclick": "Eirene.runStmt('18')",
                                "type": "button",
                                "title": "Death Certificate"
							}, {
                                "name": "f6",
                                "value": "Report",
                                "type": "button",
                                "onclick": "Eirene.runStmt('5sft-5sum',{dt:formatDate()})",
                                "title": "List Parameters"
                            }
                        ]
                    },
                    "fld": "a.pid,CONCAT(d.pname,'<br>(',DATE_FORMAT(a.addate,'%d-%m-%y'),', ',a.ipcase,')') as pn,c.name,a.ward,a.ayushman,a.status",
                    "header": "PID,Patient,Doctor,Ward,Ayushman,Status,Action",
                    "functionfield": [{
                            "type": "group",
                            "caption": "Action",
                            "grp": [ {
                                    "type": "icon",
                                    "class": "mif-search fg-blue",
                                    "title": "View Clinical Details",
                                    "onclick": "Eirene.runStmt('7cd',{pid:'<a.pid>',cdate:'<a.addate>'})"
                                }, {
                                    "type": "icon",
                                    "class": "mif-profile fg-blue mif-2x",
                                    "title": "View IP_Lifeycle",
                                    "onclick": "Eirene.runStmt('5lc',{ipid:'<a.id>'})"
                                }, {
                                    "type": "icon",
                                    "class": "mif-chart-bars mif-2x",
                                    "title": "Evaluation Chart",
                                    "onclick": "Eirene.runStmt('15pr1-5evpr',{id:'<a.id>',pid:'<a.pid>',addate:'<a.addate>'})"
                                }, {
                                    "type": "icon",
                                    "class": "mif-exit fg-blue",
                                    "title": "Add Discharge Summary",
                                    "onclick": "edit('discharge','<a.id>');Eirene.runStmt('5dfre-5dfdx',{ID1:'<a.id>'})"
                                }, {
                                    "type": "switch",
                                    "dataon": "IN",
                                    "dataoff": "OUT",
                                    "value": 1,
                                    "caption": "Admit",
                                    "onclick": "if(this.checked){Eirene.runStmt('19sv',{id:'<a.id>',didate:'||CURDATETIME||',isdischarged:1});}else{Eirene.runStmt('19sv',{id:'<a.id>',didate:'null',isdischarged:0});}"
                                }, {
                                    "type": "icon",
                                    "class": "mif-printer fg-blue",
                                    "title": "Discharge Summary",
                                    "onclick": "Eirene.runStmt('15pr1-15pr-20',{id:'<a.id>'})"
                                }, {
                                    "type": "icon",
                                    "class": "mif-file-text fg-blue",
                                    "title": "Journal",
                                    "onclick": "Eirene.runStmt('21lst',{ipid:'<a.id>',pname:'<d.pname>'})"
                                }
                            ]
                        }
                    ],
                    "srt": "a.addate DESC",
					"filter":"a.ward,a.addate,ipcase,ayushman,isdischarged",
                    "limit":150,
                    "defaultwhr": ["a.recordstatus=1",
						{"if":"||isdischarged|| = BLANK","then":" and a.isdischarged = 0","else":" and a.isdischarged = ||isdischarged||"}
					],
                    "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:hide;#workareaAppendix;slow"
                }
            },
            "fields": [
				{"name": "pid char(6) NOT NULL","label": "Patient ID"},
				{"name": "addate datetime NOT NULL","label": "Admission Date","default":{"insert":"NOW()"}},
				{"name": "didate datetime","label": "Discharge Date"},
				{"name": "ipcase","label": "Case","type": "enum('Medical','Dental','Surgical','Covid','Other')"},
				{"name": "docid char(36)","label": "Doctor","fieldtype": "select",
                    "option": "SELECT id,name FROM cmch_doctors where recordstatus=1"
                },
				{"name": "nurid char(36)","label": "Nurse"},
				{
                    "name": "ward char(36) NOT NULL DEFAULT ''",
                    "fieldtype": "select","label": "Ward",					
                    "option": "(select a.id,CONCAT(bb.ward,' - ',a.bednumber) from cmch_wardrooms a INNER JOIN cmch_ward bb ON a.wardid=bb.id where a.recordstatus=1 ORDER BY CONCAT(bb.ward,' - ',a.bednumber)) UNION ALL select '',''"
                },
				{
                    "name": "ayushman tinyint NOT NULL DEFAULT 0",
                    "fieldtype": "select","option": "0:No,1:Yes","label": "Ayushman"
                },
				{
                    "name": "status","other":"NOT NULL DEFAULT ''",
                    "type": "enum('','Sick','Very Sick','Improving','Stable','Improved','Start Discharge')",
                    "fieldtype": "select",
                    "option": ",Sick,Very Sick,Improving,Stable,Improved,Start Discharge",
                    "label": "Status"
                },
				{"name":"appid varchar(36)","label":"Appointment ID","fieldtype":"hidden",
					"saveif":[
						{"sqlstatement":{"a":"SELECT COUNT(*) FROM cmch_ip where appid='||appid||' and id !='||id||'"}},
						{"if":"||GET_a|| = 0","errormsg":"Duplicate Entry"}
					]
				},
				{"name":"isdischarged tinyint default 0","label":"Is Discharged","fieldtype":"select","option":"0:No,1:Yes"}
            ]
        }, {
            "name": "cmch_iptreatment",
            "saveid": "ipsv",
            "getid": "ipgt",
            "delid": "ipdt",
			"joindef":{
				"cmch_ip":"||thistbl||.ipid=cmch_ip.id",
				"cmch_patient":"cmch_ip.pid=cmch_patient.pid"				
			},
            "list": {
                "5tppr": {
                    "action": "Get Table",
                    "name": "Treatm Protocol Print",
                    "tbl": "cmch_iptreatment a",
                    "output": "#workareaAppendix","usejoin":"cmch_ip c,cmch_patient b",
                    "fld": "c.pid,b.pname,a.diagnosis,a.medicare,a.nursecare,a.newlabtests",                    
                    "whr": "c.recordstatus=1 and (c.didate IS NULL or c.didate < c.addate)",
                    "header": "Patient ID, Patient Name,Diagnosis,Medical Care,Nursing Care,New Lab Tests",
                    "onsuccess": "cmd:dom,fun:function;printHTML;workareaAppendix"
                },
                "5tppr2": {
                    "action": "Get Table",
                    "name": "Treatm Protocol Print(Selected)",
                    "tbl": "cmch_iptreatment a",
                    "output": "#workareaAppendix","usejoin":"cmch_ip c,cmch_patient b",
                    "fld": "c.pid,b.pname,a.diagnosis,a.medicare,a.nursecare,a.newlabtests",                   
                    "whr": "a.ipid IN (||IDS||)",
                    "header": "Patient ID, Patient Name,Diagnosis,Medical Care,Nursing Care,New Lab Tests",
                    "onsuccess": "cmd:dom,fun:function;printHTML;workareaAppendix"
                },
                "5tppr1": {
                    "action": "Get Table",
                    "name": "Treatmt Protocol Print(Each Patient)",
                    "tbl": "cmch_ip a",
                    "output": "#workareaAppendix","usejoin":"cmch_patient b",
                    "fld": "a.pid,b.pname,a.diagnosis,a.medicare,a.nursecare,a.newlabtests",                    
                    "whr": "a.id='||ID||'",
                    "header": "Patient ID, Patient Name,Diagnosis,Medical Care,Nursing Care,New Lab Tests",
                    "onsuccess": "cmd:dom,fun:function;printHTML;workareaAppendix"
                },
                "tp0": {
                    "action": "Get Row",
                    "name": "Get Treatment Protocol Time (IP) Individual",
                    "outputto": "php",
                    "output": "tptime",
                    "tbl": "cmch_ip",
                    "fld": "DATE_FORMAT(NOW(),'%H:%i') as gtime",
                    "whr": "id='||ID||'"
                },
                "tp1": {
                    "action": "Get HTML",
                    "name": "Get Treatment Protocol(IP) Individual HTML",
                    "outputto": "html",
                    "output": "#workareaAppendix",
                    "prepend": [
                        "<center><img src='resource/image/cmch_logo1.png' width='400' height='60'></center>",
                        "<DIV class='font-ArialNarrow' style='margin-top:15px'><center><h4>Treatment Protocol (IP)</h4></center></DIV>",
                        "<DIV align='right'><span class='font-ArialNarrow' style='margin-top:15px;font-size:0.9em;margin-right:2cm;width:100%;text-align:right'>Time:||CURDATE_D_M_Y||-||GET_tptime_gtime||</span></DIV>"
                    ],
                    "template": [
                        "<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;line-height:1.5;margin-top:15px;margin-left:2cm;margin-right:2cm;font-size:0.9em'>",
                        "<tr>",
                        "<th style='border:1px solid black' class='pl-2'>Patient ID - Name</th>",
                        "<th style='border:1px solid black' class='pl-2'>Medical Care</th>",
                        "<th style='border:1px solid black' class='pl-2'>Nursing Care</th>", {
                            "if": "||newlabtests|| != BLANK",
                            "then": "<th style='border:1px solid black' class='pl-2'>New Lab Tests</th>"
                        },
                        "</tr><tr><td style='text-align:center;padding:8px;border:1px solid black'>||pid||&nbsp;&nbsp;&nbsp;<b>||pname||</b><div style= 'margin-top:30%;margin-bottom:25%;'><table class='font-ArialNarrow' ><tr><th>Diagnosis<th></tr><tr><td>||diagnosis||</td></tr></table></div></td><td style='border:1px solid black;padding:8px'><b>Regular</b><br>||medicare||<div><table style='margin-top:5px'><tr><td style='padding:2px'><b>Important</b><br>||medicare1||</td></tr></table></div></td><td style='border:1px solid black;padding:8px;'>||nursecare||</td>", {
                            "if": "||newlabtests|| != BLANK",
                            "then": "<td style='border:1px solid black;padding:8px'>||newlabtests||</td>"
                        },
                        "</tr></table>",
                        "<p class='font-ArialNarrow' style='text-align:left;margin-left:2cm;margin-top:30px;font-size:0.9em'>Signature of Doctor</p>"
                    ],
                    "append": "<div  class='font-ArialNarrow' style='font-size:0.7em'><div style='position:fixed;left:10px;bottom:5px;right:10px'>Powered By CMCH App.</div><div style='position:fixed;right:10px;bottom:5px;right:10px'>Copyright@cmch2021-All Right Reserved.</div></div>",

                    "tbl": "cmch_iptreatment a","usejoin":"cmch_ip c,cmch_patient b",
                    "fld": "c.pid,b.pname,a.diagnosis,a.medicare,a.nursecare,a.newlabtests,a.medicare1",                    
                    "whr": "a.ipid='||ID||'",
                    "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast-cmd:dom,fun:function;printHTML;workareaAppendix"
                }
            },
            "fields": [
				{"name": "ipid char(36) NOT NULL"},
				{"name": "medicare varchar(2000) NOT NULL"},
				{"name": "medicare1 varchar(2000) NOT NULL"},
				{"name": "nursecare varchar(2000) NOT NULL"},
				{"name": "diagnosis varchar(1000) NOT NULL"},
				{"name": "newlabtests varchar(1000) NOT NULL"}
            ]
        }, {
            "name": "cmch_ipdischarge",
            "fields": [{
                    "name": "ipid",
                    "type": "char(36)",
                    "other": "NOT NULL"
                }, {
                    "name": "pid",
                    "type": "char(36)",
                    "other": "NOT NULL"
                }, {
                    "name": "details",
                    "type": "varchar(501)",
                    "other": "NOT NULL DEFAULT ''"
                }, {
                    "name": "cause",
                    "type": "varchar(501)",
                    "other": "NOT NULL DEFAULT ''"
                }, {
                    "name": "labreport",
                    "type": "text"
                }, {
                    "name": "dischargenotes",
                    "type": "varchar(2001)",
                    "other": "NOT NULL DEFAULT ''"
                }, {
                    "name": "advice",
                    "type": "varchar(2001)",
                    "other": "NOT NULL DEFAULT ''"
                }, {
                    "name": "issuefollowup",
                    "type": "varchar(1001)",
                    "other": "NOT NULL DEFAULT ''"
                }, {
                    "name": "nextdate",
                    "type": "datetime",
                    "other": "NOT NULL"
                }, {
                    "name": "bowelhabits",
                    "type": "varchar(500)",
                    "other": "NOT NULL"
                }, {
                    "name": "micturition",
                    "type": "varchar(500)",
                    "other": "NOT NULL"
                }, {
                    "name": "sleep",
                    "type": "varchar(500)",
                    "other": "NOT NULL"
                }, {
                    "name": "diet",
                    "type": "varchar(500)",
                    "other": "NOT NULL"
                }, {
                    "name": "calciumintake",
                    "type": "varchar(500)",
                    "other": "NOT NULL"
                }, {
                    "name": "physicalactivity",
                    "type": "varchar(500)",
                    "other": "NOT NULL"
                }, {
                    "name": "sunlightexplosure",
                    "type": "varchar(500)",
                    "other": "NOT NULL"
                }, {
                    "name": "currentmedication",
                    "type": "text",
                    "other": "NOT NULL"
                }, {
                    "name": "height",
                    "type": "float",
                    "other": "NOT NULL"
                }, {
                    "name": "weight",
                    "type": "float",
                    "other": "NOT NULL"
                }, {
                    "name": "pulse",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "bp",
                    "type": "varchar(20)",
                    "other": "NOT NULL"
                }, {
                    "name": "pallor",
                    "type": "varchar(20)",
                    "other": "NOT NULL"
                }, {
                    "name": "lymphnodes",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "goiter",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "oedema",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "skin",
                    "type": "varchar(500)",
                    "other": "NOT NULL"
                }, {
                    "name": "peripheralpulses",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "feet",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "cvs",
                    "type": "varchar(100)",
                    "other": "NOT NULL"
                }, {
                    "name": "trachea",
                    "type": "varchar(20)",
                    "other": "NOT NULL"
                }, {
                    "name": "respiratorymovements",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "percussion",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "auscultation",
                    "type": "varchar(100)",
                    "other": "NOT NULL"
                }, {
                    "name": "abdomen",
                    "type": "varchar(100)",
                    "other": "NOT NULL"
                }, {
                    "name": "fundi",
                    "type": "varchar(100)",
                    "other": "NOT NULL"
                }, {
                    "name": "cns",
                    "type": "varchar(501)",
                    "other": "NOT NULL DEFAULT ''"
                }, {
                    "name": "reflexes",
                    "type": "varchar(2001)",
                    "other": "NOT NULL DEFAULT ''"
                }, {
                    "name": "plantar",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "vibrationsense",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "chvostekssign",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "proximalweaknesss",
                    "type": "varchar(10)",
                    "other": "NOT NULL"
                }, {
                    "name": "dexareport",
                    "type": "varchar(2001)",
                    "other": "NOT NULL DEFAULT ''"
                }, {
                    "name": "distalbmd",
                    "type": "varchar(6)",
                    "other": "NOT NULL"
                }, {
                    "name": "distaltscore",
                    "type": "varchar(6)",
                    "other": "NOT NULL"
                }, {
                    "name": "distalimpression",
                    "type": "varchar(6)",
                    "other": "NOT NULL"
                }, {
                    "name": "xray",
                    "type": "text",
                    "other": "NOT NULL"
                }, {
                    "name": "ecg",
                    "type": "text",
                    "other": "NOT NULL"
                }
            ]
        }, {
            "name": "cmch_ward",
            "saveid": "wrdsv",
            "getid": "wrdgt",
            "delid": "wrddt",
            "form": {
                "0": {
                    "title": "Ward",
                    "type": "1 Column",
                    "icon": "mif-hotel",
                    "fields": "*"
                }
            },
            "list": {
                "wrdlt": {
                    "fld": "ward",
                    "includeeditdelete": true,
                    "getform": "||thistbl|| 0"
                }
            },
            "fields": [
				{"name": "ward varchar(50)","label": "Ward"}
            ]
        }, {
            "name": "cmch_wardrooms",
            "saveid": "wrdmsv",
            "getid": "wrdmgt",
            "delid": "wrdmdt",
            "form": {
                "0": {
                    "title": "Ward",
                    "type": "2 Columns",
                    "icon": "mif-dashboard",
                    "fields": "*"
                }
            },
			"joindef":{
				"cmch_ward":"||thistbl||.wardid=cmch_ward.id"				
			},
            "list": {
                "wrdmlt": {
                    "filter": "wardid",
                    "tbl": "||thistbl|| a",
                    "includeeditdelete": true,
                    "getform": "||thistbl|| 0", "usejoin":"cmch_ward b",                   
                    "fld": "b.ward,a.bednumber,a.bedside",
                    "editablefields": "a.bednumber,a.bedside",
                    "limit": "150",
                    "srt": "b.ward"
                },
                "wrdmsm": {
                    "output": "#workareaTablebox",
                    "datatable": false,
                    "header": "Ward,Room Count,Room Occupied,Available",
                    "elem": {
                        "output": "#workareaFilter1",
                        "parent": "div",
                        "elem": [{
                                "name": "wrdm1",
                                "id": "wrdm1",
                                "type": "button",
                                "onclick": "Eirene.runStmt('wrdlt')",
                                "value": "Ward"
                            }, {
                                "name": "wrdm2",
                                "id": "wrdm2",
                                "type": "button",
                                "onclick": "Eirene.runStmt('wrdmlt')",
                                "value": "Ward & Room"
                            }, {
                                "name": "wrdm3",
                                "id": "wrdm3",
                                "type": "button",
                                "onclick": "Eirene.runStmt('wrdmsm')",
                                "value": "Room Availability"
                            }
                        ]
                    },
                    "stmt": [
                        "SELECT ward,sum(rooms),sum(occupied),sum(rooms)-sum(occupied) as available FROM",
                        "(SELECT b.ward as ward,count(*) as rooms,'' as occupied FROM cmch_wardrooms a INNER JOIN cmch_ward b ON a.wardid=b.id GROUP BY b.ward",
                        "UNION ALL",
                        "SELECT cc.ward,'',count(*) FROM cmch_ip aa INNER JOIN cmch_wardrooms bb ON aa.ward=bb.id INNER JOIN cmch_ward cc ON bb.wardid=cc.id where (aa.didate is null or aa.didate ='0000-00-00 00:00:00') and aa.recordstatus=1 GROUP BY cc.ward",
                        "UNION ALL",
                        "SELECT 'ZTotal',count(*),(SELECT count(*) FROM cmch_ip where (didate is null or didate ='0000-00-00 00:00:00') and recordstatus=1) FROM cmch_wardrooms",
                        ") as sm",
                        "group by ward order by ward"
                    ],
                    "onsuccess": "cmd:dom,fun:show;#workareaFilter1"
                }
            },
            "fields": [{
                    "name": "wardid char(36) NOT NULL",
                    "fieldtype": "select",
                    "option": "SELECT id,ward FROM cmch_ward",
                    "label": "Ward"
                }, {
                    "name": "bednumber tinyint",
                    "label": "Bed No"
                }, {
                    "name": "bedside enum('Left','Right')",
                    "fieldtype": "select",
                    "option": ",Left,Right",
                    "label": "Bed Side"
                }
            ]
        }, {
            "name": "cmch_clinicaldetails",
			"saveid":"7savcd","getid":"7gtcd","delid":"7delcd",
            "form":{
				"0": {
                    "title": "Clinical Details","icon": "mif-medkit",
                    "type": "Inline","fields": "*"
                }
			},
			"list":{
				"7flt":{
					"action": "Return",
					"output": "#workareaFilter1",
					"value": "<div class='d-flex flex-justify-around'>Patient ID<input type='text' id='fpid'></input>Date From<input type='date' id='attfromdate'></input>Date To<input type='date' id='atttodate'></input><button type='button' onclick='let df=$(&apos;#attfromdate&apos;).val();let dt=$(&apos;#atttodate&apos;).val();Eirene.runStmt(&apos;7&apos;,{pid:$(&apos;#fpid&apos;).val(),attfromdate:df,atttodate:dt})' >Get</button></div>",
					"onsuccess": "cmd:dom,fun:show;#workareaFilter1;slow"
				},
				"7cd":{					
					"getform": "||this|| 0",
					"outputto": "html",
					"output": "app",
					"tbl": "cmch_clinicaldetails",
					"fld": "pid,cdate,bp,pulse,temperature,spo2,sugar,ecg",
					"includeeditdelete":true,
					"header": "PatientID,Date,BP,Pulse,Temperature,spo2,Sugar,ECG",					
					"srt": "createdon DESC",					
					"onsuccess": "cmd:dom,fun:show;#workareaAppendix;slow-cmd:dom,fun:html;#workareaAppendix;||app||"
				}				
			},
			"fields": [
				{"name": "pid char(36) NOT NULL","label":"Patient ID"},
				{"name": "cdate datetime","required": 1}, 
				{"name": "bp varchar(10)","label": "BP"},
				{"name": "pulse varchar(10)","label":"Pulse"},
				{"name": "temperature varchar(10)","label":"Temperature"},
				{"name": "spo2 varchar(10) NOT NULL","label":"SPo2"},
				{"name": "sugar varchar(10) NOT NULL","label":"Sugar"},
				{"name": "ecg varchar(30) NOT NULL","label":"ECG"}
            ]
        }, {
            "name": "cmch_bill",
			"saveid":"8sv","getid":"8gt","delpermanentid":"8dt",
			"form":{
				"0": {
                    "title": "Bill Item","icon": "mif-medkit",
                    "type": "3 Columns","fields": "pid,item,quatity"
                }
			},
			"joindef":{
				"cmch_printbill":"cmch_printbill.billno=cmch_bill.billno",
				"cmch_patient":"cmch_patient.pid=cmch_bill.pid"
			},
			"list":{
				"8lt":{
					"tbl":"||thistbl||","getform":"||thistbl|| 0",
					"fld":"pid,item,quatity,rate,total",
					"defaultwhr":"billno is NULL"
				},
				"8lt1":{
					"tbl":"||thistbl|| a","filter":"a.category,b.department,a.createdon","usejoin":"cmch_patient b,cmch_printbill c",
					"fld":"DATE_format(c.createdon,'%d-%m-%Y')as BillDate,a.pid,b.pname,a.billno,a.item,a.quatity,a.rate,a.total",
					"defaultwhr":"a.billno is NOT NULL and a.recordstatus = 1",
					"header":"Date,PID,Name,Bill No,Item,Quantity,Rate,Amount"
				},
				"bitem":{
					"action":"Get Table",
					"tbl": "cmch_bill",
					"fld": "item,rate,quatity,(rate*quatity) as amount,discount,total",					
					"header":"Item,Rate,Quantity,Amount,Discount,Total",
					"whr":"recordstatus=1 and billno='||billno||'",
					"vsum":"6"
				},
				"10tb":{            
					"action": "Get Table",
					"name": "Total Bill","datatable":false,
					"class":"dataTable",
					"output": "#workareaTablebox",										
					"tbl": "cmch_bill a","getform":"cmch_bill 0",
					"fld": "CONCAT('<input type=checkbox data-role=check name=fldchk value=',a.total,' id=',a.id,' onclick=billsum() />') as chk,a.item,a.bdate,a.quatity,a.total",
					"header": [
						"<input type=checkbox data-role=check name=chk id=fld onclick='checkAllBill($(this))' />",
						"Item", "Date", "Quantity", "Amount", "Action"
					],
					"union": "UNION ALL SELECT '','','','',concat('<b>',(SELECT sum(total) FROM cmch_bill WHERE recordstatus=1 and billno is null and pid='||pid||'),'</b>'),''",
					"includeeditdelete":true,					
					"whr": "a.recordstatus=1 and a.billno is null and a.pid='||pid||'",
					"onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:show;#workareaAppendix;slow-cmd:dom,fun:html;#workareaAppendix;BLANK",
					"append":[
						"<script>",
						"function billsum(){",
							"let sum=0;",
							"$('input[type=checkbox][name=fldchk]:checked').each(function(){",
								"sum+=parseInt($(this).attr('value'));});",
								"showToast('Total: '+sum,'warning',5000);",
						"}",
						"function checkAllBill(elem){",
							"let status=elem.prop('checked');",
							"if(status){",
								"$('input[type=checkbox][name=fldchk]').prop('checked',true);",
							"}else{",
								"$('input[type=checkbox][name=fldchk]').prop('checked',false);",
							"}",
							"billsum();",
						"}",
						"</script>"
					]
				}
			},
            "fields": [
				{"name": "bdate datetime NOT NULL","label":"Bill Date","fieldtype":"hidden","default":{"insert":"NOW()"}},
				{"name": "pid char(36) NOT NULL","label":"Patient ID","fieldtype":"lookup","lookup":{"sqlid":"cblk1","tbl":"cmch_patient","fld":"pid,CONCAT(pname,' - ',pid) as pname","whr":"pid = '||searchtext||' or pname like '%||searchtext||%'"}},
				{"name": "doctorid char(36)","label":"Doctor"},
				{"name": "billno int","label":"Bill No"},
				{"name": "item varchar(50) NOT NULL","label":"Item","fieldtype":"lookup","lookup":{"sqlid":"cblk2","tbl":"cmch_item","fld":"item,concat(item,' : ',rate)","whr":"recordstatus=1 and item like '%||searchtext||%'","srt":"item"}},
				{"name": "category varchar(20) NOT NULL","label":"Category","fieldtype":"select","option":"SELECT distinct category FROM cmch_item","default":"SELECT category FROM cmch_item where item='||item||'"}, 
				{"name": "rate float NOT NULL","label":"Rate","fieldtype":"hidden","default":"SELECT rate FROM cmch_bill WHERE item='||item||'"},
				{"name": "quatity float NOT NULL","label":"Quantity","required":1},
				{"name": "discount float NOT NULL","label":"Discount"},
				{"name": "total float GENERATED ALWAYS AS (quatity * rate) STORED","label":"Total"}
            ]
        }, {
            "name": "cmch_item",
			"saveid": "9svit",
            "getid": "9gtit","delid":"9delit",
			"form":{
				"0": {
                    "title": "Item","icon": "mif-medkit",
                    "type": "Inline","fields": "*"
                }
			},
			"list":{
				"9":{
					"action": "Get Table",
					"name": "Item List","filter":"item,category",
					"getform":"||thistbl|| 0",					
					"tbl": "cmch_item",
					"fld": "item,rate,category",
					"includeeditdelete":true,
					"header": "Item,Rate,Category"			
				}
			},
            "fields": [
				{"name": "item varchar(50) NOT NULL UNIQUE","required":1,"label":"Item"},
				{"name": "rate float NOT NULL","required":1,"label":"Rate"},
				{"name": "category varchar(20) NOT NULL","required":1,"label":"Category","fieldtype":"select","option":"SELECT distinct(category) FROM cmch_item where recordstatus=1 order by category"}
            ]
        },
		{
            "name": "cmch_printbill",
			"saveid":"pbsv",
			"joindef":{
				"cmch_patient":"cmch_patient.pid=cmch_printbill.pid",
				"cmch_bill":"cmch_bill.billno=cmch_printbill.billno"				
			},
			"list":{
				"10brec":{				
					"name": "Bill Records",				
					"action": "Get Table",					
					"output": "#workareaTablebox",
					"filter":[
						"a.createdon,a.pid,a.department",
						{"name":"breccategory","label":"Category","fieldtype":"select","option":"SELECT DISTINCT category FROM cmch_item order by category"}
					],
					"tbl": "cmch_printbill a",
					"usejoin":"cmch_patient c",
					"fld": "a.pid,c.pname,a.billno,a.createdon,b.billamount",
					"join": [
						"INNER JOIN (SELECT billno,SUM(total) as billamount FROM cmch_bill WHERE recordstatus=1 ",
						{"if":"||breccategory|| != BLANK","then":" and category='||breccategory||'"},
						"group by billno) b ON a.billno=b.billno"						
					],					
					"functionfield": [{
							"name": "f1",
							"type": "button",
							"class": "mif-printer fg-blue",
							"onclick": "Eirene.runStmt('10prbl',{billno:'<a.billno>',pid:'<c.pid>'})",
							"caption": "Print"
						}
					],					
					"defaultwhr":[
						"a.recordstatus=1",						
						{"if":"||cmch_printbillconfromdate|| = BLANK","then":" and DATE(a.createdon)=CURDATE()"}
						
					],					
					"srt": "a.billno DESC",
					"grp":"a.pid,c.pname,a.billno,a.createdon",
					"vsum": "5,6",					
					"header": "Patient ID,Patient Name,BIll NO,Date,Total Bill,",
					"onsuccess": "cmd:dom,fun:hide;#workareaAppendix;slow"				
				},
				"10pndg":{				
					"name": "Pending Bill Records",				
					"action": "Get Table",					
					"output": "#workareaTablebox",
					"filter":[
						"a.createdon,a.pid,a.department,b.category",
						{"name":"brecpending","id":"brecpending","fieldtype":"select","option":"Pending","label":"Is Pending"}
					],
					"tbl": "cmch_printbill a",
					"usejoin":"cmch_patient c",
					"fld": "a.pid,c.pname,a.billno,DATE_FORMAT(a.createdon,'%d-%m-%Y'),IF(b.billamount!=d.paidamount or d.paidamount is null,CONCAT('<span class=fg-red >',b.billamount,'</span>'),b.billamount) as billamt,IF(d.paidamount is null,0,d.paidamount) as paid",
					"join": [
						"INNER JOIN (SELECT billno,SUM(total) as billamount FROM cmch_bill WHERE recordstatus=1 group by billno) b ON a.billno=b.billno",
						"LEFT JOIN (select billno,SUM(amount) as paidamount FROM cmch_payment where recordstatus=1 GROUP BY billno) d ON d.billno=a.billno"
					],					
					"functionfield": [{
							"name": "f1",
							"type": "button",
							"class": "mif-printer fg-blue",
							"onclick": "Eirene.runStmt('10prbl',{billno:'<a.billno>',pid:'<c.pid>'})",
							"caption": "Print"
						}
					],										
					"defaultwhr":[
						"a.recordstatus=1",
						{"if":"||brecpending|| != BLANK","then":" and (b.billamount!=d.paidamount or d.paidamount is null)"},
						{"if":"||cmch_printbillconfromdate|| = BLANK","then":" and DATE(a.createdon)=CURDATE()"}
					],					
					"srt": "a.billno DESC",
					"grp":"a.pid,c.pname,a.billno,a.createdon",
					"vsum": "5,6",					
					"header": "Patient ID,Patient Name,BIll NO,Bill Date,Total Bill,Total Paid,",
					"onsuccess": "cmd:dom,fun:hide;#workareaAppendix;slow"				
				},
				"pbinfo":{					                            
					"action": "Return",
					"outputto": "html",
					"output": "#printbill_2",
					"name":"Patient and Bill Info",
					"value": [
						"<center><img src='resource/image/cmch_logo1.png' width='500' height='70'>",
						"<div>Bill No. :||billno||</div></center>",
						"<center>",
						"<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:auto;margin-right:auto;font-size:0.7em'>",
						"<tr><td style='border:1px solid black' class='p-1'><b>Patient ID</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pid||</td><td style='border:1px solid black' class='p-1'><b>Name</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||patient_pname||</td></tr>",
						"<tr><td style='border:1px solid black' class='p-1'><b>Date</b></td><td style='border:1px solid black' class='p-1'>||bill_billdate||</td><td style='border:1px solid black' class='p-1'><b>Mobile No.</b></td><td style='border:1px solid black' class='p-1'>||patient_pmobile||</td></tr>",
						"<tr><td style='border:1px solid black' class='p-1'><b>Case Type</b></td><td style='border:1px solid black' class='p-1'>||appointment_pcase||</td><td style='border:1px solid black' class='p-1'><b>Doctor</b></td><td style='border:1px solid black' class='p-1'>||appointment_name||</td></tr>",
						"<tr><td style='border:1px solid black' class='p-1'><b>Department</b></td><td style='border:1px solid black' class='p-1'>||bill_department||</td><td style='border:1px solid black' class='p-1'></td><td style='border:1px solid black' class='p-1'></td></tr>",
						"</table></center>"
					],
					"onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast"
				},
				"pddtls":{
					"action": "Get Table",					
					"appendoutput": 1,"datatable":false,
					"vsum":"3","displayfunctionbutton":false,
					"class":"font-ArialNarrow .eirene-table-thleftaligh",
					"style":"margin-left: auto;margin-right:auto;width:80%;font-size:0.7em",                
					"tbl": "cmch_payment",
					"fld": "DATE_FORMAT(createdon,'%d-%m-%Y'),paymentmethod,amount",
					"header":"Date,Mode,Amount",                
					"whr": "recordstatus=1 and billno='||billno||'"					
				}				
        
			},
            "fields": [
				{"name": "billno int","label":"Bill No"},
				{"name": "paystatus varchar(20)","label":"Payment Status"},
				{"name": "pid char(36) NOT NULL","label":"Patient ID"},
				{"name": "appid char(36) NOT NULL","label":"Appointment ID"},
				{"name": "department varchar(50) NOT NULL",
					"label":"Department (Pending Bills)",
					"fieldtype": "select",
                    "option": "Get Array CMCH Department (Bills)"
				}
			]
        }, {
            "name": "cmch_xray",
			"joindef":{
				"cmch_printbill":"||thistbl||.billno=cmch_printbill.billno",
				"cmch_patient":"cmch_printbill.pid=cmch_patient.pid"				
			},
			"list":{
				"11":{				
					"action": "Get Table",
					"name": "Xray Details","getchart":"11crt1,11crt2",				
					"output": "table",
					"elem": {
						"parent": "div",
						"output": "#workareaFilter",
						"elem": [{
								"name": "f2",
								"value": "Report",
								"type": "button",
								"onclick": "Eirene.runStmt('11sum-11sft',{dt:formatDate()})",
								"title": "List Parameters"
							}
						]
					},
					"tbl": "cmch_xray a",
					"fld": "b.pid,c.pname,a.billno,a.item",                
					"usejoin":"cmch_printbill b,cmch_patient c",
					"header": "Patient ID,Patient Name,Bill No,Item",					
					"srt": "a.billno DESC",
					"defaultwhr":"a.recordstatus=1 and DATE(a.createdon)=CURDATE()",
					"filter":"a.billno,b.pid,a.createdon"
				},
				"11crt1":{					
					"name":"Daily Report",
					"action":"Get Chart New",
					"tbl": "cmch_xray","filter":"createdon",
					"fld": "DATE_FORMAT(createdon,'%d') as adate,count(*) as cnt",									
					"srt": "adate",
					"grp":"adate",
					"title":"XRay Daily Report",
					"label":"adate",					
					"value":"cnt",
					"type":"bar"
				},"11crt2":{					
					"name":"Monthly Report",
					"action":"Get Chart New",
					"tbl": "cmch_xray","filter":"createdon",
					"fld": "DATE_FORMAT(createdon,'%M') as adate,count(*) as cnt",									
					"srt": "createdon",
					"grp":"adate",
					"title":"XRay Monthly Report",
					"label":"adate",					
					"value":"cnt",
					"type":"bar"
				}
			},
            "fields": [
				{"name": "billno int","label":"Bill No"},
				{"name": "item varchar(50)","label":"Item"},
				{"name": "billitemid char(36)","label":"Bill Item ID"},
				{"name": "xray varchar(400)","label":"XRay"}
            ]
        }, {
            "name": "cmch_xrayimage",
            "fields": [{
                    "name": "xrayid",
                    "type": "char(36)",
                    "other": "NOT NULL"
                }, {
                    "name": "image",
                    "type": "varchar(400)"
                }
            ]
        }, {
            "name": "cmch_lab",
            "saveid": "labsv",
            "getid": "labgt",
            "delid": "labdt",
			"joindef":{
				"cmch_printbill":"||thistbl||.billno= cmch_printbill.billno",
				"cmch_patient":"cmch_printbill.pid=cmch_patient.pid"
			},
			"list":{
				"12":{
					"action": "Get Table",
					"name": "Lab Details",					
					"outputto": "html",
					"output": "#workareaTablebox",
					"elem": {
						"parent": "div",
						"output": "#workareaFilter",
						"elem": [ {
								"name": "f3",
								"type": "button",
								"value": "List Parameters",
								"onclick": "Eirene.runStmt('labplt')",
								"title": "List Parameters"
							}, {
								"name": "f4",
								"value": "Evaluation Chart",
								"type": "button",
								"onclick": "Eirene.runStmt('12flt')",
								"title": "List Parameters"
							}, {
								"name": "f5",
								"value": "Lab Report",
								"type": "button",
								"onclick": "Eirene.runStmt('12sum-12sft',{dt:formatDate()})",
								"title": "List Parameters"
							}, {
								"name": "f6",
								"value": "Other",
								"type": "button",
								"onclick": "Eirene.runStmt('8lt1')",
								"title": "List Parameters"
							}

						]
					},
					"tbl": "cmch_lab a","filter":"a.billno,a.item,b.pid,a.createdon",
					"prepend": "<div><button type='button' onclick='let chk=true;let ids=[];let pid=$(&apos;#workareaTablebox input[type=checkbox]:checked&apos;).attr(&apos;pid&apos;);$(&apos;#workareaTablebox input[type=checkbox]:checked&apos;).each(function(i,x){if($(this).attr(&apos;pid&apos;)!=pid){showToast(&apos;Cannot select multiple patients.&apos;,&apos;alert&apos;,5000);chk=false}else{ids.push($(this).attr(&apos;id&apos;));}});if(!chk) return false;$(&apos;#workareaAppendix&apos;).html(&apos;<div><div id=&quot;header&quot;></div><div id=&quot;labresult&quot;></div><div id=&quot;labresult1&quot;></div><div id=&quot;sign&quot;></div></div>&apos;);Eirene.runStmt(&apos;12lpr&apos;,{ids:ids.join(&apos;,&apos;)});'>Print</button></div>",
					"fld": [
						"CONCAT('<input type=checkbox data-role=check name=fldchk id=',a.id,' pid=',b.pid,' />') as chk",
						"b.pid,d.pname,a.billno,a.item"
					],
					"functionfield": [{
							"if":"a.collectiontime is null",
							"name": "ct",
							"type": "button",
							"title": "Add Collection Time",                        
							"value": "",
							"class": "mif-lab fg-blue mr-3 lab-function",
							"onclick": "Eirene.runStmt('labsv',{id:'<a.id>',collectiontime:'NOW()'});$(this).hide();$(this).parent().find('.lab-function[name=ap]').removeClass('no-visible')",
							"caption": "Collection Time"

						}, {
							"name": "ap",
							"type": "button",
							"otherattr": "status",
							"otherattrvalue": "<a.status>",
							"value": "",
							"title": "Add Parameters",
							"class": "mif-plus fg-blue mr-3 lab-function",
							"onclick": "Eirene.runStmt('12st1-12gp',{pid:'<b.pid>',billno:'<a.billno>',item:'<a.item>',id:'<a.id>',billitemid:'<a.billitemid>'});$(this).hide();$(this).parent().find('.lab-function[name=ep],.lab-function[name=pp]').removeClass('no-visible');",
							"caption": "Parameter"
						}, {
							"name": "ep",
							"type": "button",
							"otherattr": "status",
							"otherattrvalue": "<a.status>",
							"value": "",
							"title": "Add or edit Value",
							"class": "mif-pencil fg-blue mr-3 lab-function",
							"onclick": "Eirene.runStmt('12aval',{id:'<a.id>'})",
							"caption": "Edit Parameter"
						},{
							"name": "pp",
							"type": "button",
							"value": "",
							"class": "mif-printer fg-blue lab-function",
							"otherattr": "status",
							"otherattrvalue": "<a.status>",
							"title": "Patinet Report",
							"onclick": "Eirene.runStmt('12st1-12rt-12pr',{id:'<a.id>',billno:'<a.billno>',item:'<a.item>',comment:'<a.comment>',reportingtime:'NOW()'})",
							"caption": "Print"
						}
					],
					"usejoin":"cmch_printbill b,cmch_patient d",					
					"header": ",Patient ID,Patient Name,Bill No,Item",
					"defaultwhr":"a.recordstatus=1","limit":"1000",
					"srt": "a.createdon DESC",               
					"onsuccess": "cmd:dom,fun:show;#workareaTablebox-cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:empty;#workareaAppendix;slow"
				}
				
			},
            "fields": [
				{"name": "billno int"},
				{"name": "item varchar(50)"},
				{"name": "billitemid char(36)"},
				{"name": "status tinyint NOT NULL"},
				{"name": "collectiontime datetime"},
				{"name": "reportingtime datetime"},
				{"name": "comment varchar(50) NOT NULL DEFAULT ''"}
            ]
        }, {
            "name": "cmch_labresult",
			"joindef":{
				"cmch_labparameters":"cmch_labparameters.id=cmch_labresult.parameterid"				 
			},
            "list": {
                "12aval": {
                    "outputto": "html",
                    "output": "#workareaAppendix",
                    "tbl": "||thistbl|| b",
					"prerun":[
						{"sqlstatement":{"labcomment":"SELECT comment FROM cmch_lab WHERE id='||id||'"}}
					],
                    "functionfield": [{
                            "type": "group",
                            "grp": [{
                                    "if": "a.options=''",
                                    "type": "text",
                                    "value": "<result>",
                                    "onblur": "Eirene.runStmt('12sval',{ID:'<b.id>',value:$(this).val()})"
                                }, {
                                    "if": "a.options!=''",
                                    "type": "select",
                                    "value": "<result>",
                                    "values": "<a.options>",
                                    "onchange": "Eirene.runStmt('12sval',{ID:'<b.id>',value:$(this).val()})"
                                }
                            ],
                            "caption": "LabValue"
                        }, {
                            "type": "icon",
                            "class": "mif-cross fg-red",
                            "onclick": "Eirene.currentelem=$(this).parent().parent();Eirene.runStmt('12sdel',{ID:'<b.id>',confirmBeforeProcess:'Do you want to Delete this record?'})",
                            "caption": "DeleteRow"
                        }
                    ],
                    "convertSelect": "2",
                    "append": "<div class='d-flex flex-justify-around'>Comment:<input type='text' value='||labcomment||' onblur='Eirene.runStmt(&apos;labsv&apos;,{ID:&apos;||id||&apos;,comment:$(this).val()})'/></div>",
                    "fld": "a.parametername",
                    "header": "Parameter Name",
                    "usejoin": "cmch_labparameters a",
                    "srt": "a.porder",
                    "whr": "a.recordstatus=1 and b.labid='||id||'",
                    "onsuccess": "cmd:dom,fun:show;#workareaAppendix;slow-cmd:dom,fun:function;convertSelect;#workareaAppendix;"
                }
            },
            "fields": [
				{"name": "pid char(36)"},
				{"name": "labid char(36)"},
				{"name": "parameterid char(36)"},
				{"name": "result varchar(20)"},
				{"name": "date datetime"}
            ]
        }, {
            "name": "cmch_labparameters",
			"saveid":"labpsv","getid":"labpgt","delid":"labpdt",
			"form":{
				"0": {
                    "title": "Lab Parameter","icon": "mif-medkit",
                    "type": "Inline","fields": "*"
                }
			},
			"list":{
				"labplt":{
					"tbl":"||thistbl||","fld":"parametername,porder,unit,lrange",
					"editablefields":"porder","filter":"itemid",
					"srt":"porder","getform":"||thistbl|| 1",
					"includeeditdelete":true
				}
			},
            "fields": [
				{"name": "parametername varchar(30)","label":"Parameter"},
				{"name": "lrange varchar(30)","label":"Range"},
				{"name": "unit varchar(20)","label":"Unit"},
				{"name": "itemid char(36)","label":"Item","fieldtype":"lookup","lookup":{"sqlid":"labplk","tbl":"cmch_item","fld":"item","whr":"recordstatus=1 and category like '%Lab%' and item like '%||searchtext||%'"}},
				{"name": "porder int","label":"Print Order"},
				{"name": "options varchar(30) NOT NULL","label":"Option (comma seperated)"},
				{"name": "prefil varchar(20)","label":"Prefill"},
				{"name": "lowerrange float","label":"Lower Range"},
				{"name": "upperrange float","label":"Upper Range"},
				{"name": "strcomparision varchar(20)","label":"String Comparision"},
				{"name": "referencerange varchar(300)","label":"Reference Range"}
            ]
        }, {
            "name": "cmch_advance",
            "saveid": "13sv",
			"joindef":{
				"cmch_patient":"||thistbl||.pid=cmch_patient.pid"				
			},
            "form": {
                "0": {
                    "title": "Advance","icon": "mif-medkit",
                    "type": "Horizontal","fields": "pid,paymentmethod,advance,balance"
                }
            },
            "list": {
                "13": {
                    "name": "Advance List",
                    "outputto": "html", "output": "#workareaTablebox",
                    "filter": "pid,createdon","getform": "||thistbl|| 0",
                    "includeeditdelete": true,
                    "tbl": "cmch_advance a",
                    "fld": "a.advanceid,a.pid,b.pname,a.paymentmethod,a.advance,a.balance,a.createdon",
                    "functionfield": [{
                            "name": "ad",
                            "type": "button",
                            "class": "mif-printer fg-blue",
                            "caption": "prt",
                            "onclick": "Eirene.runStmt('13ap-13a',{ID:'<a.id>',pid:'<a.pid>',advid:'<a.advanceid>'})"
                        }
                    ],
					"srt":"a.createdon DESC",
                    "vsum": "5,6",
                    "usejoin": "cmch_patient b",
                    "header": "Advance ID,Patient ID, Patient Name,Payment Mode,Amount,Balance,Date&Time"
                }
            },
            "fields": [
				{
                    "name": "pid char(36)","required": true,
                    "label": "Patient",
                    "fieldtype": "lookup",
                    "lookup": {
                        "sqlid": "13lkup","tbl": "cmch_patient",
                        "fld": "pid,pname","whr": "pid='||searchtext||'"
                    }
                },
				{"name": "advanceid int AUTO_INCREMENT","label": "Advance ID"},
				{"name": "advance float","label": "Amount",
                    "onblur": "$('input[name=cmch_advance5]').val($(this).val())"                    
                },
				{"name": "paymentmethod varchar(30)","fieldtype": "select",
                    "option": "Cash,Card,POS,InternetBanking,UPI,Cheque",
                    "label": "Payment Method"
                },
				{"name": "balance float","fieldtype": "hidden"}
            ]
        }, {
            "name": "cmch_refund",
			"saveid":"rfsv","getid":"rfgt","delid":"rfdt",
			"joindef":{
				"cmch_patient":"||thistbl||.pid=cmch_patient.pid"				
			},
			"trigger":{
				"insert":{"sqlstatement":{"runif":"||refundfrom|| != Cash","a":"UPDATE cmch_advance set balance=balance-||refund|| where id='||refundfrom||'"}}
			},
			"form":{
				"0":{"type":"Inline","title":"Refund","icon":"mif-delicious","fields":"pid,refundfrom,refund,remark"}
			},
            "list": {
                "14": {
                    "name": "Refund Details","includeeditdelete":true,"getform":"||thistbl|| 0",
                    "outputto": "html","output": "table","vsum": "6",
                    "tbl": "cmch_refund a","filter": "pid,createdon",
                    "fld": " DATE_FORMAT(a.createdon,'%d-%m-%Y') as createdon,rfnum,a.pid,b.pname,a.refund,a.remark",
                    "functionfield": [{
                            "type": "icon","class": "mif-printer fg-blue",
                            "caption": "Print","title": "Print Refund",
                            "onclick": "Eirene.runStmt(&apos;14rg-14a&apos;,{rfnum:'<a.rfnum>',id:'<a.id>',date:'<a.createdon>'})"
                        }
                    ],
                    "usejoin": "cmch_patient b",
                    "header": "Date,Refund No.,Patient ID, Name,Amount,Remark",
                    "srt": "a.createdon DESC",
					"elem": {
						"parent": "div",
						"output": "#workareaFilter1",
						"elem": [{
								"name": "f1",
								"id": "14ftpid",
								"type": "button",
								"value": "Refund Form",
								"onclick": "showNewForm('refund');"
							}
						]
					},
					"onsuccess":"cmd:dom,fun:show;#workareaFilter1"
                },
                "14a": {
                    "action": "Get HTML",
                    "name": "Get refund details - HTML",
                    "outputto": "html",
                    "output": "#workareaAppendix",
                    "appendoutput": 1,
                    "tbl": "cmch_refund",
                    "fld": "'||GET_refundtbl_remark||' as remark,refund",
                    "union": "SELECT '<b>Grand Total<b>',CONCAT('<div id=14rftotal >',sum(refund),'</div>') FROM cmch_refund WHERE recordstatus=1 and rfnum='||rfnum||'",
                    "parent": "TABLE class='font-ArialNarrow' style='margin-left: auto;margin-right:auto;margin-top:0.5cm;font-size:0.7em;width:80%;'><thead><tr><TH style='text-align:left;'>Reamrk</TH><TH style='text-align:left;'>Amount</TH></TR",
                    "template": "<TR><TD style='text-align:left;'> ||remark||</TD><TD style='text-align:left;'> ||refund||</TD></TR>",
                    "whr": "recordstatus=1 and rfnum='||rfnum||'",
                    "append": [
                        "<div class='font-ArialNarrow' style='text-align:left;font-size:0.7em'>",
                        "<span><b>Figure: </b></span>",
                        "<span id='14rftotfigure'></span>",
                        "</div>",
                        "<script>$('#14rftotfigure').html(ConvertNumberToWords($('#14rftotal').text()));</script>",
                        "<div class='row mt-4 font-ArialNarrow' style='font-size:0.7em;'><div class='cell font-ArialNarrow'>Prepared by</div><div class='cell font-ArialNarrow'>Checked By</div></div>"
                    ],
                    "onsuccess": "cmd:dom,fun:function;printHTML;workareaAppendix"
                }
            },
            "fields": [
				{
                    "name": "pid char(36)","label": "Patient","required":1,"fieldtype": "lookup",
                    "lookup": {
                        "sqlid": "14lkup","tbl": "cmch_patient",
                        "fld": "pid,pname","whr": "pid='||searchtext||' or pname like '%||searchtext||%'"
                    }
                },
				{"name":"refundfrom char(36)","fieldtype":"lookup","lookup":{"sqlid":"14rlkp","tbl":"cmch_advance","fld":"id,CONCAT('Balance: ',balance) as balance","whr":"pid='||searchtext||' and balance>0","union":"union all select 'Cash','Cash'","searchelemid":"||pid_alias||"},"label":"Refund From","required":1,
					"saveif":[						
						{"sqlstatement":{							
							"advbal":"SELECT sum(balance) FROM cmch_advance WHERE id='||thisvalue||'"							
							}
						}							
					]
				},								
				{"name": "refund","type": "float","label": "Refund Amount","required":1,
					"saveif":[
						{"if":"||refundfrom|| = Cash or ||advbal|| >= ||thisvalue||","errormsg":"Insufficient Advance Balance"}
					]
				},
				{"name": "remark","type": "varchar(100)","label": "Remark","required":1},
				{"name": "rfnum int","label": "Refund No","default":"SELECT MAX(rfnum)+1 FROM cmch_refund"}
            ]
        }, {
            "name": "cmch_iplifecycle",
            "fields": [
				{"name": "ipid char(36) NOT NULL"},
				{"name": "lcname varchar(50) NOT NULL"},
				{"name": "details varchar(50)"}
            ]
        }, {
            "name": "cmch_ipcategory",
            "saveid": "svcat",
            "getid": "gtcat",
            "delid": "5catd",
            "fields": [
				{"name": "pid char(36) NOT NULL","label": "Patient ID"},
				{"name": "ipid char(36) NOT NULL","label": "IP ID"},
				{"name": "ward char(36) NOT NULL","label": "Ward"},
				{"name": "bed char(36) NOT NULL","label": "Bed"},
				{"name": "indate datetime","label": "Date - IN"},
				{"name": "outdate datetime","label": "Date - OUT"}
            ]
        }, {
            "name": "cmch_payment",
			"saveid":"paysv","delid":"paydt","getid":"paygt",
			"joindef":{
				"cmch_printbill":"||thistbl||.billno=cmch_printbill.billno",
				"cmch_patient":"cmch_printbill.pid=cmch_patient.pid"				
			},
			"trigger":{
				"insert":[
					{"if":"||advanceid|| != BLANK","then":[
						{"sqlstatement":"UPDATE cmch_advance SET balance= balance - ||amount|| WHERE id='||advanceid||'"}
					]}				
				]
			},
			"form":{
				"0":{"type":"Inline","title":"Payment","icon":"mif-delicious","fields":["paymentmethod,amount",{"name":"billno","fieldtype":"hidden","value":"||billno||"}],"datacollapsed":false},
				"1":{"type":"Inline","title":"Payment from Advance","icon":"mif-delicious",
					"fields":[
						"paymentmethod,amount",
						{"name":"billno","fieldtype":"hidden","value":"||billno||"},
						{"name":"advanceid","fieldtype":"select","option":"SELECT id,CONCAT('Balance: ',balance) as balance FROM cmch_advance WHERE pid='||pid||' and balance>0","required":true}
					],"datacollapsed":true
				}
			},
			"list":{				
				"10ph":{					
					"action": "Get Table",
					"name": "Payment Details",
					"outputto": "html",
					"output": "table",
					"tbl": "cmch_payment a",
					"usejoin":"cmch_printbill b,cmch_patient c",
					"fld": "DATE_FORMAT(a.createdon,'%d-%m-%Y'),a.billno,DATE_FORMAT(b.createdon,'%d-%m-%Y'),c.pid,c.pname,a.paymentmethod,a.amount",
					"functionfield": [{
							"name": "f1",
							"type": "button",
							"class": "mif-printer fg-blue",
							"onclick": "Eirene.runStmt('10prec',{receiptno:'<a.receiptno>',billno:'<a.billno>',pid:'<c.pid>'})",
							"caption": "Print"
						}
					],
										
					"vsum": "7",
					"header": "Payment Date,Bill No,Bill Date,Patient ID,Patient Name,Paymode,Amount",
					"filter":"a.paymentmethod,a.createdon,b.pid,c.department"
					
				}				
			},
            "fields": [
				{"name": "billno int","label":"Bill No"},
				{"name": "paymentmethod varchar(30)","label":"Mode","fieldtype":"select",
				"option":"Cash,CMCHWallet,UPI,POS Card,InternetBanking,Cheque,InternetBanking/Cheque"},			
				{"name": "amount float","label":"Amount"},
				{"name": "advanceid char(36)","label":"Advance ID",
						"saveif":[
							{"sqlstatement":{"advbalance":"select balance FROM cmch_advance WHERE id='||thisvalue||'"}},
							{"if":"||thisvalue|| = BLANK or ||advbalance|| >= ||amount||","errormsg":"Insufficient Balance"}
						]
				},
				{"name": "receiptno int","label":"Receipt No",
					"default":{"insert":[
						{"sqlstatement":{"receiptno":"SELECT MAX(receiptno) +1 FROM cmch_payment"}},
						"||receiptno||"
					]}
				},
				{"name": "remark char(50)","label":"Remark"}
            ]
        }, {
            "name": "cmch_deathcertificate",
            "saveid": "18sv",
            "getid": "18dt",
            "delid": "18dt",
			"joindef":{
				"cmch_patient":"||thistbl||.pid=cmch_patient.pid"				
			},
            "form": {
                "0": {
                    "title": "Death Certificate",
                    "icon": "mif-delicious",
                    "type": "1 Column",
                    "fields": "*"
                }
            },
            "list": {
                "18": {
                    "action": "Get Table",
                    "formname": "deathcertificate",
                    "getform": "||thistbl|| 0",
                    "outputto": "html",
                    "output": "table",
                    "includeeditdelete": "true",
                    "filter": "pid",
                    "tbl": "cmch_deathcertificate a","filter":"a.pid",
                    "fld": "b.pname,a.pid,a.deathtime,a.issuedate",
                    "header": "Name,PatientID, Death Time,Certificate Issue Date",
                    "functionfield": [{
                            "name": "f1",
                            "type": "button",
                            "class": "mif-printer fg-blue",
                            "onclick": "Eirene.runStmt('18pr1-18pr',{pid:'<a.pid>',id:'<a.id>'})",
                            "caption": "Print"
                        }
                    ],
					"usejoin": "cmch_patient b",                    
                    "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:empty;#workareaAppendix;slow-cmd:dom,fun:show;#workareaFilter1;fast"
                },
                "18pr1": {
                    "action": "Get Row",
                    "outputto": "php",
                    "output": "details",
                    "tbl": "cmch_deathcertificate",
                    "fld": "DATE_FORMAT(issuedate,'%d-%m-%Y') as issuedate,DATE_FORMAT(deathtime,'%d-%m-%Y') as deathdate,DATE_FORMAT(deathtime,'%H:%i') as deathtime",
                    "whr": "id='||id||'"
                },
                "18pr": {
                    "action": "Get HTML",
                    "outputto": "html",
                    "output": "#workareaAppendix",
                    "prepend": [
                        "<center><img src='resource/image/cmch_logo1.png' width='400' height='60'></center>",
                        "<DIV class='font-ArialNarrow' style='margin-top:20px'><center><h5>MEDICAL NOTIFICATION OF DEATH<h5></center></DIV>",
                        "<DIV class='font-ArialNarrow' style='margin-left:14cm;font-size:0.9em'>Date:||GET_details_issuedate||</DIV>"
                    ],
                    "template": [
                        "<table class='font-ArialNarrow' style='line-height:1.5;margin-top:10px;margin-left:2cm;margin-right:2cm;font-size:0.9em'>",
                        "<tr><td>I do hereby certify that I attended the deceased<b>   <u>||pname||</u>  </b>aged<b>  <u>||page||</u>  </b>sex ||pgender||",						
                        "Aadhaar Number <b> <u>||paadhaar||</u></b>, residing at <b>  <u>||pward||,||pcity||,||pdistrict||,||pstate||</u>.  </b>", 
						{
                            "if": "||pgender|| = Male",
                            "then": "He",
                            "else": "She"
                        },
                        " died at (time)<b>   <u>||GET_details_deathtime||</u>  </b> on (date)<b>   <u>||GET_details_deathdate||.</u>  </b></td>",
                        "<tr><td>To the best of my knowledge the cause of death is stated below</td></tr></table>",
                        "<table class='font-ArialNarrow' style='line-height:1.5;border:1px solid black;border-collapse:collapse;;margin-top:10px;margin-left:2cm;margin-right:2cm;font-size:0.9em'><tr><th colspan='2' style='border:1px solid black' class='pl-2'>Cause of death</th><th style='border:1px solid black' class='pl-2'>App.Interval between onset & death(Duration)</th></tr>",
                        "<tr><td style='width:250px;border:1px solid black'><div style='padding:8px;margin-right:8px;'><div>1. A) Disease or condition directly leading death.</div><div style='margin-top:50px'>B) Antecedent causes </div><div style='margin-top:20px'>C) Morbid conditions if any giving rise to the above cause stating the underlying condition last.</div><div style='margin-top:20px'>2. Other significant conditions contributing to the death but not related to the disease or conditions causing it.</div></td><td style='width:200px;border:1px solid black'><div style='padding:8px;margin-right:8px;'> a)<b>||disease||</b><br>due to or as consequence of <br>b) <b>||consequence1||</b><br>due to or as consequence of  <br>C) <b>||consequence2||<b><br><br><br><br>||significant||</div></td><td style='text-align:center;padding:8px;vertical-align: middle;border:1px solid black'>||onsetdeathduration||</td></tr></table>",
                        "<p class='font-ArialNarrow' style='text-align:left;margin-left:2cm;margin-top:10px;font-size:0.9em'>If deceased was a female, was the death associated with pregnancy<span style='float:right;margin-right:2cm;'>Yes/No</span><br> If Yes, was there a Delivery <span style='float:right;margin-right:2cm;'>Yes/No</span></p>",
                        "<p class='font-ArialNarrow' style='text-align:left;margin-left:2cm;margin-top:40px;font-size:0.9em'>Address or Rubber Stamp of the Institution<span style='float:right;margin-right:2cm;'>Signature & Designation <br> of Doctor<br><br>Name of Dr. & Reg.No.</span></p>"
                    ],
                    "tbl": "cmch_deathcertificate a",
                    "fld": "a.pid,b.pname,(YEAR(CURDATE())-b.pyob) as page,b.pgender,b.paadhaar,b.pward,b.pcity,b.pdistrict,b.pstate,a.deathtime,a.onsetdeathduration,a.disease,a.consequence1,a.consequence2,a.significant,a.pregnancydeath,a.delivery",
                    "usejoin":"cmch_patient b",					
                    "whr": "a.id='||id||'",
                    "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast-cmd:dom,fun:function;printHTML;workareaAppendix"
                }
            },
            "fields": [
				{"name": "pid char(36)","label": "Patient ID"},
				{"name": "deathtime datetime","label": "Death Date & Time"},
				{"name": "disease varchar(50)","label": "Disease/Condition directly leading to death"},
				{"name": "consequence1 varchar(100)","label": "Antecedent Causes"},
				{"name": "consequence2 varchar(100)", "label": "Morbid conditions if any giving rise to the above cause stating the underlying condition last"},
				{"name":"significant varchar(100)","label":"Other significant conditions contributing to thr death but no related to the disease or conditions causing it"},
				{"name":"onsetdeathduration varchar(20)","label":"If deceased was a female, was the death associated with pregnancy"},
				{"name":"pregnancydeath varchar(10)","label":"If Yes, was there a Delivery"},
				{"name":"delivery varchar(10)","label":"App. Interval between onset & death (Duration)"},
				{"name":"issuedate datetime","label":"Certificate Issue Date"}
            ]
        }, {
            "name": "cmch_evaluation",
            "fields": [{
                    "name": "parameterid char(36) UNIQUE NOT NULL"
                }, {
                    "name": "porder int NOT NULL default 1"
                }
            ]
        }, {
            "name": "cmch_ipjournal",
            "saveid": "21jsv",
            "getid": "21gtj",
            "delpermanentid": "21jdt",
            "form": {
                "1": {
                    "title": "Journal",
                    "icon": "mif-note",
                    "type": "Horizontal",
                    "fields": "jdate,title,remark,ipid"
                },
                "2": {
                    "title": "Journal",
                    "icon": "mif-dashboard",
                    "type": "Inline",
                    "fields": "jdate,ipid,title,remark",
                    "datacollapsed": false
                }
            },
            "list": {
                "21lst": {
                    "outputto": "html",
                    "output": "#workareaAppendix",
                    "tbl": "||thistbl||",
                    "getform": "||thistbl|| 2",
                    "includeeditdelete": true,
                    "fld": [
                        "jdate,title,remark"
                    ],
                    "datefield": "jdate",
                    "whr": [
                        "recordstatus=1", {
                            "if": "||ipid|| != BLANK",
                            "then": "and ipid='||ipid||'"
                        }, {
                            "if": "||jdate|| != BLANK",
                            "then": " and jdate='||jdate||'"
                        }
                    ],
                    "srt": "jdate",
                    "header": "Date,Title,Remark,Function",
                    "onsuccess": "cmd:dom,fun:show;#workareaAppendix"
                }
            },
            "fields": [{
                    "name": "ipid lookup NOT NULL",
                    "label": "Patient",
                    "default": "||pname||",
                    "lookup": {
                        "sqlid": "21lkup",
                        "tbl": "cmch_ip a",
                        "fld": "CONCAT(a.pid,' ',b.pname,' ',DATE_FORMAT(a.addate,'%d-%m-%Y')) as patient",
                        "whr": "a.didate is null",
                        "join": "INNER JOIN cmch_patient b on a.pid=b.pid"
                    }
                }, {
                    "name": "jdate date",
                    "label": "Date",
                    "default": "||CURDATE||"
                }, {
                    "name": "title varchar(100) NOT NULL",
                    "label": "Title"
                }, {
                    "name": "remark varchar(200) NOT NULL",
                    "label": "Remark"
                }
            ]
        }, {
            "name": "cmch_diettable",
            "saveid": "dietsv",
            "getid": "dietgt",
            "delid": "dietdt",
            "form": {
                "0": {
                    "title": "Diet Chart",
                    "icon": "mif-note",
                    "type": "1 Column",
                    "fields": "*"
                }
            },
            "list": {
                "dietlt": {
                    "output": "#workareaTablebox",
                    "getform": "||thistbl|| 0",
                    "fld": "disease,diet",
                    "whr": [
                        "recordstatus=1", {
                            "if": "||dietid|| != BLANK",
                            "then": " and id='||dietid||'"
                        }
                    ],
                    "includeeditdelete": "true",
                    "header": "Disease,Recommended Food",
                    "elem": {
                        "output": "#workareaFilter1",
                        "parent": "div",
                        "elem": [{
                                "name": "dietlt0",
                                "id": "dietlt0",
                                "type": "select",
                                "option": "SELECT id,disease FROM cmch_diettable WHERE recordstatus=1"
                            }, {
                                "name": "dietlt1",
                                "id": "dietlt1",
                                "type": "button",
                                "value": "Ok",
                                "onclick": "Eirene.runStmt('diettm',{dietid:$('#dietlt0').val()})"
                            }
                        ]
                    },
                    "onsuccess": "cmd:dom,fun:show;#workareaFilter-cmd:dom,fun:show;#workareaFilter1"
                },
                "diettm": {
                    "action": "Get HTML",
                    "output": "#workareaTablebox",
                    "name": "Diet HTML",
                    "tbl": "||thistbl||",
                    "fld": "disease,diet",
                    "whr": [
                        "recordstatus=1", {
                            "if": "||dietid|| != BLANK",
                            "then": " and id='||dietid||'"
                        }
                    ],
                    "template": [
                        "<div><span class='mif-print' onclick='printHTML(&apos;dietprt&apos;)'></span></div>",
                        "<div id='dietprt'>",
                        "<div>Disease: <b>||disease||</b></div><hr/>",
                        "<div>||diet||</div>",
                        "</div>"
                    ]
                }
            },
            "fields": [{
                    "name": "disease varchar(40)",
                    "label": "Disease"
                }, {
                    "name": "diet varchar(6000)",
                    "fieldtype": "texteditor",
                    "label": "Diet Recommendation"
                }
            ]
        },
		{
			"name": "cmch_op",
			"saveid": "opsv",
			"delid": "opdel",
			"getid": "opdet",
			"joindef": {
				"cmch_appointment": "||thistbl||.appid=cmch_appointment.id",
				"cmch_patient":"cmch_patient.pid=cmch_appointment.pid",
				"cmch_doctors":"cmch_appointment.doctor=cmch_doctors.id"	
			},
			"trigger": {
				"insert": {
					"sqlstatement": {
						"a": "INSERT INTO cmch_prescription(id,medicine,createdby) SELECT UUID(), medicine, '||userid||' FROM cmch_op WHERE medicine NOT IN (SELECT medicine FROM cmch_prescription)"
					}
				}
			},
		"form": {
				"0": {
					"title": "OPD Prescription",
					"icon": "mif-delicious",
					"type": "inline",
					"fields": "pasthistory,complaints,dctr_recmdtn,medicine,visit_date"
				}
			},
			"list": {
				"4lt": {
					"tbl": "cmch_op a",
					"getform": "||thistbl|| 0",
					"outputto": "html",
					"output": "#workareaTablebox",
					"serialno": 1,
					"usejoin": "cmch_appointment b,cmch_doctors c,cmch_patient d",
					"fld": "b.pid,d.pname,c.name,b.pcase,a.pasthistory,a.complaints,a.dctr_recmdtn,a.medicine,a.visit_date",
					"header": "PID,Patient,Doctor,Case Type,Past History,Complaints & Clinical findings,Investigation,Prescription Details,Next Visit Date",
					"filter":"b.pid,c.name,b.pcase",
					"editablefields": "a.pasthistory,a.complaints,a.dctr_recmdtn,a.medicine,a.visit_date",
					"includeeditdelete": true,
					"srt":"a.createdon ASC",
                    "elem": {
						"parent": "div",
						"output": "#workareaFilter",
						"elem": [
							{
								"name": "f",
								"value": "OP Today",
								"type": "button",
								"onclick": "Eirene.runStmt('4lt')",
								"title": "OP List"
							},{
								"name": "f1",
								"value": "OP List",
								"type": "button",
								"onclick": "Eirene.runStmt('7lt')",
								"title": "OP List"
							},
							{
								"name": "f2",
								"value": "Medication List",
								"type": "button",
								"onclick": "Eirene.runStmt('5lt')",
								"title": "Prescription"
							}
						]
					},
					"functionfield": [
					{
						"name": "print",
						"type": "button",
						"class": "mif-printer fg-blue",
						"caption": "Print",
						"onclick": "Eirene.runStmt('oprnt',{id:'<a.id>'})"
					}],
					"whr": "a.recordstatus=1 and DATE(a.opdate) = CURDATE()",
					"onsuccess": "cmd:dom,fun:show;#workareaFilter-cmd:dom,fun:show;#workareaTablebox-cmd:dom,fun:hide;#workareaFilter1-cmd:dom,fun:hide;#workareaAppendix;"
				},"7lt": {
					"tbl": "cmch_op a",
					"getform": "||thistbl|| 0",
					"outputto": "html",
					"output": "#workareaTablebox",
					"serialno": 1,
					"usejoin": "cmch_appointment b,cmch_doctors c,cmch_patient d",
					"fld": "b.pid,d.pname,c.name,b.pcase,a.pasthistory,a.complaints,a.dctr_recmdtn,a.medicine,a.visit_date",
					"header": "PID,Patient,Doctor,Case Type,Past History,Complaints & Clinical findings,Investigation,Prescription Details,Next Visit Date",
					"filter":"b.pid,c.name,b.pcase",
					"editablefields": "a.complaints,a.pasthistory,a.dctr_recmdtn,a.medicine,a.visit_date",
					"includeeditdelete": true,
					"srt":"a.createdon DESC",
					"functionfield": [
						{
						"name": "print",
						"type": "button",
						"class": "mif-printer fg-blue",
						"caption": "print",
						"onclick": "Eirene.runStmt('oprnt',{id:'<a.id>'})"
					}],
					"whr": "a.recordstatus=1",
					"onsuccess": "cmd:dom,fun:show;#workareaFilter-cmd:dom,fun:show;#workareaTablebox-cmd:dom,fun:hide;#workareaFilter1-cmd:dom,fun:hide;#workareaAppendix;"
				}
			},
			"fields": [
				{	"name":"appid char(36)",
					"label":"Appointment ID"
				},
				{
					"name": "pasthistory",
					"label": "Past History",
					"type": "varchar(2000)",
					"fieldtype": "textarea"
				},{
					"name": "complaints",
					"label": "Complaints and Clinical findings",
					"type": "varchar(2000)",
					"fieldtype": "textarea"
				},
				{
					"name": "dctr_recmdtn",
					"type": "varchar(2000)",
					"label": "Investigations",
					"fieldtype": "textarea"
					
				},
				{
					"name": "medicine",
					"label": "Prescription Details",
					"type": "varchar(2000)",
					"fieldtype": "textarea"
				},
				{
					"name": "visit_date",
					"type": "date",
					"label": "Next Visit Date"
				},{
					"name": "opdate",
					"type": "datetime",
					"default": "CURDATETIME()",
					"label": "OP Date"
				}
			]
		},
		{
			"name": "cmch_prescription",
			"saveid": "psv",
			"delid": "pdel",
			"getid": "pdet",
			"form": {
				"0": {
					"title": "Medication List",
					"icon": "mif-delicious",
					"type": "Inline",
					"fields": "*"
				}
			},
			"list": {
				"5lt": {
					"tbl": "cmch_prescription",
					"getform": "||thistbl|| 0",
					"output": "#workareaTablebox",
					"filter": "medicine",
					"fld": "medicine",
					"header": "Medication List",
					"includeeditdelete": true,
					"whr": "recordstatus=1",
					"onsuccess": "cmd:dom,fun:show;#workareaFilter-cmd:dom,fun:show;#workareaTablebox-cmd:dom,fun:hide;#workareaFilter1-cmd:dom,fun:hide;#workareaAppendix;"
				}
			},
			"fields": [
				{
					"name": "medicine",
					"label": "Medicine",
					"type": "varchar(2000)",
					"fieldtype": "textarea"
				}
			]
		}],
		"sqlcommands_oninstall": [],
		"form": [{
            "name": "discharge",
            "formtype": "Horizontal",
            "title": "Discharge",
            "icon": "mif-delicious",
            "saveButton": "1",
            "savecustomid": "15svdi",
            "getrecordcustomid": "15gtip",
            "cancelButton": "1",
            "flex_row": "true",
            "flex_justify": "start",
            "field": [{
                    "name": "pid",
                    "donotprint": 1,
                    "label": "Patient ID",
                    "fieldtype": "u",
                    "type": "text",
                    "required": 1

                }, {
                    "name": "diagnosis",
                    "label": "Diagnosis",
                    "fieldtype": "s",
                    "type": "hidden",
                    "style": "line-height:1.2"

                }, {
                    "name": "details",
                    "label": "Details at Presentation",
                    "fieldtype": "s",
                    "type": "textarea",
                    "style": "line-height:1.2"

                }, {
                    "name": "cause",
                    "label": "Cause for Admission",
                    "fieldtype": "s",
                    "type": "textarea",
                    "style": "line-height:1.2"
                }, {
                    "name": "pasthistory",
                    "label": "Past History",
                    "fieldtype": "s",
                    "type": "textarea",
                    "style": "line-height:1.2"
                }, {
                    "name": "pastsurgery",
                    "label": "Past Surgery",
                    "fieldtype": "s",
                    "type": "textarea",
                    "style": "line-height:1.2"
                }, {
                    "name": "familyhistory",
                    "label": "Family History",
                    "fieldtype": "s",
                    "type": "textarea",
                    "style": "line-height:1.2"
                }, {
                    "name": "ipid",
                    "label": "IP ID",
                    "type": "hidden",
                    "fieldtype": "s"
                }, {
                    "name": "labreport",
                    "printlabel": "Lab Report",
                    "label": "Lab Report <span><button onclick='Eirene.runStmt(&apos;5flr-5lrdi&apos;,{pid:$(&apos;input[name=pid]&apos;).val()})'>Fetch</button></span>",
                    "fieldtype": "s",
                    "type": "texteditor"
                }, {
                    "name": "medicare",
                    "label": "Regular",
                    "fieldtype": "s",
                    "type": "hidden",
                    "style": "line-height:1.2"
                }, {
                    "name": "medicare1",
                    "label": "Important",
                    "fieldtype": "s",
                    "type": "hidden",
                    "style": "line-height:1.2"
                }, {
                    "name": "dischargenotes",
                    "label": "Discharge Details",
                    "fieldtype": "s",
                    "type": "textarea",
                    "style": "line-height:1.2"
                }, {
                    "name": "advice",
                    "label": "Advice at Discharge",
                    "fieldtype": "s",
                    "type": "textarea",
                    "style": "line-height:1.2"
                }, {
                    "name": "issuefollowup",
                    "label": "Issues to Addressed at follow up",
                    "fieldtype": "s",
                    "type": "textarea",
                    "style": "line-height:1.2"
                }, {
                    "name": "nextdate",
                    "donotprint": 1,
                    "label": "Next Follow Up Date",
                    "fieldtype": "datetime",
                    "type": "datetime"
                }, {
                    "name": "bowelhabits",
                    "label": "Bowel Habits",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "micturition",
                    "label": "Micturition",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "sleep",
                    "label": "Sleep",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "diet",
                    "label": "Diet",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "calciumintake",
                    "label": "Calcium In take",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "physicalactivity",
                    "label": "Physical Activity",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "sunlightexplosure",
                    "label": "Sunlight Explosure",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "currentmedication",
                    "label": "Current Medication",
                    "type": "textarea",
                    "fieldtype": "s"
                }, {
                    "name": "onexamination",
                    "label": "On Examination",
                    "type": "label",
                    "fieldtype": "s"
                }, {
                    "name": "height",
                    "label": "Height(CM)",
                    "type": "number",
                    "fieldtype": "s"
                }, {
                    "name": "weight",
                    "label": "Weight(KG)",
                    "type": "number",
                    "fieldtype": "s"
                }, {
                    "name": "bmi",
                    "label": "IBW",
                    "type": "number",
                    "type": "hidden",
                    "fieldtype": "s",
                    "maxlength": "5"
                }, {
                    "name": "ibwm",
                    "label": "Ideal Body Weight",
                    "type": "number",
                    "type": "hidden",
                    "fieldtype": "s",
                    "maxlength": "5"
                }, {
                    "name": "ibwf",
                    "label": "Ideal Body Weight",
                    "type": "number",
                    "type": "hidden",
                    "fieldtype": "s",
                    "maxlength": "5"
                }, {
                    "name": "overweightm",
                    "label": "Over Weight",
                    "type": "number",
                    "type": "hidden",
                    "fieldtype": "s",
                    "maxlength": "5"
                }, {
                    "name": "overweightf",
                    "label": "Over Weight",
                    "type": "number",
                    "type": "hidden",
                    "fieldtype": "s"
                }, {
                    "name": "pulse",
                    "label": "Pulse",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "bp",
                    "label": "BP",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "pallor",
                    "label": "Pallor",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "lymphnodes",
                    "label": "Lymph nodes",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "goiter",
                    "label": "Goiter",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "oedema",
                    "label": "Oedema",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "skin",
                    "label": "Skin",
                    "type": "textarea",
                    "fieldtype": "s"
                }, {
                    "name": "peripheralpulses",
                    "label": "Peripheral Pulses",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "feet",
                    "label": "Feet",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "cvs",
                    "label": "CVS",
                    "type": "textarea",
                    "fieldtype": "s"
                }, {
                    "name": "rs",
                    "label": "Respiratory System",
                    "type": "label",
                    "fieldtype": "s"
                }, {
                    "name": "trachea",
                    "label": "Trachea",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "respiratorymovements",
                    "label": "Respiratory Movements",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "percussion",
                    "label": "Percussion",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "auscultation",
                    "label": "Auscultation",
                    "type": "textarea",
                    "fieldtype": "s"
                }, {
                    "name": "abdomen",
                    "label": "Abdomen",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "cns",
                    "label": "CNS",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "fundi",
                    "label": "Fundi",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "reflexes",
                    "label": "Reflexes",
                    "type": "texteditor",
                    "fieldtype": "s"
                }, {
                    "name": "plantar",
                    "label": "Plantar",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "vibrationsense",
                    "label": "Vibration Sense",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "chvostekssign",
                    "label": "Chvosteks Sign",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "proximalweaknesss",
                    "label": "Proximal Weaknesss",
                    "type": "text",
                    "fieldtype": "s"
                }, {
                    "name": "dexareport",
                    "label": "Dexa Report",
                    "type": "texteditor",
                    "fieldtype": "s"
                }, {
                    "name": "xray",
                    "label": "X-RAY",
                    "type": "texteditor",
                    "fieldtype": "s"
                }, {
                    "name": "ecg",
                    "label": "ECG",
                    "type": "texteditor",
                    "fieldtype": "s"
                }

            ]
        }, {
            "name": "billing",
            "formtype": "Horizontal",
            "title": "Billing",
            "icon": "mif-delicious",
            "saveButton": "1",
            "savecustomid": "8svbl",
            "getrecordcustomid": "8gtbl",
            "cancelButton": "1",
            "flex_row": "true",
            "flex_justify": "start",
            "field": [{
                    "name": "pid",
                    "label": "Patient ID<span id='pidnm'></span>",
                    "fieldtype": "s",
                    "type": "text",
                    "required": 1,
                    "maxlength": "50",
                    "jsevent": "onblur",
                    "jsfun": "Eirene.runStmt(&apos;4gtpnm&apos;,{pid:$(this).val()});"
                }, {
                    "name": "item",
                    "label": "Item",
                    "style": "width:300px",
                    "fieldtype": "u",
                    "required": 1,
                    "type": "select",
                    "option": "select item,concat(item,':',rate,':',category) from cmch_item where recordstatus=1",
                    "jsevent": "onchange",
                    "jsfun": "let a=$(&apos;select[name=item] option:selected&apos;).text();a=a.split(&apos;:&apos;);if(a.length<2) return false;$(&apos;input[name=rate]&apos;).val(a[1]);$(&apos;input[name=category]&apos;).val(a[2]);$(&apos;#quatity&apos;).val(1);$(&apos;#total&apos;).val(a[1]);$(&apos;#discount&apos;).val(0);"

                }, {
                    "name": "rate",
                    "label": "Rate",
                    "fieldtype": "n",
                    "required": 1,
                    "type": "number"
                }, {
                    "name": "category",
                    "label": "Category",
                    "fieldtype": "s",
                    "required": 1,
                    "type": "hidden"
                }, {
                    "name": "quatity",
                    "label": "Quantity",
                    "fieldtype": "n",
                    "required": 1,
                    "type": "number",
                    "jsevent": "onblur",
                    "jsfun": "let to= $(this).val()*$(&apos;input[name=rate]&apos;).val(); $(&apos;input[name=total]&apos;).val(to);$(&apos;input[name=discount]&apos;).val(0);"
                }, {
                    "name": "discount",
                    "label": "Discount<span><select id='dtype'><option value='0' selected>%</option><option value='1'>Rs.</option></select></span>",
                    "fieldtype": "n",
                    "type": "number",
                    "jsevent": "onblur",
                    "jsfun": "if($(&apos;#dtype&apos;).val()==0){$(&apos;#total&apos;).val(($(&apos;#quatity&apos;).val()*$(&apos;#rate&apos;).val())-($(&apos;#discount&apos;).val()*$(&apos;#quatity&apos;).val()*$(&apos;#rate&apos;).val()/100));$(&apos;#discount&apos;).val($(&apos;#discount&apos;).val()*$(&apos;#quatity&apos;).val()*$(&apos;#rate&apos;).val()/100)}else{$(&apos;#total&apos;).val(($(&apos;#quatity&apos;).val()*$(&apos;#rate&apos;).val())-$(&apos;#discount&apos;).val())}"
                }, {
                    "name": "total",
                    "label": "Total",
                    "fieldtype": "n",
                    "required": 1,
                    "type": "number"

                }
            ]
        }
		


    ],
	"form_html": "",
    "navbutton": [{
            "customid": "1",
            "caption": "CMCH",
            "icon": "mif-delicious",
            "btntype": "ribbon-button",
            "btngroup": "Others",
            "btntab": "Developer",
            "btnorder": "1",
            "onclick": "initializePlugin()"

        }
    ],
    "script": "",
    "formbuttons": [
		{
            "name": "doctors",
            "caption": "Doctors",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('1lt')"
        }, {
            "name": "patient",
            "caption": "Patient",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('3')"
        }, {
            "name": "Appointment",
            "caption": "Appointment",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('4')"
        },{
            "name": "IP",
            "caption": "IP",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('5')"
        }, {
            "name": "OP",
            "caption": "OP",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('4lt')"
        }, {
            "name": "clinicaldetails",
            "caption": "Clinical Details",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('7-7flt')"
        }, {
            "name": "billing",
            "caption": "Billing",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('8-10bft')"
        }, {
            "name": "diet",
            "caption": "Recommended Diet",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('dietlt')"
        }, {
            "name": "xray",
            "caption": "X-RAY",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('11')"
        }, {
            "name": "lab",
            "caption": "Lab",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('12')"
        }, {
            "name": "ayushman",
            "caption": "Ayushman",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('ayubtn')"
        }, {
            "name": "report",
            "caption": "Report",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('20')"
        }, {
            "name": "settings",
            "caption": "Settings",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('16-16btn')"
        }, {
            "name": "asset",
            "caption": "Asset",
            "icon": "mif-delicious fg-red",
            "onclick": "Eirene.runStmt('astlt',{project:'CMCH'})"
        }
    ],
    "sqlstatement": [
		  {
            "id": "oprnt",
            "name": "OP Details Print",
            "sql": {
                "action": "Return",
                "outputto": "html",
                "output": "#workareaAppendix",
			"prerun":[
				{"sqlstatement":{"tbl":"SELECT d.pid,b.pname,(YEAR(CURDATE())-b.pyob)as age,b.pward,b.pcity,b.pdistrict,b.pstate,b.pgender,c.name,c.qualification,c.mcireg,(SELECT DATE_FORMAT(a.visit_date,'%d/ %m/ %Y'))AS vistdt,(SELECT DATE_FORMAT(a.opdate,'%d/%m/%Y - %H:%i:%s'))AS opdt,d.pcase,a.pasthistory,REPLACE(a.complaints, '\\\\n', '<br>')as complaint,REPLACE(a.dctr_recmdtn, '\\\\n', '<br>')AS investigation,REPLACE(a.medicine, '\\\\n', '<br>')AS medicines,c.specialization FROM cmch_op a LEFT JOIN cmch_appointment d ON a.appid= d.id LEFT JOIN cmch_patient b ON d.pid= b.pid LEFT JOIN cmch_doctors c ON d.doctor=c.id WHERE a.id='||id||'"}}
			],
            "prepend": [
			"<center><img src='resource/image/cmch_logo1.png' width='400' height='60'></center>",
			"<div style='text-align:center; font-size:12pt; margin-top:10px; font-weight:bold;'>OPD Prescription</div>",
			"<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:3cm;margin-right:3cm;margin-top:10px;width:80%;font-size:0.8em'>",
			"<tr><td style='border:1px solid black' class='pl-1'><b>Name</b></td>",
			"<td style='border:1px solid black;width:5cm' class='p-1'>||tbl_pname||</td>",
			"<td style='border:1px solid black' class='p-1'><b>Patient ID</b></td>",
			"<td style='border:1px solid black;width:5cm' class='p-1'>||tbl_pid||</td></tr>",
			"<tr><td style='border:1px solid black' class='p-1'><b>Gender</b></td>", 
			"<td style='border:1px solid black' class='p-1'>||tbl_pgender||</td>",					
			"<td style='border:1px solid black' class='pl-1'><b>Doctor</b></td>",
			"<td style='border:1px solid black;width:5cm' class='p-1'>||tbl_name||</td><tr>",
			"<tr><td style='border:1px solid black' class='pl-1'><b>Age</b></td>",
			"<td style='border:1px solid black;width:5cm' class='p-1'>||tbl_age||</td>",
			"<td style='border:1px solid black' class='p-1'><b>Next Visit</b></td>",
			"<td style='border:1px solid black;width:5cm' class='p-1'>||tbl_vistdt||</td></tr>",
			"<tr><td style='border:1px solid black' class='p-1'><b>Address</b></td>",
			"<td style='border:1px solid black;width:5cm' class='p-1'>||tbl_pcity||,||tbl_pdistrict||,||tbl_pstate||</td>",
			"<td style='border:1px solid black' class='p-1'><b>Case</b></td>",
			"<td style='border:1px solid black;width:5cm' class='p-1'>||tbl_pcase||</td></tr>",
			"</table>",
			"<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:3cm;margin-right:3cm;font-size:0.7em;width:80%;margin-top:30px'>",
			"<tr><TH style='text-align:left;Background-color:#A3A3A3;font-size:1.2em;padding:4px' class='pl-2'><b>Past History:</b></TH></tr>",
			"<tr><td style='border:1px solid black;padding:4px;height:80px;' class='pb-4'>&nbsp;||tbl_pasthistory||</td></tr>", 
			"<tr><TH style='text-align:left;Background-color:#A3A3A3;font-size:1.2em;padding:4px' class='pl-2'><b>Complaints and Clinical findings:</b></TH></tr>",
			"<tr><td style='border:1px solid black;padding:4px;height:100px;' class='pb-4'>&nbsp;||tbl_complaint||</td></tr>", 
			"<tr><TH style='text-align:left;Background-color:#A3A3A3;font-size:1.2em;padding:4px' class='pl-2'><b>Investigation:</b></TH></tr>",
			"<tr><td style='border:1px solid black;padding:4px;height:100px;' class='pb-4'>&nbsp;||tbl_investigation||</td></tr>",
			"<tr><TH style='text-align:left;Background-color:#A3A3A3;font-size:1.2em;padding:4px' class='pl-2'><b>Prescription Details:</b></TH></tr>",
			"<tr><td style='border:1px solid black;padding:4px;height:180px;' class='pb-4'>&nbsp;||tbl_medicines||</td></tr>",
			"</table>"
			],
			"append": [
				"<div class='font-ArialNarrow' style='margin-left:3cm;margin-top:50px;font-size:0.8em'><b>||tbl_name||</b>, ||tbl_qualification||,||tbl_specialization||</div>", 
				"<div class='font-ArialNarrow' style='margin-left:3cm;font-size:0.8em'><b>Reg No:</b> &nbsp;||tbl_mcireg||</div>", 
				"<div class='font-ArialNarrow' style='margin-left:3cm;margin-top:60px;font-size:0.8em'>Signature of the Attending Physician/Doctor</div>",
				"<div class='font-ArialNarrow' style='margin-left:3cm;font-size:0.8em'>Date & Time: ||tbl_opdt||</div>",
				"<div class='font-ArialNarrow' style='margin-left:3cm;font-size:0.8em'>Christian Medical Centre & Hospital</div>"
			],
			"onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast-cmd:dom,fun:function;printHTML;workareaAppendix"
            }
        },
		{
            "id": "4a",
            "name": "Treatment Protocol(Appointment)",
            "sql": {
                "action": "MULTISTMT",
                "multistmt": [{
                        "action": "Get Table",
                        "outputto": "html",
                        "output": "table",
                        "tbl": "cmch_appointment a",
                        "fld": "b.pid,b.pname",
                        "functionfield": [{
                                "type": "checkbox",
                                "name": "5tpchk",
                                "prepend": 1,
                                "id": "'<a.id>'"
                            }, {
                                "type": "textarea",
                                "style": "line-height:1.2",
                                "value": "<primarycomplaint>",
                                "caption": "Primary Complaint",
                                "showDialogOnFocus": true,
                                "onblur": "Eirene.runStmt('4pcs',{ID:'<a.id>',primarycomplaint:$(this).val()})"
                            }, {
                                "type": "textarea",
                                "style": "line-height:1.2",
                                "value": "<test>",
                                "caption": "Diagnostic Tests",
                                "showDialogOnFocus": true,
                                "onblur": "Eirene.runStmt('4ts',{ID:'<a.id>',test:$(this).val()})"
                            }, {
                                "type": "textarea",
                                "style": "line-height:1.2",
                                "value": "<diagnosis>",
                                "caption": "Diagnosis",
                                "showDialogOnFocus": true,
                                "onblur": "Eirene.runStmt('4dgs',{ID:'<a.id>',diagnosis:$(this).val()})"
                            }, {
                                "type": "textarea",
                                "style": "line-height:1.2",
                                "value": "<medicare>",
                                "caption": "Medical Care",
                                "showDialogOnFocus": true,
                                "onblur": "Eirene.runStmt('4mcs',{ID:'<a.id>',medicare:$(this).val()})"
                            }, {
                                "type": "icon",
                                "class": "mif-attachment",
                                "title": "Add OP Documents",
                                "onclick": "let content='&lt;div id=&quot;4adiv1&quot;&gt;&lt;/div&gt;&lt;div id=&quot;4adiv2&quot;&gt;&lt;/div&gt;';showDialog('Appointment Doc',content,'info');Eirene.runStmt('4b',{appid:'<a.id>'});",
								"caption":"attach"
                            }, {
                                "type": "icon",
                                "class": "mif-printer",
                                "onclick": "Eirene.runStmt('4pr1-4tppr',{id:'<a.id>'})",
								"caption":"print"
                            }
                        ],
                        "join": "INNER JOIN cmch_patient b ON a.pid=b.pid LEFT JOIN cmch_doctors c ON c.id=a.doctor",
                        "header": "Patient ID,Patient",
                        "whr":
                        [
                            "a.recordstatus=1", {
                                "if": "||pid|| != BLANK",
                                "then": " and a.pid='||pid||'"
                            }, {
                                "if": "||appdtfrom|| != BLANK and ||appdtto|| != BLANK",                                
                                "then": " and DATE(a.pdate)>='||appdtfrom||' and DATE(a.pdate)<='||appdtto||'"
                            }, {
                                "if": "||appdtfrom|| != BLANK and ||appdtto|| = BLANK",                                
                                "then": " and DATE(a.pdate)='||appdtfrom||'"
                            }, {
                                "if": "||appdtfrom|| = BLANK and ||appdtto|| = BLANK",                               
                                "then": " and DATE(a.pdate)=CURDATE()"
                            }
                        ],
                        "prepend": "<div><button class='mif-printer fg-blue mr-2' onclick='let elem;let len=$(&apos;#workareaTablebox input[type=checkbox]:checked&apos;).length;if(len){elem=$(&apos;#workareaTablebox input[type=checkbox]:checked&apos;)}else{elem=$(&apos;#workareaTablebox input[type=checkbox]&apos;)}let ids=[];elem.each(function(i,x){ids[i]=$(this).attr(&apos;id&apos;)});ids=ids.join();Eirene.runStmt(&apos;4tppr2&apos;,{IDS:ids})'></button><button onclick='Eirene.runStmt(&apos;4&apos;)'>Today</button><button onclick='Eirene.runStmt(&apos;4a-4aflt&apos;)'>Treatment Protocol</button></div>",
                        "onsuccess": "cmd:dom,fun:function;convertSelect;#workareaTablebox-cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:show;#workareaFilter1;slow-cmd:dom,fun:hide;#workareaAppendix;slow"
                    }
                ]
            }
        },{
            "id": "4aflt",
            "name": "Appointment List Filter",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "flt",
                "value": "",
				"elem": {
                    "parent": "div",
                    "output": "#workareaFilter",
                    "elem": [{
                            "name": "f1",
                            "id": "pid",
                            "placeholder": "Patient ID",
                            "type": "text"
                        },{
                            "name": "f2",
                            "id": "appdtfrom",
                            "label": "Date From: ",
                            "type": "datepicker",
                            "value": "||CURDATE||"
                        },{
                            "name": "f3",
                            "id": "appdtto",
                            "label": "Date To: ",
                            "type": "datepicker",
                            "value": "||CURDATE||"
                        },{
                            "name": "f4",
                            "value": "Get",
                            "type": "button",
                            "class": "button secondary",
                            "onclick": "Eirene.runStmt('4a',{pid:$('#pid').val(),appdtfrom:$('#appdtfrom').val(),appdtto:$('#appdtto').val()})"
                        }
                    ]
                },
                "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:show;#workareaTablebox;slow-cmd:dom,fun:hide;#workareaFilter1;slow"
            }
           }, 
		   {
            "id": "4pr1",
            "name": "Get Treatment Protocol (OP Patient details)",
            "sql": {
                "action": "Get Row",
                "outputto": "php",
                "output": "dates",
                "tbl": "cmch_appointment",
                "fld": "DATE_FORMAT(pdate,'%d-%m-%Y') as pdate, DATE_FORMAT(nextvisit,'%d-%m-%Y') as nextvisit",
                "whr": "id='||id||'"
            }
        },
        {
            "id": "4tppr",
            "name": "Get Treatment Protocol HTML(OP)",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#workareaAppendix",
                "prepend": [
                    "<button class='mif-printer fg-blue' onclick='printHTML(&apos;workareaAppendix&apos;)'></button>",
                    "<center><img src='resource/image/cmch_logo1.png' width='400' height='60'></center>"
                ],
                "template": [
                    "<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:3cm;margin-right:3cm;margin-top:10px;width:80%;font-size:0.8em'>",
                    "<tr><td style='border:1px solid black' class='pl-1'><b>Name</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pname||</td><td style='border:1px solid black' class='p-1'><b>Patient ID</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pid||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>Gender</b></td>", 
					"<td style='border:1px solid black' class='p-1'>||pgender||</td>",					
                    "<td style='border:1px solid black' class='pl-1'><b>Appoinment Date</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||GET_dates_pdate||</td><tr>",
                    "<tr><td style='border:1px solid black' class='pl-1'><b>Age</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||age||</td><td style='border:1px solid black' class='p-1'><b>Next Visit</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||GET_dates_nextvisit||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>Address<b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pward||,||pcity||,||pdistrict||,||pstate||</td><td></td><td></td></tr>",
                    "</table>",
                    "<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:3cm;margin-right:3cm;font-size:0.7em;width:80%;margin-top:30px'>",
                    "<tr><TH style='text-align:left;Background-color:#A3A3A3;font-size:1.2em;padding:4px' class='pl-2'><b>Primary Complaints<bb></TH></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pb-4'>&nbsp;||primarycomplaint||</td></tr>",
                    "<tr><TH style='text-align:left;Background-color:#A3A3A3;;font-size:1.2em;padding:4px' class='pl-2'><b>Diagnostic Tests</b></TH></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pb-4'>&nbsp;||test||</td></tr>",
                    "<tr><TH style='text-align:left;Background-color:#A3A3A3;font-size:1.2em;padding:4px' class='pl-2'><b>Diagnosis</b></TH></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pb-4'>&nbsp;||diagnosis||</td></tr>",
                    "<tr><TH style='text-align:left;Background-color:#A3A3A3;font-size:1.2em;padding:4px' class='pl-2'><b>Treatment Details</b></TH></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pb-4'>&nbsp;||medicare||</td></tr>",
                    "</table>"
                ],
                "append": [
                    "<div class='font-ArialNarrow' style='margin-left:3cm;margin-top:40px;font-size:0.8em'>Signature of the Attending Physician/Doctor</div>",
                    "<div class='font-ArialNarrow' style='margin-left:3cm;font-size:0.8em'>Date:||GET_dates_pdate||</div>",
                    "<div class='font-ArialNarrow' style='margin-left:3cm;font-size:0.8em'>Dept of Medicine, CMCH</div>"
                ],
                "tbl": "cmch_appointment a",
                "fld": "a.pid,b.pname,(YEAR(CURDATE())-b.pyob) as age,a.pdate,a.nextvisit,a.diagnosis,a.primarycomplaint,a.test,a.medicare,b.pward,b.pcity,b.pdistrict,b.pstate,b.pgender",
                "join": [
                    "LEFT JOIN cmch_patient b ON a.pid= b.pid",
                    "LEFT JOIN cmch_doctors c ON a.doctor=c.id"
                ],
                "whr": "a.id='||id||'",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast-cmd:dom,fun:function;printHTML;workareaAppendix"
            }
        }, {
            "id": "4tppr2",
            "name": "Treatm Protocol Print(Appointment Selected)",
            "sql": {
                "action": "Get Table",
                "tbl": "cmch_appointment a",
                "output": "#workareaAppendix",
                "fld": "a.pid,b.pname,a.primarycomplaint,a.test,a.diagnosis,a.medicare",
                "join": "INNER JOIN cmch_patient b ON a.pid=b.pid",
                "whr": "a.id IN (||IDS||)",
                "header": "Patient ID, Patient Name,Primary Complaint,Diagnostic Tests,Diagnosis,Medical Care",
                "onsuccess": "cmd:dom,fun:function;printHTML;workareaAppendix"
            }
        }, {
            "id": "4dgs",
            "name": "Save Diagnosis(Appointment)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_appointment",
                "fld": "diagnosis",
                "value": "||diagnosis||",
                "fldtype": "s",
                "command": "update",
                "whr": "id='||ID||' ",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {
            "id": "4pcs",
            "name": "Save Primary complaint(Appointment)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_appointment",
                "fld": "primarycomplaint",
                "value": "||primarycomplaint||",
                "fldtype": "s",
                "command": "update",
                "whr": "id='||ID||' ",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {
            "id": "4ts",
            "name": "Save Test(Appointment)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_appointment",
                "fld": "test",
                "value": "||test||",
                "fldtype": "s",
                "command": "update",
                "whr": "id='||ID||' ",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {
            "id": "4mcs",
            "name": "Save medical care(Appointment)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_appointment",
                "fld": "medicare",
                "value": "||medicare||",
                "fldtype": "s",
                "command": "update",
                "whr": "id='||ID||' ",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {

            "id": "4st3",
            "name": "Save Visited(Appointment)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_appointment",
                "fld": "status",
                "value": "3",
                "fldtype": "n",
                "command": "update",
                "whr": "id= '||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful-4",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {

            "id": "4st4",
            "name": "Save Visited(Appointment)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_appointment",
                "fld": "status",
                "value": "4",
                "fldtype": "n",
                "command": "update",
                "whr": "id= '||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful-4",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {

            "id": "4st5",
            "name": "Save Visited(Appointment)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_appointment",
                "fld": "status",
                "value": "5",
                "fldtype": "n",
                "command": "update",
                "whr": "id= '||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful-4",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "4gtpnm",
            "name": "Get Patient Name",
            "sql": {
                "action": "Get Value",
                "outputto": "php",
                "output": "nm",
                "tbl": "cmch_patient",
                "fld": "CONCAT(' (',pname,') ')",
                "whr": "pid='||pid||'",
                "onsuccess": "cmd:dom,fun:html;#pidnm;||GET_nm||"
            }

        }, {
            "id": "5sft",
            "name": "IP Summary Filter",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "demo",
                "value": "",

                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter1",
                    "elem": [{
                            "name": "f1",
                            "type": "datepicker",
                            "id": "5sumftdt",
                            "value": "||CURDATE||"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Daily Report",
                            "onclick": "Eirene.runStmt('5sum',{dt:$('#5sumftdt').val()})"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Monthly Report",
                            "onclick": "Eirene.runStmt('5sum1',{dt:$('#5sumftdt').val().substring(0,7),cd:formatDate(new Date()),cm:formatDate(new Date()).substring(0,7),dfi:formatDate(new Date($('#5sumftdt').val().substring(0,4), $('#5sumftdt').val().substring(6,7)-1, 1)),dti:formatDate(new Date($('#5sumftdt').val().substring(0,4), $('#5sumftdt').val().substring(6,7), 0))})"
                        }
                    ]
                },
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix1;fast"
            }

        }, {
            "id": "5sum",
            "name": "Appointment Summary",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [{
                        "action": "Return",
                        "output": "#workareaTablebox",
                        "value": [
                            "<div>",
                            "<button class='no-print button secondary' onclick='printHTML(&apos;workareaTablebox&apos;)'>Print</button>",
                            "</div>",
                            "<center>",
                            "<h4 class='mt-3'>IP Report</h4>", {
                                "if": "||dt|| = BLANK",
                                "then": "<div><h4>||CURDATE_D_M_Y||</h4></div>"
                            }, {
                                "if": "||dt|| != BLANK",
                                "then": "<div><h4>||dt||</h4></div>"
                            },

                            "</center>"
                        ]
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "admission",
                        "stmt": "select count(id) from cmch_ip where recordstatus=1 and DATE(createdon)='||dt||' "
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "discharge",
                        "stmt": "select count(id) from cmch_ip where recordstatus=1 and DATE(didate)='||dt||' "
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "current",
                        "stmt": "select count(id) from cmch_ip where recordstatus=1 and DATE(addate) <= '||dt||' and (DATE(didate) >'||dt||' or didate='0000-00-00 00:00:00' or didate IS NULL)"
                    },
                    {
                        "action": "Return",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "value": [
                            "<center>",
                            "</center>",
                            "<br><p style='text-align:left;margin-left:4cm'>Total Admissions:||GET_admission||",
                            "<span style='float:right;margin-right:4cm;'>Total Discharges:||GET_discharge||</span><span style='float:right;margin-right:4cm;'>Total IP: ||GET_current||</span></p>"

                        ]
                    }

                ]
            }

        }, {
            "id": "5sum1",
            "name": "IP Summary (Monthly)",
            "sql": {
                "action": "Return",
                "outputto": "html",
                "output": "#workareaTablebox",
                "value": [
                    "<div id='pr0'></div>",
                    "<div id='pr1'></div>",
                    "<div id='pr2'></div>",
                    "<div id='pr3'></div>",
                    "<div id='pr4'></div>"
                ],
                "onsuccess": "5s1"
            }
        }, {
            "id": "5s1",
            "name": "IP Summary (Monthly)",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [{
                        "action": "Return",
                        "output": "#pr0",
                        "value": [
                            "<div>",
                            "<button class='no-print button secondary' onclick='printHTML(&apos;workareaTablebox&apos;)'>Print</button>",
                            "</div>",
                            "<center>",
                            "<h3 class='mt-3'>Monthly Report</h3>", {
                                "if": "||dt|| = BLANK",
                                "then": "<div><h3>||CURDATE_M_Y||</h3></div>"
                            }, {
                                "if": "||dt|| != BLANK",
                                "then": "<div><h3>||dt||</h3></div>"
                            },
                            "</center>"
                        ]
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "admission",
                        "stmt": "select count(id) from cmch_ip where recordstatus=1 and DATE_FORMAT(addate,'%Y-%m')= '||dt||' "
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "discharge",
                        "stmt": "select count(id) from cmch_ip where recordstatus=1 and DATE_FORMAT(didate,'%Y-%m')= '||dt||' "
                    }, {
                        "action": "Return",
                        "output": "#pr1",
                        "appendoutput": 1,
                        "value": [
                            "<center>",
                            "</center>",
                            "<p style='text-align:left;margin-left:4cm'>Total Admissions:||GET_admission||",
                            "<span style='float:right;margin-right:4cm;'>Total Discharges:||GET_discharge||</span></p>"

                        ]
                    }, {
                        "action": "Get Matrix",
                        "row": "a",
                        "col": "b",
                        "val": "result",
                        "outputto": "html",
                        "output": "#pr2",
                        "appendoutput": 1,
                        "horizontalsum": "1",
                        "tbl": "cmch_ip",
                        "class": "dataTable font-ArialNarrow",
                        "style": "border:1px solid black;border-collapse:collapse;margin-left:2cm;margin-top:0.5cm;width:75%;font-size:0.8em",
                        "fld": "'Admissions#' as a,DATE_FORMAT(createdon, '%d/%m') as b,CONCAT('<center>',COUNT(addate),'</center>')as result",
                        "grp": "a,b",
                        "srt": "createdon ASC",
                        "whr": "recordstatus=1 and DATE_FORMAT(addate,'%Y-%m')= '||dt||'",
                        "class": "eirene-table dataTable",
                        "prepend": "<center><h6 class='mt-3'>Detailed Admissions Report</h6></center>"
                    }, {
                        "action": "Get Matrix",
                        "row": "a",
                        "col": "b",
                        "val": "result",
                        "outputto": "html",
                        "output": "#pr3",
                        "horizontalsum": "1",
                        "tbl": "cmch_ip",
                        "class": "dataTable font-ArialNarrow",
                        "style": "border:1px solid black;border-collapse:collapse;margin-left:2cm;margin-top:0.5cm;width:75%;font-size:0.8em",
                        "fld": "'Discharges#' as a,DATE_FORMAT(didate, '%d/%m') as b,CONCAT('<center>',COUNT(didate),'</center>')as result",
                        "grp": "a,b",
                        "srt": "didate ASC",
                        "whr": "recordstatus=1 and DATE_FORMAT(didate,'%Y-%m')= '||dt||' ",
                        "class": "eirene-table dataTable",
                        "prepend": "<center><h6 class='mt-3'>Detailed Discharges Report</h6></center>"
                    }, {
                        "runif": "||dt|| != ||cm||",
                        "action": "Loop",
                        "output": "res",
                        "outputto": "php",
                        "looptype": "date",
                        "loopvalue": "||dfi|| ||dti||",                        
                        "loopsqlid": "5ipc",
                        "onsuccess": "5ipc2"
                    }, {
                        "runif": "||dt|| = ||cm||",
                        "action": "Loop",
                        "output": "res",
                        "outputto": "php",
                        "looptype": "date",
                        "loopvalue": "||dfi|| ||cd||",                       
                        "loopsqlid": "5ipc",
                        "onsuccess": "5ipc2"
                    }

                ]
            }
        }, {
            "id": "5ipc",
            "name": "IP Count",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [{
                        "action": "Return",
                        "outputto": "php",
                        "output": "str",
                        "appendoutput": 1,
                        "value": " UNION ALL select DATE_FORMAT('||currentloopvalue||','%d/%m') as dt,count(*) as cnt from cmch_ip where recordstatus=1 and DATE(addate) <= '||currentloopvalue||' and (DATE(didate) > '||currentloopvalue||' or didate='0000-00-00 00:00:00' or didate IS NULL)"
                    }
                ]
            }
        }, {
            "id": "5ipc2",
            "name": "IP Table",
            "sql": {
                "action": "Get Chart",
                "outputto": "html",
                "output": "#pr4",
                "stmt": "select '' as dt,'' as cnt from cmch_ip where id='a' ||GET_str||",
                "type": "bar",
                "title": "IP Monthly #",
                "elem": "#pr4",
                "label": "dt",
                "value": "cnt",
                "legend": "Total IP"

            }
        }, {
            "id": "5evpr",
            "name": "Get Evaluation Chart",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "multistmt": [{
                        "action": "Get HTML",
                        "outputto": "html",
                        "output": "#workareaAppendix",
                        "appendoutput": 1,
                        "prepend": [
                            "<button class='mif-printer fg-blue' onclick='printHTML(&apos;workareaAppendix&apos;)'></button>",
                            "<center><img src='resource/image/cmch_logo1.png' width='400' height='60'></center>",
                            "<DIV style='margin-top:20px' class='font-ArialNarrow'><center><h5>Evaluation Chart<h5></center></DIV>"
                        ],
                        "template": [
                            "<table class='font-ArialNarrow' style='border-collapse:separate;border-spacing:15px;;margin-left:1cm;margin-right:1cm;margin-top:30px;width:80%;font-size:0.8em'>",
                            "<tr><td><b>Name:</b>||pname||</td><td></td><td><b>Patient ID:</b>||pid||</td><td><b>Age:</b>||age||</td>",
                            "<td><b>Sex:</b> ||pgender||",
                            "<tr><td><b>DOA:</b>||GET_dates_addate||</td>",
                            "<td><b>Blood Group:</b></td><td><b>HBsAg:</b></td>",
                            "<td><b>HIV:</b></td><td><b>Others:<b></td></tr>",
                            "</table>"

                        ],
                        "tbl": "cmch_ip a",
                        "fld": "a.pid,b.pname,(YEAR(CURDATE())-b.pyob) as age,a.addate,a.didate,b.pgender",
                        "join": [
                            "LEFT JOIN cmch_patient b ON a.pid= b.pid",
                            "LEFT JOIN cmch_doctors c ON a.docid=c.id"
                        ],

                        "whr": "a.id='||id||'",
                        "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast"
                    }, {
                        "action": "Get Matrix",
                        "row": "a",
                        "col": "b",
                        "val": "result",
                        "outputto": "html",
                        "output": "#workareaAppendix",
                        "appendoutput": 1,
                        "tbl": "cmch_labresult a",
                        "class": "dataTable font-ArialNarrow",
                        "style": "border:1px solid black;border-collapse:collapse;margin-left:2cm;margin-top:0.5cm;width:75%;font-size:0.8em",
                        "fld": "b.parametername as a,DATE_FORMAT(a.createdon, '%d/%m') as b,CONCAT('<center>',a.result,'</center>')as result",
                        "srt": "a.createdon,c.porder",
                        "join": [
                            "INNER JOIN cmch_labparameters b ON a.parameterid=b.id",
                            "INNER JOIN cmch_evaluation c ON a.parameterid=c.parameterid"
                        ],"limit":"2000",
                        "whr": "b.recordstatus=1 and a.pid='||pid||' and DATE(a.createdon) >=DATE('||addate||') and b.id=c.parameterid"
                    }
                ]
            }
        }, {
            "id": "5tp",
            "name": "Treatment Protocol",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "table",
                "tbl": "cmch_ip a",
                "prepend": "<button class='mif-printer fg-blue' onclick='let ids=[];$(&apos;#workareaTablebox input[type=checkbox]:checked&apos;).each(function(i,x){ids[i]=$(this).attr(&apos;id&apos;)});ids=ids.join();if(!ids){Eirene.runStmt(&apos;5tppr&apos;)}else{Eirene.runStmt(&apos;5tppr2&apos;,{IDS:ids})}'></button>",
                "fld": "a.pid,d.pname",
                "br2nl": "3,4,5,6",
                "functionfield": [{
                        "type": "checkbox",
                        "name": "5tpchk",
                        "prepend": 1,
                        "id": "'<a.id>'",
                        "caption": "Ck"
                    }, {
                        "type": "textarea",
                        "style": "line-height:1.2",
                        "value": "<c.diagnosis>",
                        "caption": "Diagnosis",
                        "showDialogOnFocus": true,
                        "onblur": "Eirene.runStmt('5dgs',{ID:'<a.id>',diagnosis:$(this).val()})"
                    }, {                       
						"type": "textarea",
						"style": "line-height:1.2",
						"value": "<c.medicare>",
						"caption": "Med Care",
						"showDialogOnFocus": true,
						"onblur": "Eirene.runStmt('5mcare',{ID:'<a.id>',medicare:$(this).val()})"                        
                    }, {
                        "type": "textarea",
                        "style": "line-height:1.2",
                        "value": "<c.medicare1>",
                        "caption": "ImportantMedicalCare",
                        "showDialogOnFocus": true,
                        "onblur": "Eirene.runStmt('5care1',{ID:'<a.id>',medicare1:$(this).val()})"
                    }, {
                        "type": "textarea",
                        "style": "line-height:1.2",
                        "value": "<c.nursecare>",
                        "caption": "NursingCare",
                        "showDialogOnFocus": true,
                        "onblur": "Eirene.runStmt('5ncare',{ID:'<a.id>',nursecare:$(this).val()})"
                    }, {                        
						"type": "textarea",
						"style": "line-height:1.2",
						"value": "<c.newlabtests>",
						"id": "newlabtests",
						"name": "newlabtests",
						"showDialogOnFocus": true,
						"onblur": "Eirene.runStmt('5nlt',{ID:'<a.id>',newlabtests:$(this).val()})"                       
                    }, {
                        "type": "icon",
                        "class": "mif-printer fg-blue",
                        "onclick": "Eirene.runStmt('tp0-tp1',{ID:'<a.id>'})",
                        "caption": "Print"
                    }
                ],
                "join": [
                    "LEFT JOIN cmch_iptreatment c ON a.id=c.ipid",                    
                    "LEFT JOIN cmch_patient d ON d.pid=a.pid"
                ],
                "header": "Patient ID,Patient Name","limit":150,
                "whr": [
                    "a.recordstatus=1", {
                        "if": "||ward|| != BLANK",
                        "then": " and a.ward='||ward||'"
                    }, {
                        "if": "||dtfrom|| != BLANK and ||dtto|| != BLANK",                        
                        "then": " and DATE(a.addate)>='||dtfrom||' and DATE(a.addate)<='||dtto||'"
                    }, {
                        "if": "||dtfrom|| != BLANK and ||dtto|| = BLANK",                        
                        "then": " and DATE(a.addate)='||dtfrom||'"
                    }, {
                        "if": "||dtfrom|| = BLANK and ||dtto|| = BLANK",                       
                        "then": " and (a.didate is NULL or a.didate='0000-00-00 00:00:00')"
                    }
                ],
                "onsuccess": "cmd:dom,fun:empty;#workareaFilter1;slow-cmd:dom,fun:hide;#workareaAppendix;slow"
            }
        }, {
            "id": "5tpnl",
            "name": "Get New Lab Result (Treatment Protocol) - HTML",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "multistmt": [{
                        "action": "Get HTML",
                        "outputto": "html",
                        "output": "labr",
                        "tbl": "cmch_labresult a",
                        "fld": "b.parametername,a.result,collectiontime,c.item",
                        "datefield": "collectiontime",
                        "join": [
                            "LEFT JOIN cmch_labparameters b ON a.parameterid=b.id",
                            "LEFT JOIN cmch_lab c ON c.id=a.labid"
                        ],
                        "template": [{
                                "if": "||previous_item|| != ||item|| and ||currentrow|| != 1",                                
                                "then": "<br><br><b>||collectiontime|| ||item||</b><br>"
                            }, {
                                "if": "||currentrow|| = 1",                                
                                "then": "<b>||collectiontime|| ||item||</b><br>"
                            },
                            " ||parametername||:||result||;"

                        ],
                        "whr": "a.pid='||pid||' and DATE(collectiontime)=CURDATE()",
                        "srt": "collectiontime,c.item,b.porder"
                    }, {
                        "action": "Save Row",
                        "outputto": "php",
                        "tbl": "cmch_ip",
                        "fld": "newlabtests",
                        "value": "||GET_labr||",
                        "fldtype": "s",
                        "command": "update",
                        "whr": "id='||ID||' ",
                        "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"

                    }
                ]
            }
        }, {
            "id": "5mcare",
            "name": "Save Medical Care(IP)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_iptreatment",
                "fld": "medicare",
                "value": "||medicare||",
                "fldtype": "s",
                "command": "update",
                "whr": "ipid='||ID||' ",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {
            "id": "5care1",
            "name": "Save Medical Care(Important-IP)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_iptreatment",
                "fld": "medicare1",
                "value": "||medicare1||",
                "fldtype": "s",
                "command": "update",
                "whr": "ipid='||ID||' ",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {
            "id": "5ncare",
            "name": "Save Nursing Care Care(IP)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_iptreatment",
                "fld": "nursecare",
                "value": "||nursecare||",
                "fldtype": "s",
                "command": "update",
                "whr": "ipid='||ID||' ",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {
            "id": "5nlt",
            "name": "Save Lab Tests(IP Treatment Protocol)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_iptreatment",
                "fld": "newlabtests",
                "value": "||newlabtests||",
                "fldtype": "s",
                "command": "update",
                "whr": "ipid='||ID||' ",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {
            "id": "5dgs",
            "name": "Save Medical Care(IP)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_iptreatment",
                "fld": "diagnosis",
                "value": "||diagnosis||",
                "fldtype": "s",
                "command": "update",
                "whr": "ipid='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {

            "id": "5lc",
            "name": "show Life Cycle",
            "sql": {
                "action": "Get Table",
                "formname": "s",
                "outputto": "html",
                "output": "app",
                "tbl": "cmch_iplifecycle",
                "fld": "lcname,details,createdon",
                "header": "Lifecycle Name, Details, Date&Time",
                "whr": "ipid='||ipid||'",
                "srt": "createdon ASC",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;slow-cmd:dom,fun:html;#workareaAppendix;||app||"
            }
        }, {
            "id": "5lcdm",
            "name": "Save Current Mark(Lifecycle)",
            "sql": {
                "action": "Save Row",

                "outputto": "php",
                "tbl": "cmch_iplifecycle",
                "fld": "ipid,lcname,details,createdby",
                "value": "||ipid||,Patient Status,||mark||,||USERID||",
                "fldtype": "s,s,s,s",
                "command": "insertorupdate",
                "whr": "ipid='||ipid||' and lcname='Patient Status'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "5lcba",
            "name": "Save Bed Allotted(Lifecycle)",
            "sql": {
                "action": "Save Row",

                "outputto": "php",
                "tbl": "cmch_iplifecycle",
                "fld": "ipid,lcname,details,createdby",
                "value": "||ID||,Bed Allotted,||bed||,||USERID||",
                "fldtype": "s,s,s,s",
                "command": "insertorupdate",
                "whr": "ipid='||ID||' and lcname='Bed Allotted'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "5lcdi",
            "name": "Save Discharge(Lifecycle)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "tbl": "cmch_iplifecycle",
                "fld": "ipid,lcname,createdby",
                "value": "||ID||,Discharged,||USERID||",
                "fldtype": "s,s,s",
                "command": "insertorupdate",
                "whr": "ipid='||ID||' and lcname='Discharged'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "5lcdic",
            "name": "Delete Discharge(LifeCycle)",
            "sql": {
                "action": "Delete Row Permanently",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_iplifecycle",
                "whr": "ipid='||ID||' and lcname='Discharged'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Delete Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Delete Failed"
            }
        },{
            "id": "5flr",
            "name": "Get Lab Report",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "multistmt": [{
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "addate",
                        "tbl": "cmch_appointment",
                        "fld": "pdate",
                        "srt": "createdon DESC",
                        "limit": "1",
                        "whr": "pid='||pid||' and recordstatus=1"
                    }
                ]
            }
        }, {
            "id": "5dfre",
            "name": "Form Reflexes (Discharge Summary) - HTML",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "multistmt": [{
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "refl",
                        "stmt": "SELECT count(reflexes) FROM cmch_ipdischarge WHERE ipid='||ID1||'"
                    }, {

                        "action": "Get Value",
                        "outputto": "php",
                        "output": "refl1",
                        "stmt": "SELECT reflexes FROM cmch_ipdischarge WHERE ipid='||ID1||'"
                    }, {
                        "runif": "||GET_refl|| = 0",
                        "action": "Return",
                        "outputto": "html",
                        "output": "reflexes",
                        "value": [
                            "<table class='font-ArialNarrow' style='line-height:1.5;border:1px solid black;border-collapse:collapse;;margin-top:10px;font-size:0.9em'><tr><th style='border:1px solid black' class='pl-2'>Reflexes</th><th style='border:1px solid black' class='pl-2'>Rt</th><th style='border:1px solid black' class='pl-2'>Lt</th></tr>",
                            "<tr><td style='text-align:left;width:100px'>Biceps</td><td style='text-align:center;width:100px'> </td><td style='text-align:center;width:100px'></td></tr>",
                            "<tr><td style='text-align:left;width:100px'>Triceps</td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td></tr>",
                            "<tr><td style='text-align:left;width:100px'>Supinator</td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td></tr>",
                            "<tr><td style='text-align:left;width:100px'>Knee</td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td></tr>",
                            "<tr><td style='text-align:left;width:100px'>Ankle</td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td></tr></table>"
                        ],
                        "onsuccess": "cmd:dom,fun:function;setValueToTextEditor;#reflexes;||reflexes||"
                    }
                ]
            }
        }, {
            "id": "5dfdx",
            "name": "Form Dexa Report (Discharge Summary) - HTML",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "multistmt": [{
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "dexa",
                        "stmt": "SELECT count(dexareport) FROM cmch_ipdischarge WHERE ipid='||ID1||'"
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "dexa1",
                        "stmt": "SELECT dexareport FROM cmch_ipdischarge WHERE ipid='||ID1||'"
                    }, {
                        "runif": "||GET_dexa|| = 0",
                        "action": "Return",
                        "outputto": "html",
                        "output": "dexareport",
                        "value": [
                            "<table class='font-ArialNarrow' style='line-height:1.5;border:1px solid black;border-collapse:collapse;;margin-top:10px;font-size:0.9em'><tr><th style='border:1px solid black' class='pl-2'>Region</th><th style='border:1px solid black' class='pl-2'>BMD</th><th style='border:1px solid black' class='pl-2'>T-SCORE</th><th style='border:1px solid black' class='pl-2'>IMPRESSION</th></tr>",
                            "<tr><td>L-Spine</td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td></tr>",
                            "<tr><td>Femoral Neck</td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td></tr>",
                            "<tr><td>Distal 1/3rd</td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td><td style='text-align:center;width:100px'></td></tr></table>"
                        ],
                        "onsuccess": "cmd:dom,fun:function;setValueToTextEditor;#dexareport;||dexareport||"
                    }
                ]
            }
        }, {
            "id": "5lrdi",
            "name": "Get Lab Result (Discharge Summary) - HTML",
            "sql": {
                "action": "Get HTML",

                "outputto": "html",
                "output": "labr",
                "tbl": "cmch_labresult a",
                "fld": "b.parametername,a.result,collectiontime,c.item",
                "datefield": "collectiontime",
                "join": [
                    "LEFT JOIN cmch_labparameters b ON a.parameterid=b.id",
                    "LEFT JOIN cmch_lab c ON c.id=a.labid"
                ],
                "parent": "div class='font-ArialNarrow'",
                "template": [{
                        "if": "||previous_item|| != ||item|| and ||currentrow|| != 1",                        
                        "then": "<br><br><b>||collectiontime|| ||item||</b><br>"
                    }, {
                        "if": "||currentrow|| = 1",                        
                        "then": "<b>||collectiontime|| ||item||</b><br>"
                    },
                    " ||parametername||:||result||;"

                ],
                "whr": "a.pid='||pid||' and DATE(c.collectiontime)>=DATE('||GET_addate||')",
                "srt": "collectiontime,c.item,b.porder",
                "onsuccess": "cmd:dom,fun:function;setValueToTextEditor;#labreport;||labr||"
            }
        }, {
            "id": "5fmdi",
            "name": "Get Medicare (Discharge Summary)",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "medicare",
                "tbl": "cmch_iptreatment",
                "fld": "medicare,medicare1",
                "parent": "div class='font-ArialNarrow'",
                "template": [
                    "<b>Regular</b><br>",
                    "||medicare||<br>",
                    "<b>Important</b><br>",
                    "||medicare1||"
                ],
                "whr": "ipid='||ipid||'",
                "onsuccess": "cmd:dom,fun:function;setValueToTextEditor;#medicare;||GET_medicare||"
            }
        }, {
            "id": "5fddi",
            "name": "Get Medicare (Discharge Summary)",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "diagnosis",
                "tbl": "cmch_iptreatment",
                "fld": "diagnosis",
                "parent": "div class='font-ArialNarrow'",
                "template": [
                    "||diagnosis||"
                ],
                "whr": "ipid='||ipid||'",
                "onsuccess": "cmd:dom,fun:function;setValueToTextEditor;#diagnosis;||GET_diagnosis||"
            }

        },
        {
            "id": "6",
            "name": "Ward Details",
            "sql": {
                "action": "Get Table",

                "formname": "wardmaster",
                "outputto": "html",
                "output": "table",
                "tbl": "cmch_wardmaster",
                "fld": "wardname,abbreviation",
                "functionfield": [{
                        "type": "group",
                        "caption": "Max Capacity",
                        "grp": [{
                                "type": "text",
                                "value": "<maxcapacity>",
                                "onblur": "Eirene.runStmt('6sipw',{ID:'<id>',maxcapacity:$(this).val()})"
                            }
                        ]
                    }, {
                        "type": "text",
                        "value": "<rate>",
                        "caption": "Rate",
                        "onblur": "Eirene.runStmt('6sipr',{ID:'<id>',rate:$(this).val()})"
                    }, {
                        "type": "group",
                        "caption": "Action",
                        "grp": [{
                                "type": "icon",
                                "class": "mif-pencil fg-blue mr-2",
                                "onclick": "edit('wardmaster','<id>')"
                            }, {
                                "type": "icon",
                                "class": "mif-cross fg-red",
                                "onclick": "Eirene.runStmt2('6delwd','ID','<id>')"
                            }
                        ]
                    }
                ],
                "header": "Ward Name,Abbreviation",
                "whr": "recordstatus=1"
            }
        }, {
            "id": "6sipw",
            "name": "Save ward (Ward Master)",
            "sql": {
                "action": "Save Row",

                "outputto": "php",
                "output": "res",
                "tbl": "cmch_wardmaster",
                "fld": "maxcapacity",
                "value": "||maxcapacity||",
                "fldtype": "n",
                "command": "update",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"

            }
        }, {
            "id": "6sipr",
            "name": "Save Rate (Ward Master)",
            "sql": {
                "action": "Save Row",

                "outputto": "php",
                "output": "res",
                "tbl": "cmch_wardmaster",
                "fld": "rate",
                "value": "||rate||",
                "fldtype": "n",
                "command": "update",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"

            }
        }, {
            "id": "6flt1",
            "name": "Ward Details",
            "sql": {
                "action": "Get Table",
                "formname": "wardmaster",
                "outputto": "html",
                "output": "table",
                "tbl": "cmch_wardmaster a",
                "fld": "a.abbreviation,IF(b.cnt is null,0,b.cnt) as cnt, a.maxcapacity",
                "functionfield": [{
                        "type": "donut",
                        "value": "<cnt/maxcapacity * 100>",
                        "bgclr": "bg-gray"
                    }, {
                        "type": "group",
                        "caption": "Action",
                        "grp": [{
                                "type": "icon",
                                "class": "mif-pencil fg-blue mr-2",
                                "onclick": "edit('wardmaster','<a.id>')"
                            }, {
                                "type": "icon",
                                "class": "mif-cross fg-red",
                                "onclick": "Eirene.runStmt2('6delwd','ID','<a.id>')"
                            }
                        ]
                    }
                ],
                "join": "LEFT JOIN(SELECT ward,count(*) as cnt FROM cmch_ip WHERE (didate is null or didate='0000-00-00 00:00:00') GROUP BY ward) b on b.ward= a.id",
                "header": "Abbreviation,Occupied,Max.Capacity",
                "whr": [
                    "recordstatus=1", {
                        "if": "||ward|| != BLANK",
                        "then": " and ward='||ward||'"
                    }
                ],
                "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:hide;#workareaFilter1;slow-cmd:dom,fun:hide;#workareaAppendix;slow"
            }
        }, {
            "id": "6a",
            "name": "Ward Details",
            "sql": {
                "action": "Get HTML",

                "outputto": "html",
                "output": "table",
                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter",
                    "elem": [{
                            "name": "f4",
                            "value": "IP List",
                            "type": "button",
                            "onclick": "Eirene.runStmt('5')",
                            "title": "List of Patient"
                        }, {
                            "name": "f5",
                            "value": "Ward",
                            "type": "button",
                            "onclick": "Eirene.runStmt('wrdmsm')",
                            "title": "Ward Details"
                        }, {
                            "name": "f1",
                            "type": "buttonspan",
                            "icon": "mif-plus fg-red",
                            "value": "",
                            "onclick": "showNewForm('wardmaster')",
                            "title": "Add Ward"
                        }, {
                            "name": "f2",
                            "value": "Ward Details",
                            "sqlid": "6",
                            "type": "button",
                            "onclick": "Eirene.runStmt('6')",
                            "title": "Ward Details"
                        }, {
                            "name": "f6",
                            "type": "button",
                            "value": "Treatment Protocol",
                            "onclick": "Eirene.runStmt('5-5tp')",
                            "title": "Ward Details"

                        }, {
                            "name": "f7",
                            "type": "button",
                            "value": "Death Certificate",
                            "onclick": "Eirene.runStmt('18')",
                            "title": "Death Certificate"

                        }
                    ]
                },
                "tbl": "cmch_wardmaster a",
                "parent": "div class='d-flex flex-wrap flex-justify-around'",
                "template": [
                    "<div class='cell'>",
                    "<div class='icon-box border bd-default' style='height:100px;'>",
                    "<div class='bg-cyan fg-white'>||Donut||</div>",
                    "<div class='content p-4'>",
                    "<div class='text-upper'>||wardname||</div>",
                    "<div class='text-upper text-bold text-lead'>||cnt||/||maxcapacity||</div>",
                    "</div>",
                    "</div></div>"
                ],

                "fld": "a.wardname,a.abbreviation,IF(b.cnt is null,0,b.cnt) as cnt, a.maxcapacity,a.id",
                "functionfield": [{
                        "type": "donut",
                        "value": "<cnt/maxcapacity * 100>",
                        "bgclr": "bg-gray",
                        "caption": "Donut",
                        "onclick": "Eirene.runStmt('6ad',{w:'<a.id>'})"

                    }
                ],
                "join": "LEFT JOIN(SELECT ward,count(*) as cnt FROM cmch_ip WHERE (didate is null or didate='0000-00-00 00:00:00') GROUP BY ward) b on b.ward= a.id",
                "whr": "a.recordstatus=1",
                "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:hide;#workareaFilter1;slow-cmd:dom,fun:hide;#workareaAppendix;slow"

            }
        }, {

            "id": "6ad",
            "name": "Ward Details",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "app",
                "tbl": "cmch_ip a",
                "fld": "a.pid,b.pname,a.bed,a.addate",
                "header": "PatientID,Patient Name,Bed,Admission Date",
                "join": "LEFT JOIN cmch_patient b ON a.pid=b.pid",
                "whr": "a.recordstatus=1 and a.ward='||w||' and (a.didate is NULL or a.didate='0000-00-00 00:00:00')",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;slow-cmd:dom,fun:html;#workareaAppendix;||app||"

            }

        }, {
            "id": "6gtwm",
            "name": "Get Ward Details",
            "sql": {
                "action": "Get Row",

                "outputto": "html",
                "output": "edit",
                "tbl": "cmch_wardmaster",
                "fld": "id,wardname,abbreviation,maxcapacity,rate",
                "whr": "id='||ID||'",
                "jsfunction": "edit1"

            }
        }, {
            "id": "6svwm",
            "name": "Save Ward Details",
            "sql": {
                "action": "Save Row",

                "outputto": "php",
                "output": "res",
                "tbl": "cmch_wardmaster",
                "fld": "wardname,abbreviation,maxcapacity,rate",
                "value": "||wardname||,||abbreviation||,||maxcapacity||,||rate||",
                "fldtype": "s,s,n,n",
                "command": "insertorupdate",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful-cmd:dom,fun:val;input[name=wardname];BLANK",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "6delwd",
            "name": "Delete Ward",
            "sql": {
                "action": "Delete Row",

                "outputto": "php",
                "output": "res",
                "tbl": "cmch_wardmaster",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Delete Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Delete Failed"
            }
        }, {
            "id": "7",
            "name": "Clinical Details",
            "sql": {
                "action": "Get Table",
                "formname": "clinicaldetails",
                "outputto": "html",
                "output": "table",
                "tbl": "cmch_clinicaldetails a",
                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter",
                    "elem": [{
                            "name": "f1",
                            "type": "buttonspan",
                            "icon": "mif-plus fg-red",
                            "value": "",
                            "onclick": "showNewForm('clinicaldetails')",
                            "title": "Add Clinical Details"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Clinical Details",
                            "onclick": "Eirene.runStmt('7')",
                            "title": "Clinical Details"
                        }
                    ]
                },
                "fld": "b.pname,a.cdate,a.bp,a.pulse,a.temperature,a.spo2,a.sugar,a.ecg",
                "functionfield": [{
                        "type": "group",
                        "caption": "Action",
                        "grp": [{
                                "type": "icon",
                                "class": "mif-pencil fg-blue mr-2",
                                "onclick": "edit('clinicaldetails','<a.id>')"
                            }, {
                                "type": "icon",
                                "class": "mif-cross fg-red",
                                "onclick": "Eirene.runStmt2('7delcd','ID','<a.id>')"
                            }
                        ]
                    }
                ],
                "join": "LEFT JOIN cmch_patient b ON b.pid=a.pid",
                "header": "Patient Name,Date,BP,Pulse,Temperature,spo2,Sugar,ECG",
                "whr": [
                    "a.recordstatus=1", {
                        "if": "||pid|| != BLANK",
                        "then": " and a.pid='||pid||'"
                    }, {
                        "if": "||attfromdate|| != BLANK and ||atttodate|| != BLANK",
                        "then": " and DATE(a.cdate)>='||attfromdate||' and DATE(a.cdate)<='||atttodate||'"
                    }, {
                        "if": "||attfromdate|| != BLANK and ||atttodate|| = BLANK",
                        "then": " and DATE(a.cdate)='||attfromdate||'"
                    }
                ],
                "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:hide;#workareaAppendix;slow"

            }
        }, {
            "id": "8",
            "name": "Billing",
            "sql": {
                "action": "Get Table",

                "formname": "billing",
                "outputto": "html",
                "output": "table",
                "tbl": "cmch_bill a",
                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter",
                    "elem": [{
                            "name": "f1",
                            "type": "buttonspan",
                            "icon": "mif-plus fg-red",
                            "value": "Item Bill",
                            "onclick": "showNewForm('billing');Eirene.runStmt('10bft')",
                            "title": "Bill"
                        },{
                            "name": "f1a",
                            "type": "button",                           
                            "value": "New Bill",
                            "onclick": "Eirene.runStmt('8lt')",
                            "title": "Bill"
                        }, {
                            "name": "f12",
                            "value": "Receipts",
                            "type": "button",
                            "onclick": "Eirene.runStmt('10phft-10ph')",
                            "title": "Bills of Today"
                        }, {
                            "name": "f8",
                            "value": "Items",
                            "type": "button",
                            "onclick": "Eirene.runStmt('9')",
                            "title": "Show Item List"
                        }, {
                            "name": "f10",
                            "value": "Bill Records",
                            "type": "button",
                            "onclick": "Eirene.runStmt('10brec')",
                            "title": "Records of Bill"
                        },{
                            "name": "f10a",
                            "value": "Pending Bills",
                            "type": "button",
                            "onclick": "Eirene.runStmt('10pndg')",
                            "title": "Pending Bill Records"
                        }, {
                            "name": "f11",
                            "value": "Advance",
                            "type": "button",
                            "onclick": "Eirene.runStmt('13');//showNewForm('advance');Eirene.runStmt('13adft')",
                            "title": "Advance"
                        }, {
                            "name": "f12",
                            "value": "Refund",
                            "type": "button",
                            "onclick": "Eirene.runStmt('14')",
                            "title": "Refund"
                        }, {
                            "name": "f13",
                            "value": "Bill Summary",
                            "type": "button",
                            "onclick": "Eirene.runStmt('8sumft-8sum',{dt:formatDate()})",
                            "title": "Summary"
                        }

                    ]
                },
                "fld": "a.bdate,c.pname,b.item,a.rate,a.quatity,a.discount,a.total",
                "functionfield": [{
                        "type": "group",
                        "grp": [{
                                "if": "a.billno IS NULL",
                                "type": "icon",
                                "class": "mif-pencil fg-blue mr-3",
                                "onclick": "edit('billing','<a.id>')"
                            }, {
                                "if": "a.billno IS NULL",
                                "type": "icon",
                                "class": "mif-cross fg-red",
                                "onclick": "Eirene.runStmt2('ditem','ID','<a.id>')"
                            }
                        ]
                    }
                ],

                "join": "LEFT JOIN cmch_item b ON b.item=a.item and b.recordstatus=1 LEFT JOIN cmch_patient c ON a.pid=c.pid",
                "header": "Date,Patient Name,Item,Rate,Quantity,Discount,Total",
                "whr": [
                    "a.recordstatus=1", {
                        "if": "||attfromdate|| != BLANK and ||atttodate|| != BLANK",
                        "then": " and DATE(a.bdate)>='||attfromdate||' and DATE(a.bdate)<='||atttodate||'"
                    }, {
                        "if": "||attfromdate|| != BLANK and ||atttodate|| = BLANK",
                        "then": " and DATE(a.bdate)='||attfromdate||'"
                    }, {
                        "if": "||attfromdate|| = BLANK and ||atttodate|| = BLANK",
                        "then": " and DATE(a.bdate)=CURDATE()"
                    }, {
                        "if": "||fcat|| = BLANK",
                        "then": " and b.category= '||fcat||'"
                    }
                ],
                "srt": "a.createdon DESC",
                "prepend": "<div class='d-flex flex-justify-around'>Date From<input type='date' id='attfromdate'></input>Date To<input type='date' id='atttodate'></input><button type='button' onclick='let df=$(&apos;#attfromdate&apos;).val();let dt=$(&apos;#atttodate&apos;).val();Eirene.runStmt(&apos;8&apos;,{attfromdate:df,atttodate:dt})' >Get</button></div>",
                "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:hide;#workareaAppendix;slow"

            }
        },
        {
            "id": "8sum",
            "name": "Bill Summary",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [{
                        "action": "Return",
                        "output": "#workareaTablebox",
                        "value": [
							{"sqlstatement":{"dtstring":"SELECT date_format('||dt||','%d-%m-%Y')"}},
                            "<div>",
                            "<button class='no-print button secondary' onclick='printHTML(&apos;workareaTablebox&apos;)'>Print</button>",
                            "</div>",
                            "<center>", {
                                "if": "||dt|| = BLANK",
                                "then": "<div><h2>||CURDATE_D_M_Y||</h2></div>",
                                "else": "<div><h2>||dtstring||</h2></div>"
                            },
                            "</center>"
                        ]
                    }, {
                        "action": "Get Table",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "tbl": "cmch_payment",
                        "fld": "paymentmethod,IF(paymentmethod='Cash',CONCAT('<span id=&apos;8sum_cash&apos;>',SUM(amount),'</span>'),SUM(amount))",
                        "whr": [{
                                "if": "||dt|| = BLANK",
                                "then": " DATE(createdon)=CURDATE()",
                                "else": " DATE(createdon)='||dt||'"
                            }
                        ],
                        "grp": "paymentmethod",
                        "header": "Mode,Amount",
                        "union": [
                            " UNION ALL SELECT '<b>Total</b>',SUM(amount)",
                            " FROM cmch_payment WHERE", {
                                "if": "||dt|| = BLANK",
                                "then": " DATE(createdon)=CURDATE()",
                                "else": " DATE(createdon)='||dt||'"
                            },
                            " UNION all SELECT '<b>Total (Non Cash)</b>',SUM(amount)",
                            " FROM cmch_payment WHERE paymentmethod <>'Cash' and ", {
                                "if": "||dt|| = BLANK",
                                "then": " DATE(createdon)=CURDATE()",
                                "else": " DATE(createdon)='||dt||'"
                            }
                        ],
                        "prepend": "<h2>Receipts</h2>",
                        "class": "eirene-table dataTable",
                        "datatable": false,
                        "responsive": false,
						"displayfunctionbutton":false
                    }, {
                        "action": "Get Matrix",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "row": "name",
                        "col": "category",
                        "val": "tot",
                        "horizontalsum": 1,
                        "verticalsum": 1,
                        "class": "eirene-table dataTable",
						"stmt":[
							"select cc.name,aa.category,sum(aa.billtotal) as tot from ",
								"(select a.billno,a.category,a.doctorid,sum(a.total) as billtotal from cmch_bill a",
									"inner join cmch_printbill b on a.billno=b.billno ",
									"where date(b.createdon)=",
									{"if": "||dt|| = BLANK","then": "CURDATE()",
										"else": "'||dt||'"
									},
								" group by a.billno,a.doctorid,a.category) aa",							
							"INNER JOIN cmch_doctors cc on aa.doctorid=cc.id",
							"group by cc.name,aa.category"
                        ],
						"tbl": "cmch_printbill a",
                        "join": [
                            "INNER JOIN cmch_bill b ON a.billno=b.billno",                            
                            "INNER JOIN cmch_doctors d ON b.doctorid=d.id"
                        ],
                        "fld": "d.name,b.category,SUM(b.total) as tot",
                        "whr": [
                        ],
                        "grp": "d.name,b.category",
                        "prepend": "<h2 class='mt-3'>Bills</h2>",
                        "header": "",
                        "class": "eirene-table dataTable",
						"datatable": false,
                        "responsive": false
                    }, {
                        "action": "Get Matrix",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "tbl": "cmch_advance a",
                        "fld": "b.fullname,a.paymentmethod,SUM(a.advance) as tot",
                        "grp": "b.fullname,a.paymentmethod",
						"join":[
							"INNER JOIN eirene_users b ON b.id=a.createdby"
						],                        
                        "whr": [{
                                "if": "||dt|| = BLANK",
                                "then": " DATE(a.createdon)=CURDATE()",
                                "else": " DATE(a.createdon)='||dt||'"
                            }
                        ],
                        "row": "fullname",
                        "col": "paymentmethod",
                        "val": "tot",
                        "horizontalsum": 1,
                        "verticalsum": 1,
                        "prepend": "<h2 class='mt-3'>Advance</h2>",
                        "class": "eirene-table dataTable",
                        "datatable": false,
                        "responsive": false
                    }, {
                        "action": "Get Table",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "tbl": "cmch_refund a",
                        "fld": "b.fullname,SUM(a.refund)",
						"join":"INNER JOIN eirene_users b ON b.id=a.createdby",
                        "whr": [{
                                "if": "||dt|| = BLANK",
                                "then": " DATE(a.createdon)=CURDATE()",
                                "else": " DATE(a.createdon)='||dt||'"
                            }
                        ],
						"grp":"b.fullname",
                        "header": "Name,Refund Amount",
						"vsum":"2",
                        "prepend": "<h2 class='mt-3'>Refund</h2>",
                        "class": "eirene-table dataTable",
                        "datatable": false,
                        "responsive": false,
						"displayfunctionbutton":false
                    }, {
                        "action": "Get Matrix",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "prepend": "<h2>Fund Summary</h2>",
						"colsource":"SELECT DISTINCT paymentmethod FROM cmch_payment",
                        "aggregatefunction":"SUM",
						"col": "paymentmethod",
                        "row": "fullname",
                        "val": "amount",
                        "tbl": "cmch_payment a",
                        "fld": "b.fullname,a.paymentmethod,SUM(a.amount) amount",
                        
                        "union": [
                            "UNION ALL select d.fullname,'Refund',SUM(c.refund) FROM cmch_refund c LEFT JOIN eirene_users d ON c.createdby=d.id WHERE ", {
                                "if": "||dt|| = BLANK",
                                "then": " DATE(c.createdon)=CURDATE()",
                                "else": " DATE(c.createdon)='||dt||'"
                            },
                            "group by d.fullname"
                        ],
                        "join": "INNER JOIN eirene_users b ON a.createdby=b.id",
                        "whr": [{
                                "if": "||dt|| = BLANK",
                                "then": " DATE(a.createdon)=CURDATE()",
                                "else": " DATE(a.createdon)='||dt||'"
                            }
                        ],
                        "grp": "b.fullname,a.paymentmethod",
						"vsum":true,
                        "append": "<b>NB: Refund to be deducted from cash sum</b>",
                        "class": "eirene-table dataTable",
                        "datatable": false,
                        "responsive": false
                    },{
						"action":"Get Table",
						"output": "#workareaTablebox",
                        "appendoutput": 1,
                        "prepend": "<h2>Pending Payment Summary</h2>",
						"stmt":[
							"select aa.department,aa.totalbill,bb.totalpaid,IF(bb.totalpaid is null,(aa.totalbill),(aa.totalbill-bb.totalpaid))as pending FROM ",
								"((select c.department,sum(a.total) as totalbill FROM cmch_bill a ",
									"INNER JOIN cmch_printbill b ON a.billno=b.billno ",
									"INNER JOIN cmch_patient c ON b.pid=c.pid ",
									"WHERE a.billno is not null and date(b.createdon)=",
									{"if": "||dt|| = BLANK","then": " CURDATE()","else": " '||dt||'"},
									"group by c.department",
								") aa",
								"LEFT JOIN (",
									"select c.department,sum(a.amount) as totalpaid FROM cmch_payment a ",
									"INNER JOIN cmch_printbill b ON a.billno=b.billno",
									"INNER JOIN cmch_patient c ON c.pid=b.pid",
									"WHERE date(a.createdon)= ",
									{"if": "||dt|| = BLANK","then": " CURDATE()","else": " '||dt||'"},
									"group by c.department",								
								") bb ON aa.department=bb.department)",							
							"group by aa.department"
						],
						"header":"Department,Total Bill,Total Paid,Pending",
						"vsum":"2,3,4",
						"class": "eirene-table dataTable",
                        "datatable": false,
                        "responsive": false,
						"displayfunctionbutton":false
					}
                ]
            }

        }, {
            "id": "8sumft",
            "name": "Billing Summary Filter",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "demo",
                "value": "",

                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter1",
                    "elem": [{
                            "name": "f1",
                            "type": "datepicker",
                            "id": "8sumftdt",
                            "value": "||CURDATE||"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Get",
                            "onclick": "Eirene.runStmt('8sum',{dt:$('#8sumftdt').val()})"
                        }
                    ]
                },
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix1;fast"
            }

        }, {
            "id": "8gtbl",
            "name": "Get bill item Item",
            "sql": {
                "action": "Get Row",

                "outputto": "html",
                "output": "edit",
                "tbl": "cmch_bill",
                "fld": "id,billno,bdate,pid,item,category,rate,quatity,discount,total",
                "whr": "id='||ID||'",
                "jsfunction": "edit1"

            }
        }, {
            "id": "ditem",
            "name": "Delete bill Item",
            "sql": {
                "action": "Delete Row",

                "outputto": "php",
                "output": "res",
                "tbl": "cmch_bill",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Delete Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Delete Failed"
            }
        }, {
            "id": "8dept",
            "name": "Get department",
            "sql": {
                "action": "Get Value",
                "outputto": "php",
                "output": "dept",
                "tbl": "eirene_meta",
                "fld": "pdata",
                "whr": "recordstatus=1 and pname='CMCH Department (Bills)'"
            }
        }, {
            "id": "8svbl",
            "name": "Save Bill",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_bill",
                "fld": "bdate,pid,item,category,rate,quatity",
                "value": "NOW(),||pid||,||item||,||category||,||rate||,||quatity||",
                "fldtype": "n,s,s,s,n,n",
                "command": "insertorupdate",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful-cmd:dom,fun:val;input[name=total];BLANK-8dept-10apd-8svbla",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "8svbla",
            "name": "Total Bill",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "#workareaAppendix",
                "tbl": "cmch_bill a",

                "append": [
                    "<div><select id=appdate>||GET_appdate||</select>",
                    "<select id='department' values='||GET_dept||' class='select0'></select>",
                    "<button onclick='let ids=[];$(&apos;#workareaAppendix table tbody input[type=checkbox]:checked&apos;).each(function(i,x){ids[i]=$(this).attr(&apos;id&apos;)});ids=ids.join();if(!ids){showToast(&apos;Select Bill Items&apos;,&apos;alert&apos;,5000);return false;} Eirene.runStmt(&apos;8gens1&apos;,{pid:&apos;||pid||&apos;,IDS:ids,paystatus:$(&apos;#paystatus&apos;).val(),appid:$(&apos;#appdate&apos;).val(),department:$(&apos;#department&apos;).val()},$(this).hide())'>Generate</button></div>",
                    "<script>convertSelect('#workareaAppendix');</script>"
                ],
                "fld": "CONCAT('<input type=checkbox data-role=check name=fldchk value=',a.total,' id=',a.id,' onclick=\\\"let sum=0;$(&apos;input[type=checkbox][name=fldchk]:checked&apos;).each(function(){sum+=parseInt($(this).attr(&apos;value&apos;));});showToast(&apos;Total: &apos;+sum,&apos;warning&apos;,5000);\\\" />') as chk,a.item,a.bdate,a.quatity,a.total",
                "header": [
                    "<input type='checkbox' name='chk'; id='fld' onclick='let chk=this.checked;if(chk){$(&apos;input[type=checkbox][name=fldchk]&apos;).prop(&apos;checked&apos;,true);}else{$(&apos;input[type=checkbox][name=fldchk]&apos;).prop(&apos;checked&apos;,false)} let sum=0;$(&apos;input[type=checkbox][name=fldchk]:checked&apos;).each(function(){sum+=parseInt($(this).attr(&apos;value&apos;));});showToast(&apos;Total: &apos;+sum,&apos;warning&apos;,5000);' />",
                    "Item", "Date", "Quantity", "Amount", "Action"
                ],
                "functionfield": [{
                        "type": "group",
                        "caption": "Action",
                        "grp": [{
                                "type": "icon",
                                "class": "mif-pencil fg-blue mr-2",
                                "onclick": "edit('billing','<a.id>')"
                            }, {
                                "type": "icon",
                                "class": "mif-cross fg-red",
                                "onclick": "Eirene.runStmt2('10del','ID','<a.id>')"
                            }
                        ]
                    }
                ],
                "vsum": "5",
                "serialno": true,
                "join": "LEFT JOIN cmch_printbill b ON b.billno=a.billno",
                "whr": "a.recordstatus=1 and a.billno is null and a.pid='||pid||'",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;slow"
            }
        }, {
            "id": "8gens1",
            "name": "Create PrintBill Record",
            "sql": {
				"action":"Return","outputto":"php",
                "output":"res",				
				"value":[
					{"call":"pbsv","pid":"||pid||","appid":"||appid||","department":"||department||"},
					{"sqlstatement": {
						"a": "UPDATE cmch_patient SET department='||department||' WHERE pid='||pid||'",
						"billno": "SELECT max(billno)+1 FROM cmch_printbill",
						"bno1": "UPDATE cmch_printbill SET billno=||billno|| WHERE id='||LASTINSERTID||'",						
						"doctorid": "SELECT doctor FROM cmch_appointment WHERE pid='||pid||' ORDER BY createdon desc limit 1",
						"updatebill": "UPDATE cmch_bill SET billno=||billno||, doctorid='||doctorid||' WHERE FIND_IN_SET(id,'||IDS||')>0",
						"pname":"SELECT pname FROM cmch_patient WHERE pid='||pid||'",
						"xray":"INSERT INTO cmch_xray (id,billno,item,createdby,billitemid) SELECT UUID(),billno,item,'||USERID||',id FROM cmch_bill WHERE category='Radiology' and billno=||billno||",
						"lab":"INSERT INTO cmch_lab (id,billno,item,createdby,billitemid,status) SELECT UUID(),billno,item,'||USERID||',id,0 FROM cmch_bill WHERE (category='Lab' or category ='Thyrocare Lab') and billno=||billno||"
					}},
					{"call":"10prbl"}
				],                        
				"onsuccess": "cmd:dom,fun:showtoast;success;Bill Generated-cmd:dom,fun:empty;#workareaTablebox;fast"
			}           
        }, {
            "id": "10prbl",
            "name": "Print Bil(Record)",
            "sql": {
                "action": "Return",
                "outputto": "html",
                "output": "#workareaAppendix",
                "value": [
					{"sqlstatement":{
						"patient":"SELECT pname,pmobile,department FROM cmch_patient WHERE pid='||pid||'",
						"bill":"SELECT DATE_FORMAT(createdon,'%d-%m-%Y') as billdate,department,appid FROM cmch_printbill WHERE billno='||billno||'",
						"appcnt":"SELECT COUNT(*) FROM cmch_appointment WHERE id='||bill_appid||'",
						"appointment":"SELECT a.pcase,b.name FROM cmch_appointment a LEFT JOIN cmch_doctors b ON a.doctor=b.id WHERE a.id='||bill_appid||'",
						"paidamt":"SELECT if(sum(amount)is null,0,sum(amount)) FROM cmch_payment WHERE billno='||billno||'",
						"billamt":"SELECT if(sum(total)is null,0,sum(total)) FROM cmch_bill WHERE billno='||billno||'"
					}},
					{"call":"pbinfo","outputto":"php","output":"billinfo"},
					{"call":"pddtls","outputto":"php","output":"paidinfo","datatable":false,"class":"dataTable","thclass":"font-ArialNarrow","thstyle":"font-size:0.7em","tdstyle":"font-size:0.7em","tdclass":"font-ArialNarrow","displayfunctionbutton":false},
					{"call":"bitem","outputto":"php","output":"billitems","datatable":false,"class":"dataTable","thclass":"font-ArialNarrow","thstyle":"font-size:0.7em","tdstyle":"font-size:0.7em","tdclass":"font-ArialNarrow","displayfunctionbutton":false},
                    "<button class='mif-print fg-blue' onclick='printHTML(&apos;printbill&apos;)'></button>",
					"<div id='printbill' class='font-ArialNarrow m-2'>",
						"<div id='printbill_patientinfo'>||billinfo||</div>",
						"<div class='font-ArialNarrow' style='font-size:0.7em'><b>A. Billing Items</b></div>",
						"<div id='printbill_billitems'>||billitems||</div>",
						"<div class='font-ArialNarrow' style='font-size:0.7em'><b>B. Payment Details</b></div>",
						"<div id='printbill_paymentinfo'>||paidinfo||</div>",
						"<div class='row mt-4; font-ArialNarrow' style='font-size:0.7em'>",
							"<div class='cell'>Prepared By</div>",
							"<div class='cell'>Checked By</div>",
						"</div>",
					"</div>",					
					{"if":"||paidamt|| < ||billamt||","then":[
						"<div>",
						{"run":{"action":"GetForm","getform":"cmch_payment 0","outputto":"php","output":"paymentform"}},
						"||paymentform||",						
						"</div>"
						]
					}
					
                ],
                "onsuccess": "cmd:dom,fun:function;printHTML;printbill-cmd:dom,fun:show;#workareaAppendix;fast"
            }
        },{
            "id": "10",
            "name": "Get Bill - HTML",
            "sql": {                
				"action": "Return",
				"outputto": "html",
				"output": "#printbill_2",
				"value": [
					"<center><img src='resource/image/cmch_logo1.png' width='500' height='70'>",
					"<div>Bill No. :||billno||</div></center>",
					"<center>",
					"<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:auto;margin-right:auto;font-size:0.7em'>",
					"<tr><td style='border:1px solid black' class='p-1'><b>Patient ID</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pid||</td><td style='border:1px solid black' class='p-1'><b>Name</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||patient_pname||</td></tr>",
					"<tr><td style='border:1px solid black' class='p-1'><b>Date</b></td><td style='border:1px solid black' class='p-1'>||bill_billdate||</td><td style='border:1px solid black' class='p-1'><b>Mobile No.</b></td><td style='border:1px solid black' class='p-1'>||patient_pmobile||</td></tr>",
					"<tr><td style='border:1px solid black' class='p-1'><b>Case Type</b></td><td style='border:1px solid black' class='p-1'>||appointment_pcase||</td><td style='border:1px solid black' class='p-1'><b>Doctor</b></td><td style='border:1px solid black' class='p-1'>||appointment_name||</td></tr>",
					"<tr><td style='border:1px solid black' class='p-1'><b>Department</b></td><td style='border:1px solid black' class='p-1'>||bill_department||</td><td style='border:1px solid black' class='p-1'></td><td style='border:1px solid black' class='p-1'></td></tr>",
					"</table></center>"
				],
				"onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast"
			}            
        }, {
            "id": "10est",
            "name": "Get Estimate Bill",
            "sql": {
                "action": "MULTISTMT",
                "output": "#workareaAppendix",
                "multistmt": [ {
                        "action": "Return",
                        "output": "#workareaAppendix",
						"prerun":[
							{"sqlstatement":{
									"patient":"SELECT a.pname,a.pmobile,b.addate,DATE_FORMAT(NOW(),'%d-%m-%Y')as edate FROM cmch_patient a INNER JOIN cmch_ip b ON a.pid=b.pid WHERE a.pid='||pid||' and b.didate is null ORDER BY b.addate DESC LIMIT 1"
							}}
						],
                        "value": [
                            "<button class='mif-printer fg-blue no-print' onclick='printHTML(&apos;workareaAppendix&apos;)'></button>",
                            "<div>",
                            "<center><img src='resource/image/cmch_logo1.png' width='500' height='70'></center>",
                            "</div>",
                            "<div class='font-ArialNarrow',style='font-size:30px'>",
                            "<center><h5 class='font-ArialNarrow'>Bill Summary</h5><center>",
                            "</div>",
                            "<div class='font-ArialNarrow' style='font-size:0.7em'>",
                            "<center>||GET_patient_edate||<center>",
                            "</div>",
                            "<div style='color:black'>"
                        ]
                    }, {
                        "action": "Get Table",
                        "outputto": "html",
                        "output": "#workareaAppendix",
                        "appendoutput": 1,
                        "tbl": "cmch_bill a",
                        "fld": "a.bdate,a.item,a.quatity,a.discount,a.total",
                        "header": "Date,Item,Quantity,Discount,Amount",
                        "class": "eirene-table dataTable mt-3 font-ArialNarrow",
                        "style": "color:black",
                        "union": "UNION ALL SELECT '','','',CONCAT('<b>',(SELECT sum(discount) FROM cmch_bill WHERE recordstatus=1 and billno is null and pid='||pid||'),'</b>'),CONCAT('<b>',(SELECT sum(total) FROM cmch_bill WHERE recordstatus=1 and billno is null and pid='||pid||'),'</b>')",
                        "serialno": true,
                        "datatable": false,
						"displayfunctionbutton":false,
                        "whr": "a.recordstatus=1 and a.billno is null and a.pid='||pid||'",
                        "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast",
                        "prepend": "<table class='eirene-table dataTable font-ArialNarrow' style='color:black'><tr><td>||pid||</td><td>||GET_patient_pname||</td><td>Mob. ||GET_patient_pmobile||</td></tr><tr><td>Admission Date</td><td>||GET_patient_addate||</td><td></td></tr></table><h6 class='font-ArialNarrow'>Bill Item</h6>"
                    }, {
                        "action": "Get Table",
                        "outputto": "html",
                        "output": "#workareaAppendix",
                        "appendoutput": 1,
                        "tbl": "cmch_advance a",
                        "fld": "a.createdon,a.paymentmethod,a.advance,a.balance",
                        "vsum": "3,4",
                        "serialno": true,
                        "datatable": false,
						"displayfunctionbutton":false,
                        "prepend": "<h6 class='font-ArialNarrow'>Advance Statement</h6>",
                        "class": "eirene-table dataTable font-ArialNarrow",
                        "style": "color:black",
                        "header": "Date,Payment Mode,Amount,Balance",
                        "whr": "a.recordstatus=1 and DATE(a.createdon)>=DATE('||patient_addate||') and a.pid='||pid||'"
                    }, {
                        "action": "Get Table",
                        "outputto": "html",
                        "output": "#workareaAppendix",
                        "appendoutput": 1,
                        "tbl": "cmch_printbill a",
                        "join": [
                            "INNER JOIN (select billno,SUM(total) total FROM cmch_bill GROUP BY billno) b ON b.billno=a.billno",
                            "LEFT JOIN (select billno,SUM(amount) amount FROM cmch_payment GROUP BY billno) d ON d.billno=a.billno"
                        ],
                        "fld": "a.createdon,a.billno,b.total as billamt,IF(d.amount is null,0,d.amount) as paid",
                        "serialno": true,
                        "datatable": false,
						"displayfunctionbutton":false,
                        "whr": "a.pid='||pid||' and a.recordstatus=1 and DATE(a.createdon)>=DATE('||GET_patient_addate||') having paid < billamt",
                        "limit": "3000",
                        "class": "font-ArialNarrow eirene-table dataTable",
                        "style": "color:black",
                        "srt": "a.billno DESC",
                        "vsum": "3,4",
                        "prepend": "<h6 class='font-ArialNarrow'>Pending Bills</h6>",
                        "header": "Date,BIll No.,Total Bill,Total Paid"
                    }, {
                        "action": "Get HTML",
                        "outputto": "html",
                        "output": "#workareaAppendix",
                        "appendoutput": 1,
						"prerun":[
							{"sqlstatement":
								{
									"billitemsum":"SELECT IF(SUM(total) is null,0,SUM(total)) as billsum FROM cmch_bill WHERE recordstatus=1 and billno is null and pid='||pid||'",
									"pendingbillsum":"SELECT IF(sum(b.total - IF(d.amount is null,0,d.amount)) is null,0,sum(b.total - IF(d.amount is null,0,d.amount))) as paid FROM cmch_printbill a INNER JOIN (select billno,SUM(total) total FROM cmch_bill GROUP BY billno) b ON b.billno=a.billno LEFT JOIN (select billno,SUM(amount) amount FROM cmch_payment GROUP BY billno) d ON d.billno=a.billno where a.pid='||pid||' and a.recordstatus=1 and DATE(a.createdon)>=DATE('||GET_patient_addate||')",
									"advancebalance":"SELECT IF(sum(balance) is not null,sum(balance),0) FROM cmch_advance WHERE recordstatus=1 and pid='||pid||' and DATE(createdon)>=DATE('||GET_patient_addate||') ",
									"grandtotal":"SELECT (||billitemsum|| + ||pendingbillsum||)",
									"due":"SELECT ||grandtotal||-||advancebalance||",
									"due1":"SELECT IF(||due||<0,'0 (||due||)',||due||)"
								}
							}
						],
                        "stmt": "SELECT ||billitemsum|| as billitemsum,||pendingbillsum|| as pendingbillsum,||advancebalance|| as advancebalance,'||due1||' as due,||grandtotal|| as grandtotal",
                        "parent": "table class='eirene-table dataTable font-ArialNarrow' style='color:black'><thead><tr><th>Item</th><th>Amount</th></tr></thead><tbody",
                        "prepend": "<h6 class:'font-ArialNarrow'>Summary</h6>",
                        "template": [
                            "<tr>",
                            "<td>Bill Item Total</td><td>||billitemsum||</td>",
                            "</tr>",
                            "<tr>",
                            "<td>Pending Bill Total</td><td>||pendingbillsum||</td>",
                            "</tr>",
                            "<tr>",
                            "<td>Advance Balance Total</td><td>||advancebalance||</td>",
                            "</tr>",
                            "<tr>",
                            "<td>Due</td><td>||due||</td>",
                            "</tr>",
                            "<tr>",
                            "<td><b>Grand Total</b></td><td>||grandtotal||</td>",
                            "</tr>",
                            "</tbody>"
                        ],
                        "onsuccess": "cmd:dom,fun:function;printHTML;workareaAppendix"
                    }, {
                        "action": "Return",
                        "output": "#workareaAppendix",
                        "appendoutput": 1,
                        "value": "</div>"
                    }
                ]
            }
        }, {
            "id": "10prt",
            "name": "Print Bill Button",
            "sql": {
                "action": "Return",
                "output": "#printbill_1",
                "outputto": "html",
                "value": "<button style='margin-right:128px' type='buttonspan' class='mif-printer fg-blue' onclick='printHTML(&apos;printbill_2&apos;)'></button>"

            }
        }, {
            "id": "10pd",
            "name": "Get Paid Details - HTML",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "#printbill_2",
                "appendoutput": 1,"datatable":false,
				"vsum":"3","displayfunctionbutton":false,
				"class":"font-ArialNarrow .eirene-table-thleftaligh",
				"style":"margin-left: auto;margin-right:auto;width:80%;font-size:0.7em",                
				"tbl": "cmch_payment",
                "fld": "DATE_FORMAT(createdon,'%d-%m-%Y'),paymentmethod,amount",
				"header":"Date,Mode,Amount",                
                "whr": "recordstatus=1 and billno='||billno||'",
                "append": "<div class='row mt-4; font-ArialNarrow' style='font-size:0.7em'><div class='cell'>Prepared By</div><div class='cell'>Checked By</div></div>"
            }
        }, {
            "id": "10a",
            "name": "Get item Bill - HTML",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#printbill_2",
                "appendoutput": 1,
                "tbl": "cmch_bill",
                "fld": "item,rate,quatity,(rate*quatity) as amount,discount,total",
                "union": [
                    "SELECT '','','','','<b>Grand Total<b>',CONCAT('<div id=10abilltotal >',sum(total),'</div>') ",
                    "FROM cmch_bill ",
                    "WHERE recordstatus=1 and ", {
                        "if": "||GET_billno|| > 0",
                        "then": " billno='||GET_billno||'",
                        "else": " billno='||billno||'"
                    }
                ],
                "parent": "TABLE style='margin-left: auto;margin-right:auto;margin-top:0.5cm;font-size:0.7em;width:80%;'><thead><tr><TH style='text-align:left;'>Item</TH><TH style='text-align:left;'>Rate</TH><TH style='text-align:left;'>Quantity</TH><TH style='text-align:left;'>Amount</TH><TH style='text-align:left;'>Discount</TH><TH style='text-align:left;'>Net</TH></TR",
                "template": "<TR><TD style='text-align:left;'> ||item||</TD><TD style='text-align:left;'> ||rate||</TD><TD style='text-align:left;'>||quatity||</TD><TD style='text-align:left;'> ||amount||</TD><TD style='text-align:left;'> ||discount||</TD><TD style='text-align:left;'>||total||</TD></TR>",
                "whr": [
                    "recordstatus=1", {
                        "if": "||GET_billno|| > 0",
                        "then": " and billno='||GET_billno||'",
                        "else": " and billno='||billno||'"
                    }
                ],
                "append": "<div style='text-align:left;font-size:0.7em'><span><b>Figure: </b></span><span id='10abilltotfigure'></span></div><script>$('#10abilltotfigure').html(ConvertNumberToWords($('#10abilltotal').text()));</script>"

            }
        }, {
            "id": "10c",
            "name": "Delegate for BillNo",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "billno",
                "value": "||billno||"
            }
        }, {
            "id": "10d",
            "name": "Delegate for Paystatus",
            "sql": {
                "action": "Get Value",
                "outputto": "php",
                "output": "paystatus",
                "tbl": "cmch_printbill",
                "fld": "paystatus",
                "whr": "billno=||GET_billno||"
            }
        }, {
            "id": "10e",
            "name": "Advance balance",
            "sql": {
                "action": "Get Row",
                "outputto": "html",
                "output": "advbalance",
                "tbl": "cmch_advance",
                "fld": "id,balance",
                "whr": "pid='||pid||' and balance>0 or (pid='||Get_pid||' and balance>0)",
                "srt": "createdon DESC",
                "limit": "1"
            }
        }, {
            "id": "10f",
            "name": "Delegate for pid",
            "sql": {
                "action": "Get Value",
                "outputto": "php",
                "output": "pid",
                "tbl": "cmch_printbill",
                "fld": "pid",
                "whr": "billno=||billno||",
                "sqlstatement": {
                    "nextreceiptno": "SELECT max(receiptno)+1 FROM cmch_payment"
                }
            }
        },
        {
            "id": "10dept",
            "name": "Get department",
            "sql": {
                "action": "Get Value",
                "outputto": "php",
                "output": "dept",
                "tbl": "eirene_meta",
                "fld": "pdata",
                "whr": "recordstatus=1 and pname='CMCH Department (Bills)'"
            }
        }, {
            "id": "10gb",
            "name": "Generate Patient(Bill)",
            "sql": {
                "action": "Return",

                "outputto": "php",
                "output": "demo",

                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter1",
                    "elem": [{
                            "name": "f1",
                            "type": "text",
                            "icon": "metro-input",
                            "id": "pid",
                            "value": "||pid||",
                            "placeholder": "PID"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Get",
                            "onclick": "Eirene.runStmt('10tb-10apd-10dept-10gb',{pid:$('#pid').val()})"
                        }, {
                            "name": "f3",
                            "type": "select",
                            "class": "mr-2",
                            "title": "App Date",
                            "id": "appdate",
                            "option": "SELECT id,DATE(pdate) FROM cmch_appointment WHERE pid='||pid||' ORDER BY pdate DESC LIMIT 5"
                        },
                        {
                            "name": "f7",
                            "type": "button",
                            "value": "Estimate",
                            "onclick": "Eirene.runStmt('10est',{pid:$('#pid').val()})"
                        }, {
                            "name": "f5",
                            "type": "select",
                            "id": "department",
                            "option": "SELECT pdata FROM eirene_meta WHERE pname='CMCH Department (Bills)'",
                            "commaseperatedvalue": true

                        }, {
                            "name": "f6",
                            "type": "button",
                            "value": "Generate Bill",
                            "onclick": "let ids=[];$('#workareaTablebox table tbody input[type=checkbox]:checked').each(function(i,x){ids[i]=$(this).attr('id')});ids=ids.join();if(!ids){showToast('Select Bill Items','alert',5000);return false;} Eirene.runStmt(&apos;8gens1&apos;,{pid:$(&apos;#pid&apos;).val(),IDS:ids,appid:$(&apos;#appdate&apos;).val(),department:$(&apos;#department&apos;).val()},$(this).hide())"
                        }
                    ]
                },
                "onsuccess": "cmd:dom,fun:show;#workareaFilter1;fast"

            }
        }, {
            "id": "10del",
            "name": "Delete Bill Item (Permanently)",
            "sql": {
                "action": "Delete Row Permanently",
                "outputto": "php",
                "tbl": "cmch_bill",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Deleted Sucessfully",
                "onfailure": "cmd:dom,fun:showtoast;alert;Delete Failed"
            }
        }, {
            "id": "10bft",
            "name": "Filter Patient(Bill)",
            "sql": {
                "action": "Return",

                "outputto": "php",
                "output": "demo",
                "value": "",

                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter1",
                    "elem": [{
                            "name": "f1",
                            "type": "text",
                            "id": "pid",
                            "icon": "mr-2"
                        }, {
                            "name": "f2",
                            "type": "button",

                            "value": "Get",
                            "onclick": "Eirene.runStmt('10tb-10apd-10dept-10gb',{pid:$('#pid').val()})"
                        }
                    ]
                },
                "onsuccess": "cmd:dom,fun:show;#workareaFilter1;fast"
            }
        }, {
            "id": "10apd",
            "name": "Get Appoinment Date(Printbill)",
            "sql": {
                "action": "Get Dropdown",
                "outputto": "php",
                "output": "appdate",
                "tbl": "cmch_appointment",
                "fld": "id,DATE(pdate)",
                "srt": "createdon DESC",
                "limit": "5",
                "whr": "recordstatus=1 and pid='||pid||'"
            }
        }, {
            "id": "10tot",
            "name": "Total Amount(WorkareaAppendix)",
            "sql": {
                "action": "Return",
                "outputto": "html",
                "output": "#printbill_3",
                "value": ["<div class='row' id='billpaymode'>",
                    "<div class='cell'>Cash:</div>",
                    "<div class='cell'><input type='text' id='cash' placeholder='Amount'/></div>",
                    "<div class='cell'><button onclick='let sum=$(&apos;#10abilltotal&apos;).text();let paid=$(&apos;#10pdpaidtotal&apos;).text();if(!paid) paid=0;sum=parseFloat(sum)-parseFloat(paid);let pay=$(&apos;#cash&apos;).val();if(!pay){showToast(&apos;Empty Value&apos;,&apos;alert&apos;,5000);return false;}if(parseFloat(pay)>parseFloat(sum)){showToast(&apos;Payment more than bill&apos;,&apos;alert&apos;,5000);return false;}Eirene.runStmt(&apos;10f-10pay-10c-10d-10-10a-10pd-10e-10tot&apos;,{pid:&apos;||pid||&apos;,paymentmethod:&apos;Cash&apos;,amount:$(&apos;#cash&apos;).val(),billno:&apos;", {
                        "if": "||GET_billno|| > 0",
                        "then": " ||GET_billno||",
                        "else": " ||billno||"
                    },
                    "&apos;})'>Pay</button></div>",
                    "</div><div class='row'>", {
                        "if": "||GET_advbalance_balance|| > 0 and ||billno|| > 0",
                        "then": "<div class='cell'>Advance: (Balance:||GET_advbalance_balance||)</div><div class='cell'><input type='number' id='advance' max='||GET_advbalance_balance||' placeholder= Max:||GET_advbalance_balance||></div><div class='cell'><button onclick='let sum=$(&apos;#10abilltotal&apos;).text();let paid=$(&apos;#10pdpaidtotal&apos;).text();if(!paid) paid=0;sum=parseFloat(sum)-parseFloat(paid);let pay=$(&apos;#advance&apos;).val();if(parseFloat(pay)>parseFloat(sum)){showToast(&apos;Payment more than bill&apos;,&apos;alert&apos;,5000);return false;}if(parseFloat(pay)>||GET_advbalance_balance||){showToast(&apos;Payment more than CMCHWallet&apos;,&apos;alert&apos;,5000);return false;}Eirene.runStmt(&apos;10f-10pay1-10paya-10c-10d-10-10a-10pd-10e-10tot&apos;,{pid:&apos;||pid||&apos;,paymentmethod:&apos;CMCHWallet&apos;,amount:$(&apos;#advance&apos;).val(),billno:&apos;||billno||&apos;,advanceid:&apos;||GET_advbalance_id||&apos;,balance:&apos;||GET_advbalance_balance||&apos;})'>Pay</button></div>"
                    },
                    "</div>",
                    "<div class='row'>",
                    "<div class='cell'>POS:</div>",
                    "<div class='cell'><input type='text' id='pos' placeholder='Amount'/></div>",
                    "<div class='cell'><button onclick='let sum=$(&apos;#10abilltotal&apos;).text();let paid=$(&apos;#10pdpaidtotal&apos;).text();if(!paid) paid=0;sum=parseFloat(sum)-parseFloat(paid);let pay=$(&apos;#pos&apos;).val();if(!pay){showToast(&apos;Empty Value&apos;,&apos;alert&apos;,5000);return false;}if(parseFloat(pay)>parseFloat(sum)){showToast(&apos;Payment more than bill&apos;,&apos;alert&apos;,5000);return false;}Eirene.runStmt(&apos;10f-10pay-10c-10d-10-10a-10pd-10e-10tot&apos;,{pid:&apos;||pid||&apos;,paymentmethod:&apos;POS&apos;,amount:$(&apos;#pos&apos;).val(),billno:&apos;", {
                        "if": "||GET_billno|| > 0",
                        "then": " ||GET_billno||",
                        "else": " ||billno||"
                    },
                    "&apos;})'>Pay</button></div>",
                    "</div><div class='row'>",
                    "<div class='cell'>InternetBanking/Cheque</div>",
                    "<div class='cell'><input type='text' id='internetbanking' placeholder='Amount'/></div>",
                    "<div class='cell'><button onclick='let sum=$(&apos;#10abilltotal&apos;).text();let paid=$(&apos;#10pdpaidtotal&apos;).text();if(!paid) paid=0;sum=parseFloat(sum)-parseFloat(paid);let pay=$(&apos;#internetbanking&apos;).val();if(!pay){showToast(&apos;Empty Value&apos;,&apos;alert&apos;,5000);return false;}if(parseFloat(pay)>parseFloat(sum)){showToast(&apos;Payment more than bill&apos;,&apos;alert&apos;,5000);return false;}Eirene.runStmt(&apos;10f-10pay-10c-10d-10-10a-10pd-10e-10tot&apos;,{pid:&apos;||pid||&apos;,paymentmethod:&apos;InternetBanking&apos;,amount:$(&apos;#internetbanking&apos;).val(),billno:&apos;", {
                        "if": "||GET_billno|| > 0",
                        "then": " ||GET_billno||",
                        "else": " ||billno||"
                    },
                    "&apos;})'>Pay</button></div>",
                    "</div><div class='row'>",
                    "<div class='cell'>UPI:</div>",
                    "<div class='cell'><input type='text' id='UPI' placeholder='Amount'/></div>",
                    "<div class='cell'><button onclick='let sum=$(&apos;#10abilltotal&apos;).text();let paid=$(&apos;#10pdpaidtotal&apos;).text();if(!paid) paid=0;sum=parseFloat(sum)-parseFloat(paid);let pay=$(&apos;#UPI&apos;).val();if(!pay){showToast(&apos;Empty Value&apos;,&apos;alert&apos;,5000);return false;}if(parseFloat(pay)>parseFloat(sum)){showToast(&apos;Payment more than bill&apos;,&apos;alert&apos;,5000);return false;}Eirene.runStmt(&apos;10f-10pay-10c-10d-10-10a-10pd-10e-10tot&apos;,{pid:&apos;||pid||&apos;,paymentmethod:&apos;UPI&apos;,amount:$(&apos;#UPI&apos;).val(),billno:&apos;", {
                        "if": "||GET_billno|| > 0",
                        "then": " ||GET_billno||",
                        "else": " ||billno||"
                    },
                    "&apos;})'>Pay</button></div>",
                    "</div><div class='row'>",
                    "<div class='cell'>DC/CC:</div>",
                    "<div class='cell'><input type='text' id='card' placeholder='Amount'/></div>",
                    "<div class='cell'><button onclick='let sum=$(&apos;#10abilltotal&apos;).text();let paid=$(&apos;#10pdpaidtotal&apos;).text();if(!paid) paid=0;sum=parseFloat(sum)-parseFloat(paid);let pay=$(&apos;#card&apos;).val();if(!pay){showToast(&apos;Empty Value&apos;,&apos;alert&apos;,5000);return false;}if(parseFloat(pay)>parseFloat(sum)){showToast(&apos;Payment more than bill&apos;,&apos;alert&apos;,5000);return false;}Eirene.runStmt(&apos;10f-10pay-10c-10d-10-10a-10pd-10e-10tot&apos;,{pid:&apos;||pid||&apos;,paymentmethod:&apos;Card&apos;,amount:$(&apos;#card&apos;).val(),billno:&apos;", {
                        "if": "||GET_billno|| > 0",
                        "then": " ||GET_billno||",
                        "else": " ||billno||"
                    },
                    "&apos;})'>Pay</button></div>",
                    "</div>"
                ]
            }
        }, {
            "id": "10pay",
            "name": "Save payment details",
            "sql": {
                "runif": "||amount|| > 0",
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_payment",
                "fld": "billno,paymentmethod,amount,createdby,receiptno",
                "value": "||billno||,||paymentmethod||,||amount||,||USERID||,||GET_nextreceiptno||",
                "fldtype": "n,s,n,s,n",
                "command": "insert",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed-DO_NOT_PROCEED"
            }
        }, {
            "id": "10pay1",
            "name": "Save advance payment details",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_payment",
                "fld": "billno,paymentmethod,amount,advanceid,createdby",
                "value": "||billno||,||paymentmethod||,||amount||,||advanceid||,||USERID||",
                "fldtype": "n,s,n,s,s",
                "command": "insert",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "10paya",
            "name": "Save payment details",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_advance",
                "fld": "balance",
                "value": "(||balance||-||amount||)",
                "fldtype": "n",
                "command": "update",
                "whr": "id='||advanceid||'"
            }

        }, {

            "id": "10tot1",
            "name": "Total Amount(WorkareaAppendix)",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "app",
                "append": "App Date:<select id='appdate'>||GET_appdate||</select><br><br>",
                "tbl": "cmch_bill a",
                "fld": "sum(a.total),b.advance",
                "header": "Total Amount:,Advance:",
                "join": "LEFT JOIN cmch_advance b ON b.pid=a.pid",
                "whr": "a.recordstatus=1 and a.pid='||pid||' and billno IS NULL",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast-cmd:dom,fun:html;#workareaAppendix;||app||"

            }

        }, {
            "id": "10prec",
            "name": "Print Receipt",
            "sql": {
                "action": "Return",
                "outputto": "html",
                "output": "#workareaAppendix",
                "value": [
                    "<div id='printbill_1'></div>",
                    "<div id='printbill_2' class='printbill_2'></div>"
                ],
                "onsuccess": "cmd:dom,fun:function;printHTML;workareaAppendix-10r1-10r2-10prt"
            }
        }, {
            "id": "10r2",
            "name": "Get Paid Details - HTML",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#printbill_2",
                "appendoutput": 1,
                "tbl": "cmch_payment",
                "fld": "createdon,paymentmethod,amount",
                "parent": "TABLE class='font-ArialNarrow' style='margin-left: auto;margin-right:auto;margin-top:0.5cm;width:80%;font-size:0.7em'><thead><tr><TH style='text-align:left;'>Date</TH><TH style='text-align:left;'>Remark</TH><TH style='text-align:left;'>Payment mode</TH><TH style='text-align:left;'>Amount</TH></TR",
                "template": "<TR><TD style='text-align:left;'> ||createdon||</TD><TD style='text-align:left;'>Amount Received For Bill no.||billno||</TD><TD style='text-align:left;'> ||paymentmethod||</TD><TD style='text-align:left;'>||amount||</TD></TR>",
                "style": "margin-left: auto;margin-right:auto;margin-top:0.5cm;width:80%;font-size:0.7em",
                "whr": "recordstatus=1 and receiptno='||receiptno||'",
                "append": "<div class='row mt-4 font-ArialNarrow' style='margin-left: auto;font-size:0.7em'><div class='cell'>Signature</div><div class='cell'>Prepared by</div><div class='cell font-ArialNarrow'>Checked By</div></div>"
            }
        }, {
            "id": "10r1",
            "name": "Get Bill - HTML",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "html",
                "multistmt": [{
                        "action": "Get Row",
                        "outputto": "php",
                        "output": "patient",
                        "tbl": "cmch_patient",
                        "fld": "pname,pmobile",
                        "whr": "pid='||pid||'"
                    }, {
                        "action": "Get Row",
                        "outputto": "php",
                        "output": "bill",
                        "tbl": "cmch_printbill",
                        "fld": "DATE_FORMAT(createdon,'%d-%m-%Y') as billdate,department,appid",
                        "whr": [{
                                "if": "||GET_billno|| > 0",
                                "then": " billno='||GET_billno||'",
                                "else": " billno='||billno||'"
                            }
                        ]
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "appcnt",
                        "stmt": "SELECT count(*) FROM cmch_appointment WHERE id='||GET_bill_appid||'"
                    }, {
                        "runif": "||GET_appcnt|| = 1",
                        "action": "Get Row",
                        "outputto": "php",
                        "output": "appointment",
                        "tbl": "cmch_appointment a",
                        "fld": "a.pcase,b.name",
                        "join": "LEFT JOIN cmch_doctors b ON a.doctor=b.id",
                        "whr": "a.id='||GET_bill_appid||'"
                    }, {
                        "runif": "||GET_appcnt|| = 0",
                        "action": "Get Row",
                        "outputto": "php",
                        "output": "appointment",
                        "stmt": "SELECT '' pcase,'' name FROM cmch_appointment LIMIT 1"
                    }, {
                        "action": "Return",
                        "outputto": "html",
                        "output": "#printbill_2",
                        "value": [
                            "<center><img src='resource/image/cmch_logo1.png' width='500' height='70'>",
                            "<div>Receipt No. :||receiptno||</div></center><center>",
                            "<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:auto;margin-right:auto;font-size:0.7em'>",
                            "<tr><td style='border:1px solid black' class='p-1'><b>Patient ID</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pid||</td><td style='border:1px solid black' class='p-1'><b>Name</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||GET_patient_pname||</td></tr>",
                            "<tr><td style='border:1px solid black' class='p-1'><b>Date</b></td><td style='border:1px solid black' class='p-1'>||GET_bill_billdate||</td><td style='border:1px solid black' class='p-1'><b>Mobile No.</b></td><td style='border:1px solid black' class='p-1'>||GET_patient_pmobile||</td></tr>",
                            "<tr><td style='border:1px solid black' class='p-1'><b>Case Type</b></td><td style='border:1px solid black' class='p-1'>||GET_appointment_pcase||</td><td style='border:1px solid black' class='p-1'><b>Doctor</b></td><td style='border:1px solid black' class='p-1'>||GET_appointment_name||</td></tr>",
                            "<tr><td style='border:1px solid black' class='p-1'><b>Department</b></td><td style='border:1px solid black' class='p-1'>||GET_bill_department||</td><td style='border:1px solid black' class='p-1'></td><td style='border:1px solid black' class='p-1'></td></tr>",
                            "</table>"
                        ],
                        "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast"
                    }
                ]
            }
        }, {
            "id": "10phft",
            "name": "Filter Payments",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "demo",
                "value": "",

                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter1",
                    "elem": [{
                            "name": "mode",
                            "id": "10phmode",
                            "type": "select",
                            "option": ",Cash,Card,CMCHWallet,POS,InternetBanking,UPI"
                        }, {
                            "name": "dfdate",
                            "id": "10phdfdate",
                            "type": "datepicker",
                            "label": "Date From"
                        }, {
                            "name": "dtdate",
                            "id": "10phdtdate",
                            "type": "datepicker",
                            "label": "Date to"
                        }, {
                            "name": "pid",
                            "id": "10phpid",
                            "type": "text",
                            "placeholder": "PatientID"

                        }, {
                            "name": "bt",
                            "value": "Get",
                            "type": "button",

                            "onclick": "Eirene.runStmt('10ph',{mode:$('#10phmode').val(),dfdate:$('#10phdfdate').val(),dtdate:$('#10phdtdate').val(),pid:$('#10phpid').val()})"
                        }
                    ]
                },
                "onsuccess": "cmd:dom,fun:show;#workareaFilter1;fast"
            }
        }, {
            "id": "11sft",
            "name": "Lab Summary Filter",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "demo",
                "value": "",

                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter1",
                    "elem": [{
                            "name": "f1",
                            "type": "datepicker",
                            "id": "11sumftdt",
                            "value": "||CURDATE||"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Daily Report",
                            "onclick": "Eirene.runStmt('11sum',{dt:$('#11sumftdt').val()})"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Monthly Report",
                            "onclick": "Eirene.runStmt('11sum1',{dt:$('#11sumftdt').val().substring(0,7)})"
                        }
                    ]
                },
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix1;fast"
            }

        }, {
            "id": "11sum",
            "name": "X-RAY Summary",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [{
                        "action": "Return",
                        "output": "#workareaTablebox",
                        "value": [
                            "<div>",
                            "<button class='no-print button secondary' onclick='printHTML(&apos;workareaTablebox&apos;)'>Print</button>",
                            "</div>",
                            "<center>",
                            "<h2 class='mt-3'>X-RAY Report</h2>", {
                                "if": "||dt|| = BLANK",
                                "then": "<div><h2>||CURDATE_D_M_Y||</h2></div>"
                            }, {
                                "if": "||dt|| != BLANK",
                                "then": "<div><h2>||dt||</h2></div>"
                            },
                            "</center>"
                        ]
                    }, {
                        "action": "Get Table",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "tbl": "cmch_xray a",
                        "appendoutput": 1,
                        "fld": "'Radiology',DATE(a.createdon) as dt,COUNT(a.id),image",
                        "hiddencol": "2",
                        "grp": "DATE(a.createdon)",
                        "whr": [{
                                "if": "||dt|| = BLANK",
                                "then": " DATE(a.createdon)=CURDATE()",
                                "else": " DATE(a.createdon)='||dt||'"
                            }
                        ],
                        "join": "LEFT JOIN (select DATE(createdon) as createdon, count(*) as image from cmch_xrayimage where DATE(createdon)='||dt||' group by DATE(createdon)) b on b.createdon=DATE(a.createdon)",
                        "header": "Test,Date,Test #,Image #",
                        "class": "eirene-table dataTable",
                        "vsum": "3,4"
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "attachment",
                        "stmt": "SELECT count(image) FROM cmch_xrayimage WHERE DATE(createdon)='||dt||'"

                    },
                    {
                        "action": "Get Table",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "tbl": "cmch_xray a",
                        "fld": "a.item,DATE(a.createdon) as dt,COUNT(a.id)",
                        "hiddencol": "2",
                        "grp": "a.item",
                        "whr": [{
                                "if": "||dt||",
                                "value": "BLANK",
                                "then": " DATE(a.createdon)=CURDATE()",
                                "else": " DATE(a.createdon)='||dt||'"
                            }
                        ],

                        "header": "Test,Date,Test #",
                        "prepend": "<h4 class='mt-3'><center>Individual Test Report</center></h4>",
                        "class": "eirene-table dataTable",
                        "vsum": "3,4"
                    }
                ]
            }

        }, {
            "id": "11sum1",
            "name": "Xray Summary (Monthly)",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [
                    {
                        "action": "Return",
                        "output": "#workareaTablebox",
                        "value": [
                            "<div>",
                            "<button class='no-print button secondary' onclick='printHTML(&apos;workareaTablebox&apos;)'>Print</button>",
                            "</div>",
                            "<center>",
                            "<h2 class='mt-3'>Monthly Report</h2>", {
                                "if": "||dt|| = BLANK",
                                "then": "<div><h2>||CURDATE_M_Y||</h2></div>"
                            }, {
                                "if": "||dt|| != BLANK",
                                "then": "<div><h2>||dt||</h2></div>"
                            },
                            "</center>"
                        ]
                    }, {
                        "action": "Get Table",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "tbl": "cmch_xray a",
                        "appendoutput": 1,
                        "fld": "'Radiology',DATE_FORMAT(a.createdon,'%Y-%m') as dt,COUNT(a.id),image",
                        "hiddencol": "2",
                        "grp": "DATE_FORMAT(a.createdon,'%Y-%m')",
                        "whr": "DATE_FORMAT(a.createdon,'%Y-%m')= '||dt||'",
                        "join": "LEFT JOIN (select DATE_FORMAT(createdon,'%Y-%m') as createdon, count(*) as image from cmch_xrayimage where DATE_FORMAT(createdon,'%Y-%m')='||dt||' group by DATE_FORMAT(createdon,'%Y-%m')) b on b.createdon=DATE_FORMAT(a.createdon,'%Y-%m')",
                        "header": "Test,Date,Test #,Image #",
                        "class": "eirene-table dataTable",
                        "vsum": "3,4"
                    }, {

                        "action": "Get Chart",
                        "outputto": "html",
                        "output": "#workareaAppendix",
                        "stmt": "select DATE_FORMAT(createdon, '%d/%m') as b, count(item) as a from cmch_xray where DATE_FORMAT(createdon,'%Y-%m')= '||dt||' group by DATE_FORMAT(createdon, '%d/%m') ",
                        "type": "bar",
                        "title": "IP Monthly #",
                        "elem": "#workareaAppendix",
                        "label": "b",
                        "value": "a",
                        "legend": "Total Test",
                        "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast"

                    }
                ]
            }

        },
        {
            "id": "rmfile",
            "name": "DeleteFile",
            "sql": {
                "action": "Remove File",
                "path": "||image||",
                "onsuccess": "cmd:dom,fun:showtoast;success;Delete Successful-11dtx",
                "onfailure": "cmd:dom,fun:showtoast;alert;Delete Failed"
            }
        }, {
            "id": "11dtx",
            "name": "Delete Xray",
            "sql": {
                "action": "Delete Row Permanently",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_xrayimage",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Delete Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Delete Failed"
            }
        },
        {
            "id": "11gtx",
            "name": "Get Xray",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "#workareaAppendix",
                "tbl": "cmch_xray a",
                "fld": "a.item",
                "functionfield": [{
                        "type": "link",
                        "href": "<d.image>",
                        "value": "Link",
                        "otherattr": "target",
                        "otherattrvalue": "_blank"
                    }, {
                        "type": "icon",
                        "class": "mif-cross mr-2",
                        "title": "Delete",
                        "onclick": "Eirene.runStmt2('11dtx','ID','<d.id>')"
                    }
                ],
                "serialno": true,
                "join": "INNER JOIN cmch_xrayimage d ON a.id=d.xrayid",
                "header": "Item",
                "whr": "d.xrayid='||ID||'",
                "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:show;#workareaAppendix;slow-cmd:dom,fun:empty;#workareaFilter;slow"

            }

        }, {
            "id": "12sft",
            "name": "Lab Summary Filter",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "demo",
                "value": "",
                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter1",
                    "elem": [{
                            "name": "f1",
                            "type": "datepicker",
                            "id": "12sumftdt",
                            "value": "||CURDATE||"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Daily Report",
                            "onclick": "Eirene.runStmt('12sum',{dt:$('#12sumftdt').val()})"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Monthly Report",
                            "onclick": "Eirene.runStmt('12sum1',{dt:$('#12sumftdt').val().substring(0,7)})"
                        }
                    ]
                },
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix1;fast"
            }

        }, {
            "id": "12sum1",
            "name": "Lab Summary (Monthly)",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [
                    {
                        "action": "Return",
                        "output": "#workareaTablebox",
                        "value": [
                            "<div>",
                            "<button class='no-print button secondary' onclick='printHTML(&apos;workareaTablebox&apos;)'>Print</button>",
                            "</div>",
                            "<center>",
                            "<h2 class='mt-3'>Monthly Report</h2>", {
                                "if": "||dt|| = BLANK",
                                "then": "<div><h2>||CURDATE_M_Y||</h2></div>"
                            }, {
                                "if": "||dt|| != BLANK",
                                "then": "<div><h2>||dt||</h2></div>"
                            },
                            "</center>"
                        ]
                    }, {
                        "action": "Get Table",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "tbl": "cmch_bill",
                        "appendoutput": 1,
                        "fld": "category,COUNT(category)",
                        "grp": "category",
                        "whr": "DATE_FORMAT(createdon,'%Y-%m')= '||dt||' and (category='Lab' or category='Thyrocare Lab' or category='Global Diagnostics') and billno IS NOT NULL",
                        "header": "Test,Count",
                        "class": "eirene-table dataTable",
                        "vsum": "2"
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "printed",
                        "stmt": "SELECT count(status) FROM cmch_lab WHERE status>2 and DATE_FORMAT(createdon,'%Y-%m')= '||dt||'"

                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "filed",
                        "stmt": "SELECT count(status) FROM cmch_lab WHERE status<3 and DATE_FORMAT(createdon,'%Y-%m')= '||dt||'"
                    },
                    {
                        "action": "Return",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "value": [

                            "<center>",
                            "<h6 class='mt-3'>Test Status</h6>",
                            "</center>",
                            "<p style='text-align:left;margin-left:4cm'>Printed:||GET_printed||",
                            "<span style='float:right;margin-right:4cm;'>Filed:||GET_filed||</span></p>"

                        ]
                    },
                    {
                        "action": "Get Matrix",
                        "row": "a",
                        "col": "b",
                        "val": "result",
                        "outputto": "html",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "horizontalsum": "1",
                        "verticalsum": "1",
                        "tbl": "cmch_lab",
                        "class": "dataTable font-ArialNarrow",
                        "style": "border:1px solid black;border-collapse:collapse;margin-left:2cm;margin-top:0.5cm;width:75%;font-size:0.8em",
                        "fld": "item as a,DATE_FORMAT(createdon, '%d/%m') as b,CONCAT('<center>',COUNT(item),'</center>')as result",
                        "grp": "a,b",
                        "srt": "createdon ASC",
                        "horizontalsum": "1",
                        "verticalsum": "1",
                        "whr": "DATE_FORMAT(createdon,'%Y-%m')= '||dt||'",
                        "class": "eirene-table dataTable",
                        "prepend": "<center><h6 class='mt-3'>Detailed Report</h6></center>"

                    }
                ]
            }

        },
        {
            "id": "12sum",
            "name": "Lab Summary",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [{
                        "action": "Return",
                        "output": "#workareaTablebox",
                        "value": [
                            "<div>",
                            "<button class='no-print button secondary' onclick='printHTML(&apos;workareaTablebox&apos;)'>Print</button>",
                            "</div>",
                            "<center>", {
                                "if": "||dt|| = BLANK",
                                "then": "<div><h2>||CURDATE_D_M_Y||</h2></div>"
                            }, {
                                "if": "||dt|| != BLANK",
                                "then": "<div><h2>||dt||</h2></div>"
                            },
                            "<h2 class='mt-3'>Lab Report</h2>",
                            "</center>"
                        ]
                    }, {
                        "action": "Get Table",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "tbl": "cmch_bill",
                        "appendoutput": 1,
                        "fld": "category,COUNT(category)",
                        "grp": "category",
                        "whr": [{
                                "if": "||dt|| = BLANK",
                                "then": "DATE(createdon)=CURDATE()",
                                "else": "DATE(createdon)='||dt||'"
                            },
                            "and (category='Lab' or category='Thyrocare Lab' or category='Global Diagnostics') and billno IS NOT NULL"
                        ],
                        "header": "Test,Count",
                        "class": "eirene-table dataTable",
                        "vsum": "2"
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "printed",
                        "stmt": "SELECT count(status) FROM cmch_lab WHERE status>2 and DATE(createdon)='||dt||'"

                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "filed",
                        "stmt": "SELECT count(status) FROM cmch_lab WHERE status<3 and DATE(createdon)='||dt||'"
                    },
                    {
                        "action": "Return",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "value": [

                            "<center>",
                            "<h6 class='mt-3'>Test Status</h6>",
                            "</center>",
                            "<p style='text-align:left;margin-left:4cm'>Printed:||GET_printed||",
                            "<span style='float:right;margin-right:4cm;'>Filed:||GET_filed||</span></p>"

                        ]
                    }, {
                        "action": "Get Table",
                        "output": "#workareaTablebox",
                        "appendoutput": 1,
                        "tbl": "cmch_lab",
                        "fld": "item,COUNT(item)",
                        "grp": "item",
                        "whr": [{
                                "if": "||dt||",
                                "value": "BLANK",
                                "then": " DATE(createdon)=CURDATE()",
                                "else": " DATE(createdon)='||dt||'"
                            }
                        ],

                        "header": "Test,Count",
                        "prepend": "<h6 class='mt-3'><center>Individual Test Report</center></h6>",
                        "class": "eirene-table dataTable",
                        "vsum": "2"
                    }
                ]
            }

        }, {
            "id": "12s1",
            "name": "Get item and comment",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "multistmt": [{
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "item",
                        "tbl": "cmch_lab",
                        "fld": "item",
                        "whr": "id='||ID||'"
                    }, {
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "comment",
                        "tbl": "cmch_lab",
                        "fld": "comment",
                        "whr": "id='||ID||'",
                        "onsuccess": [{
                                "if": "||GET_item|| = Widal Test",
                                "then": "12lrw",
                                "else": "12lr2"
                            }
                        ]
                    }
                ]

            }
        }, {
            "id": "12pre2",
            "name": "Get Report HTML(Lab Patient details)",
            "sql": {
                "action": "Return",
                "outputto": "html",
                "output": "#report_1",

                "appendoutput": 1,
                "prepend": [
                    "<button class='mif-printer fg-blue' onclick='printHTML(&apos;workareaAppendix&apos;)'></button>",
                    "<center><img src='resource/image/cmch_logo1.png' width='400' height='60'></center>"
                ],
                "template": [
                    "<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:auto;margin-right:auto;margin-top:10px;font-size:0.7em'>",
                    "<tr><td style='border:1px solid black' class='pl-2'><b>Patient ID</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pid||</td><td style='border:1px solid black' class='p-1'><b>Name</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pname||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>BIll NO:</b></td><td style='border:1px solid black' class='p-1'>||billno||</td><td style='border:1px solid black' class='p-1'><b>Bill Date</b></td><td style='border:1px solid black' class='p-1'>||createdon||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>Age/Gender</b></td>", 
					"<td style='border:1px solid black' class='p-1'>||age||/||pgender||</td>",					
                    "<td style='border:1px solid black' class='p-1'><b>Marital Status</b></td>", 
					"<td style='border:1px solid black' class='p-1'>||pmaritalstatus||</td></tr>",					
                    "<tr><td style='border:1px solid black' class='p-1'><b>Collection Time</b></td><td style='border:1px solid black' class='p-1'>||collectiontime||</td><td style='border:1px solid black' class='p-1'><b>Reporting Time</b></td><td style='border:1px solid black' class='p-1'>||reportingtime||</td></tr>",
                    "</table>"
                ],
                "tbl": "cmch_lab a",
                "fld": "b.pid,d.pname,a.billno,a.item,a.reportingtime,a.collectiontime,a.createdon,d.pgender,d.pmaritalstatus,(YEAR(CURDATE())-d.pyob) as age",
                "join": [
                    "INNER JOIN cmch_printbill b ON a.billno= b.billno",
                    "INNER JOIN cmch_patient d ON b.pid=d.pid"
                ],

                "whr": "a.id= ||IDS|| ",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast"
            }
        }, {
            "id": "12lr1",
            "name": "Get Report HTML(Lab Patient details)",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#header",
                "prepend": [
                    "<button class='mif-printer fg-blue' onclick='printHTML(&apos;workareaAppendix&apos;)'></button>",
                    "<center><img src='resource/image/cmch_logo1.png' width='400' height='60'></center>"
                ],
                "template": [
                    "<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:auto;margin-right:auto;margin-top:20px;font-size:0.7em'>",
                    "<tr><td style='border:1px solid black' class='pl-2'><b>Patient ID</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pid||</td><td style='border:1px solid black' class='p-1'><b>Name</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pname||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>BIll NO:</b></td><td style='border:1px solid black' class='p-1'>||billno||</td><td style='border:1px solid black' class='p-1'><b>Bill Date</b></td><td style='border:1px solid black' class='p-1'>||createdon||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>Age/Gender</b></td>", 
					"<td style='border:1px solid black' class='p-1'>||age||/||pgender||</td>",					
                    "<td style='border:1px solid black' class='p-1'><b>Marital Status</b></td>",
					"<td style='border:1px solid black' class='p-1'>||pmaritalstatus||</td></tr>",					
                    "<tr><td style='border:1px solid black' class='p-1'><b>Collection Time</b></td><td style='border:1px solid black' class='p-1'>||collectiontime||</td><td style='border:1px solid black' class='p-1'><b>Reporting Time</b></td><td style='border:1px solid black' class='p-1'>||reportingtime||</td></tr>",
                    "</table>"
                ],
                "tbl": "cmch_lab a",
                "fld": "b.pid,d.pname,a.billno,a.item,a.reportingtime,a.collectiontime,a.createdon,d.pgender,d.pmaritalstatus,(YEAR(CURDATE())-d.pyob) as age",
                "join": [
                    "INNER JOIN cmch_printbill b ON a.billno= b.billno",
                    "INNER JOIN cmch_patient d ON b.pid=d.pid"
                ],

                "whr": "a.id='||ID||'",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast"
            }
        }, {
            "id": "12lr2",
            "name": "Get Lab Result - HTML",
            "sql": {
                "action": "Get HTML",

                "outputto": "html",
                "output": "labresult",
                "tbl": "cmch_labresult a",
                "fld": "b.parametername,a.result,b.unit,b.lrange,b.upperrange,b.lowerrange,b.referencerange",
                "join": [
                    "INNER JOIN cmch_labparameters b ON a.parameterid=b.id",
                    "INNER JOIN cmch_lab c ON c.id=a.labid"
                ],
                "parent": "TABLE class='font-ArialNarrow' style='margin-left:5cm;margin-top:0.5cm;font-size:0.8em;width:80%'><tr><TH style='text-align:left; width:5cm'>Parameter</TH><TH style='text-align:left;width:3cm'>Result</TH><TH style='text-align:left;width:3cm'>Unit</TH><TH style='text-align:left;width:3.5cm'>Range</TH></TR",
                "template": ["<TR><TD style='text-align:left;'>||parametername||", {
                        "if": "||referencerange|| != BLANK and ||referencerange|| != 0",
                        "then": "<br><span style='font-size:0.7em'>||referencerange||</span>"
                    },
                    "</TD>", {
                        "if": "||result|| > ||upperrange|| or ||result|| < ||lowerrange||",
                        "then": "<TD style='text-align:left;'><b>||result||</b></TD>",
                        "else": "<TD style='text-align:left;'>||result||</TD>"
                    },
                    "<TD style='text-align:left;'>||unit||</TD>",
                    "<TD style='text-align:left;'> ||lrange||</TD>",
                    "</TR>"
                ],

                "whr": "c.id='||ID||'",
                "srt": "b.porder",
                "prepend": "<DIV class='font-ArialNarrow' style='text-align:center; margin-top:30px'><b>||GET_item||</b></DIV>",
                "append": [{
                        "if": "||GET_comment|| != BLANK",
                        "then": "<div class='font-ArialNarrow' style='text-align:center; margin-top:0.5cm; font-size:0.8em'>Comment:<b> ||GET_comment||</b></div>"
                    }
                ],
                "onsuccess": "cmd:dom,fun:append;#labresult;||labresult||-12st1"

            }
        },
        {
            "id": "12lrw",
            "name": "Widal Lab Print",
            "sql": {
                "action": "Get Matrix",
                "row": "paran",
                "col": "paran1",
                "val": "result",
                "outputto": "html",
                "output": "labresult1",
                "tbl": "cmch_labresult a",
                "class": "dataTable font-ArialNarrow",
                "style": "border:1px solid black;border-collapse:collapse;margin-left:2.5cm;margin-top:0.5cm;width:75%;font-size:0.8em",
                "fld": "substring_index(b.parametername,'-',1) as paran,substring_index(b.parametername,'-',-1) as paran1,CONCAT('<center>',a.result,'</center>')as result",
                "join": [
                    "INNER JOIN cmch_labparameters b ON a.parameterid=b.id",
                    "INNER JOIN cmch_lab c ON c.id=a.labid"
                ],
                "srt": "b.porder ASC",
                "whr": "c.id='||ID||'",
                "prepend": "<DIV class='font-ArialNarrow' style='text-align:center; margin-top:30px'><b>||GET_item||</b></DIV>",
                "append": [{
                        "if": "||comment|| != BLANK",
                        "then": "<div class='font-ArialNarrow' style='text-align:center; margin-top:0.5cm; font-size:0.8em'>Comment:<b> ||GET_comment||</b></div>"
                    }
                ],
                "onsuccess": "cmd:dom,fun:append;#labresult1;||labresult1||-12st1"
            }
        },
        {
			"id":"12lpr",
			"name":"Lab Report Bulk Print",
			"sql":{
				"action":"Get HTML","outputto":"html",
				"output":"#workareaAppendix",
				"tbl":"cmch_lab",
				"fld":"id,item,comment",
				"whr":"FIND_IN_SET(id,'||ids||')>0 and recordstatus=1",
				"template":[					
					{"if":"||item|| = Widal Test","then":{"call":"12prw1","outputto":"php","output":"labresult1","id":"||id||","appendoutput":0},"else":{"call":"12pre","outputto":"php","output":"labresult1","id":"||id||","appendoutput":0}},
					"||labresult1||"
				],
				"prepend":[
					{"call":"12pr","output":"labpatient","outputto":"php","onsuccess":"","id":"||id||","appendoutput":0},
					"||labpatient||"
				],
				"append":[
					{"call":"12lbsg","output":"labsign","outputto":"php"},
					"||labsign||"
				],
				"onsuccess":"cmd:dom,fun:show;#workareaAppendix-cmd:dom,fun:function;printHTML;workareaAppendix"
			}			
		}, {
            "id": "12pr",
            "name": "Get Report HTML(Lab Patient details)",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#workareaAppendix",
                "prepend": [
                    "<button class='mif-printer fg-blue no-print' onclick='printHTML(&apos;workareaAppendix&apos;)'></button>",
                    "<center><img src='resource/image/cmch_logo1.png' width='400' height='60'></center>"
                ],
                "template": [
                    "<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:auto;margin-right:auto;margin-top:10px;font-size:0.7em'>",
                    "<tr><td style='border:1px solid black' class='pl-2'><b>Patient ID</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pid||</td><td style='border:1px solid black' class='p-1'><b>Name</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pname||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>BIll NO:</b></td><td style='border:1px solid black' class='p-1'>||billno||</td><td style='border:1px solid black' class='p-1'><b>Bill Date</b></td><td style='border:1px solid black' class='p-1'>||createdon||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>Age/Gender</b></td>", 
					"<td style='border:1px solid black' class='p-1'>||age||/||pgender||</td>",					
                    "<td style='border:1px solid black' class='p-1'><b>Marital Status</b></td>", 
					"<td style='border:1px solid black' class='p-1'>||pmaritalstatus||</td></tr>",					
                    "<tr><td style='border:1px solid black' class='p-1'><b>Collection Time</b></td><td style='border:1px solid black' class='p-1'>||collectiontime||</td><td style='border:1px solid black' class='p-1'><b>Reporting Time</b></td><td style='border:1px solid black' class='p-1'>||reportingtime||</td></tr>",
                    "</table>"
                ],
                "tbl": "cmch_lab a",
                "fld": "b.pid,d.pname,a.billno,a.item,DATE_FORMAT(a.reportingtime,'%d-%m-%Y %H:%i') as reportingtime,IF(a.collectiontime is null,'_',DATE_FORMAT(a.collectiontime,'%d-%m-%Y %H:%i')) as collectiontime,DATE_FORMAT(a.createdon,'%d-%m-%Y') as createdon,d.pgender,d.pmaritalstatus,(YEAR(CURDATE())-d.pyob) as age",
                "join": [
                    "INNER JOIN cmch_printbill b ON a.billno= b.billno",
                    "INNER JOIN cmch_patient d ON b.pid=d.pid"
                ],
                "whr": "a.id='||id||'",
                "onsuccess": [{
                        "if": "||item|| = Widal Test",
                        "then": "12prw1-12lbsg-cmd:dom,fun:hide;#workareaAppendix;fast-cmd:dom,fun:function;printHTML;workareaAppendix",
                        "else": "12pre-12lbsg-cmd:dom,fun:hide;#workareaAppendix;fast-cmd:dom,fun:function;printHTML;workareaAppendix"
                    }
                ]
            }
        }, {
            "id": "12pre",
            "name": "Get Lab Result - HTML",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#workareaAppendix",
                "appendoutput": 1,
				"prerun":[
					{"sqlstatement":{
						"labtbl":"SELECT item,IF(comment is null,'',comment) comment FROM cmch_lab where id='||id||'"
					}}
				],
                "tbl": "cmch_labresult a",
                "fld": "b.parametername,a.result,b.unit,b.lrange,b.upperrange,b.lowerrange,b.referencerange",
                "join": [
                    "INNER JOIN cmch_labparameters b ON a.parameterid=b.id",
                    "INNER JOIN cmch_lab c ON c.id=a.labid"
                ],
                "parent": "TABLE class='font-ArialNarrow' style='margin-left:3cm;margin-top:0.5cm;width:80%;font-size:0.8em;'><thead><tr><TH style='text-align:left;'>Parameter</TH><TH style='text-align:left;'>Result</TH><TH style='text-align:left;'>Unit</TH><TH style='text-align:left;'>Range</TH></TR",
                "template": ["<TR><TD style='text-align:left;'>||parametername||", 
					{
                        "if": "||referencerange|| != BLANK",
                        "then": "<br><span style='font-size:0.7em'>||referencerange||</span>"
                    },
                    "</TD>", {
                        "if": "||result|| > ||upperrange|| or ||result|| < ||lowerrange||",
                        "then": "<TD style='text-align:left;'><b>||result||</b></TD>",
                        "else": "<TD style='text-align:left;'>||result||</TD>"
                    },
                    "<TD style='text-align:left;'>||unit||</TD>",
                    "<TD style='text-align:left;'> ||lrange||</TD>",
                    "</TR>"
                ],				
                "whr": "a.labid='||id||' and b.recordstatus=1",
                "srt": "b.porder",
                "prepend": "<DIV class='font-ArialNarrow' style='text-align:center; margin-top:15px'><b>||labtbl_item||</b></DIV>",
				"append": [{
                        "if": "||labtbl_comment|| != BLANK",
                        "then": "<div class='font-ArialNarrow' style='text-align:center; margin-top:0.5cm'>Comment:<b> ||labtbl_comment||</b></div>"
                    }
				]

            }
        },{
			"id":"12lbsg",
			"name":"Lab Report Signatures",
			"sql":{
				"action":"Return",
				"outputto": "html",
                "output": "#workareaAppendix",
                "appendoutput": 1,
				"value": [
                    "<div style='margin-left:3cm; margin-top:1cm'>",
                    "<div class='row' style='width:80%'><DIV class='cell'><img src='resource/image/sign.png' width='60' height='40'></DIV>",
                    "<div class='cell'></div></div>",
                    "<div class='row' style='width:80%;font-size:0.8em'><DIV class='cell font-ArialNarrow'>CMCH Lab</DIV>",
                    "<div class='cell font-ArialNarrow'><div style='text-align:right'>Lab Assistant</div></div></div>",
                    "</div>"
                ]
			}
		},{
            "id": "12prw1",
            "name": "Widal Lab Print",
            "sql": {
                "action": "Get Matrix",
                "row": "a",
                "col": "b",
                "val": "result",
                "outputto": "html",
                "output": "#workareaAppendix",
                "appendoutput": 1,
				"prerun":[
					{"sqlstatement":{
						"labtbl":"SELECT item,IF(comment is null,'',comment) comment FROM cmch_lab where id='||id||'"
					}}
				],
                "tbl": "cmch_labresult a",
                "class": "dataTable font-ArialNarrow",
                "style": "border:1px solid black;border-collapse:collapse;margin-left:2.5cm;margin-top:0.5cm;width:75%;font-size:0.8em",
                "fld": "substring_index(b.parametername,'-',1) as a,substring_index(b.parametername,'-',-1) as b,CONCAT('<center>',a.result,'</center>')as result",
                "join": [
                    "INNER JOIN cmch_labparameters b ON a.parameterid=b.id",
                    "INNER JOIN cmch_lab c ON c.id=a.labid"
                ],
                "srt": "b.porder ASC",
                "whr": "c.id='||id||'",
                "prepend": "<DIV class='font-ArialNarrow' style='text-align:center; margin-top:15px'><b>||labtbl_item||</b></DIV>",
				"append": [{
                        "if": "||labtbl_comment|| != BLANK",
                        "then": "<div class='font-ArialNarrow' style='text-align:center; margin-top:0.5cm'>Comment:<b> ||labtbl_comment||</b></div>"
                    }
				]
            }
        }, {
            "id": "12prw",
            "name": "Get Report HTML(Widal Test)",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#workareaAppendix",
                "appendoutput": 1,
                "tbl": "cmch_labresult a",
                "fld": "b.parametername,a.result,b.porder",
				"prerun":[
					{"sqlstatement":{
						"labtbl":"SELECT item,IF(comment is null,'',comment) comment FROM cmch_lab where id='||id||'"
					}}
				],
                "join": [
                    "INNER JOIN cmch_labparameters b ON a.parameterid=b.id",
                    "INNER JOIN cmch_lab c ON c.id=a.labid"
                ],
                "parent": "TABLE class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:3cm;margin-top:0.5cm;width:80%;'><thead><tr><TH style='text-align:left;'>&nbsp;</TH><TH style='text-align:left;'>1:20</TH><TH style='text-align:left;'>1:40</TH><TH style='text-align:left;'>1:80</TH><TH style='text-align:left;'>1:160</TH><TH style='text-align:left;'>1:320</TH><TH style='text-align:left;'>1:640</TH></TR><thead",
                "template": [{
                        "if": "||porder|| = 1",
                        "then": "</TR><TD style='border:1px solid black' class='p-1'>SalmonellaTyphi O</TD>"
                    }, {
                        "if": "||porder|| = 7",
                        "then": "</TR><TD style='border:1px solid black' class='p-1'>SalmonellaTyphi H</TD>"
                    }, {
                        "if": "||porder|| = 13",
                        "then": "</TR><TD style='border:1px solid black' class='p-1'>SalmonellaParaTyphi AH</TD>"
                    }, {
                        "if": "||porder|| = 19",
                        "then": "</TR><TD style='border:1px solid black' class='p-1'>SalmonellaTyphi BH</TD>"
                    },
                    "<TD style='border:1px solid black;text-align:center' class='p-1'>||result||</TD>"
                ],
                "srt": "b.porder ASC",
                "whr": "c.id='||id||'",
                "prepend": "<DIV class='font-ArialNarrow' style='text-align:center; margin-top:15px'><b>||labtbl_0||</b></DIV>",
                "append": [{
                        "if": "||labtbl_1|| != BLANK",
                        "then": "<div class='font-ArialNarrow' style='text-align:center; margin-top:0.5cm'>Comment:<b> ||labtbl_1||</b></div>"
                    },
                    "<div style='margin-left:3cm;margin-top:1cm'>",
                    "<div class='row' style='width:80%'><DIV class='cell'><img src='resource/image/sign.png' width='60' height='40'></DIV>",
                    "<DIV class='cell'></DIV></div>",
                    "<div class='row' style='width:80%;font-size:0.8em'><DIV class='cell font-ArialNarrow'>CMCH Lab</DIV>",
                    "<DIV class='cell font-ArialNarrow;font-size:0.8em'><div style='text-align:right'>Lab Assistant</div></DIV></div>",
                    "</div>"
                ]
            }
        }, {
            "id": "12alp",
            "name": "List Parameters",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "para",
                "tbl": "cmch_labparameters a",
                "functionfield": [{
                        "type": "button",
                        "value": "Select",
                        "onclick": "Eirene.runStmt('12gp',{pid:'||pid||',parameterid:'<a.id>',itemid:'<a.itemid>'},$(this).hide())"
                    }
                ],
                "fld": "a.parametername",
                "join": "INNER JOIN cmch_item b ON b.id=a.itemid",
                "header": "Parameter Name",
                "whr": "a.recordstatus=1 and b.item='||item||'",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;slow-cmd:dom,fun:html;#workareaAppendix;||para||"
            }
        }, {
            "id": "12gp",
            "name": "Save Lab Result(Add Parameters with blank)",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "res",
                "value": [{
                        "sqlstatement": {
                            "a": "SELECT count(*) FROM cmch_labresult WHERE labid='||id||'"
                        }
                    }, {
                        "sqlstatement": {
                            "runif": "||a|| = 0",
                            "b": "INSERT INTO cmch_labresult (id,labid,pid,parameterid,result,createdby) SELECT UUID(),'||id||','||pid||', c.id,'0','||USERID||' FROM cmch_lab a INNER JOIN cmch_item b ON a.item=b.item INNER JOIN cmch_labparameters c ON b.id=c.itemid  WHERE a.billitemid='||billitemid||'"
                        }
                    }
                ],
                "onfailure": "cmd:dom,fun:showtoast;alert;Adding Failed",
                "onsuccess": "cmd:dom,fun:showtoast;success;Parameter Added"
            }
        }, {
            "id": "12ct",
            "name": "Status Change(Lab)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_lab",
                "fld": "collectiontime",
                "value": "NOW()",
                "fldtype": "n",
                "command": "update",
                "whr": "id='||id||'"
            }
        }, {
            "id": "12rt",
            "name": "Update lab Reporting time",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_lab",
                "fld": "reportingtime",
                "value": "NOW()",
                "fldtype": "n",
                "command": "update",
                "whr": "id='||id||' and reportingtime IS NULL"
            }
        }, {
            "id": "12st1",
            "name": "Status Change(Add Parameters)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_lab",
                "fld": "status",
                "value": "status+1",
                "fldtype": "n",
                "command": "update",
                "whr": "id='||id||' or id='||ID||'"
            }
        }, {
            "id": "12st2",
            "name": "Status Chnage(Add Values)",
            "sql": {
                "action": "Save Row",

                "outputto": "php",
                "output": "res",
                "tbl": "cmch_lab",
                "fld": "status",
                "value": "2",
                "fldtype": "n",
                "command": "update",
                "whr": "id='||id||'"

            }
        }, {
            "id": "12sdel",
            "name": "Delete Lab Result",
            "sql": {
                "action": "Delete Row Permanently",
                "tbl": "cmch_labresult",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Delete Successful-cmd:dom,fun:hide;current",
                "onfailure": "cmd:dom,fun:showtoast;alert;Delete Failed"
            }
        }, {
            "id": "12sval",
            "name": "Save values (Lab)",
            "sql": {
                "action": "Save Row",

                "outputto": "php",
                "output": "res",
                "tbl": "cmch_labresult",
                "fld": "result",
                "value": "||value||",
                "fldtype": "s",
                "command": "update",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"

            }
        }, {
            "id": "12svlr",
            "name": "Save Lab Result",
            "sql": {
                "action": "Save Row",

                "outputto": "php",
                "output": "res",
                "tbl": "cmch_labresult",
                "fld": "pid,itemid,date,createdby",
                "value": "||pid||,||itemid||,NOW(),||USERID||",
                "fldtype": "s,s,n,s",
                "command": "insert"
            }
        }, {
            "id": "12ec",
            "name": "Get Evaluation Chart",
            "sql": {
                "action": "Get Matrix",
                "row": "a",
                "col": "b",
                "val": "result",
                "outputto": "html",
                "output": "#workareaTablebox",
                "tbl": "cmch_labresult a",
                "prepend": "<div><button class='mif-print fg-blue' onclick='printHTML(&apos;evaluationchartmatrix&apos;)'></button></div><div id='evaluationchartmatrix'>Patient ID:||pid||<br>",
                "append": "</div>",
                "class": "dataTable font-ArialNarrow",
                "style": "border:1px solid black;border-collapse:collapse;margin-left:2cm;margin-top:0.5cm;width:75%;font-size:0.8em",
                "fld": "b.parametername as a,DATE_FORMAT(a.modifiedon, '%d/%m') as b,CONCAT('<center>',a.result,'</center>')as result",
                "join": [
                    "INNER JOIN cmch_labparameters b ON a.parameterid=b.id",
                    "INNER JOIN cmch_evaluation c ON a.parameterid=c.parameterid"
                ],
                "srt": "a.modifiedon,c.porder",
                "whr": "b.recordstatus=1 and a.pid='||pid||' and DATE(a.createdon) >='||df||' and DATE(a.createdon) <='||dt||'"
            }
        }, {
            "id": "12flt",
            "name": "Evaluation Chart Filter",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "demo",
                "elem": {
                    "type": "row",
                    "output": "#workareaFilter1",
                    "elem": [{
                            "name": "f1",
                            "type": "text",
                            "id": "12fltpid",
                            "placeholder": "Patient ID"
                        }, {
                            "name": "f2",
                            "type": "datepicker",
                            "id": "12fltdf",
                            "label": "From Date:"
                        }, {
                            "name": "f3",
                            "type": "datepicker",
                            "id": "12fltdt",
                            "label": "To Date:"
                        }, {
                            "name": "f4",
                            "type": "button",
                            "value": "Get",
                            "onclick": "Eirene.runStmt('12ec',{pid:$('#12fltpid').val(),df:$('#12fltdf').val(),dt:$('#12fltdt').val()})"
                        }
                    ]
                },
                "value": "",
                "onsuccess": "cmd:dom,fun:show;#workareaFilter1;slow"
            }
        }, {
            "id": "12b",
            "name": "List Evaluation Parameters",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "table",
                "tbl": "cmch_evaluation a",
                "fld": "b.parametername",
                "header": "Parameter Name",
                "join": "LEFT JOIN cmch_labparameters b ON b.id=a.parameterid",
                "functionfield": [{
                        "type": "text",
                        "value": "<a.porder>",
                        "caption": "POrder",
                        "onblur": "Eirene.runStmt('12bp',{porder:$(this).val(),ID:'<a.id>'})"
                    }
                ],
                "whr": "a.recordstatus=1",
                "onsuccess": "cmd:dom,fun:hide;#workareaAppendix;slow"
            }
        }, {
            "id": "12bp1",
            "name": "Select for evaluation parameters",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "demo",

                "value": "",
                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter1",
                    "elem": [{
                            "name": "f1",
                            "type": "span",
                            "icon": "Lab Test",
                            "style": "margin-top:4px;"
                        }, {
                            "name": "f2",
                            "type": "select",
                            "class": "mr-2",
                            "id": "test",
                            "option": "SELECT id,item from cmch_item WHERE category like '%Lab%' order by item",
                            "onchange": "Eirene.runStmt('12evp',{ID:$('#test').val()})"
                        }
                    ]
                }
            }
        }, {
            "id": "12evp",
            "name": "List Parameters",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "table",
                "tbl": "cmch_labparameters a",
                "fld": "a.parametername",
                "functionfield": [{
                        "type": "checkbox",
                        "name": "12chk",
                        "value": "<IF(b.recordstatus is null,&apos&0&apos&,&apos&1&apos&)>",
                        "prepend": 1,
                        "id": "'<a.id>'",
                        "onclick": "let chk= this.checked; if(chk){Eirene.runStmt('12evap',{parameterid:'<a.id>'})}else{Eirene.runStmt('12evdp',{parameterid:'<a.id>'})}"
                    }
                ],
                "header": "Parameter Name",
                "join": "LEFT JOIN cmch_evaluation b ON a.id=b.parameterid",
                "whr": "a.recordstatus=1 and a.itemid='||ID||'",
                "append": "<script>$('input[name=12chk][value=1]').prop('checked',true);</script>"
            }
        }, {
            "id": "12evdp",
            "name": "Delete Parameter(Evaluation Chart)",
            "sql": {
                "action": "Delete Row Permanently",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_evaluation",
                "whr": "parameterid='||parameterid||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Removed",
                "onfailure": "cmd:dom,fun:showtoast;alert;Delete Failed"
            }
        }, {
            "id": "12evap",
            "name": "Add Parameter (Evaluation Chart)",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "multistmt": [{
                        "action": "Get Value",
                        "outputto": "php",
                        "output": "porder",
                        "tbl": "cmch_evaluation",
                        "fld": "max(porder) + 1"
                    }, {
                        "action": "Save Row",
                        "command": "insertorupdate",
                        "tbl": "cmch_evaluation",
                        "fld": "parameterid, porder",
                        "fldtype": "s,n",
                        "value": "||parameterid||,||GET_porder||",
                        "whr": "parameterid='||parameterid||'",
                        "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                        "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
                    }
                ]
            }
        }, {
            "id": "12bp",
            "name": "Save Evaluation Parameter Order",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "command": "update",
                "tbl": "cmch_evaluation",
                "fld": "porder",
                "fldtype": "n",
                "value": "||porder||",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "33",
            "name": "Upload Xray",
            "sql": {
                "action": "Upload File",
                "outputto": "html",
                "output": "upload",
                "directory": "xray",
                "maxsize": "900kb",
                "filetype": "jpg,jpeg,png",
                "path": "resource/media/",
                "onsuccess": "cmd:dom,elem:a,fun:showtoast;success;Upload Successful-cmd:dom,elem:input[name=||elemname||],fun:val,val:||GET_uploadedfilename||",
                "onfailure": "cmd:dom,fun:showtoast;alert;Upload Failed"
            }
        },
        {
            "id": "13ap",
            "name": "Get Advance Print - HTML",
            "sql": {
                "action": "Get HTML",

                "outputto": "html",
                "output": "#workareaAppendix",
                "tbl": "cmch_advance a",
                "fld": "b.pname,b.pmobile,c.pcase,a.createdon",
                "join": "INNER JOIN cmch_patient b ON a.pid=b.pid LEFT JOIN (SELECT pcase,pid FROM cmch_appointment WHERE pdate<'||date||' ORDER BY pdate DESC LIMIT 1) c ON c.pid=b.pid",
                "parent": "TABLE class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:auto;margin-right:auto;font-size:0.7em'",
                "prepend": [
                    "<div><button class='button secondary no-print' onclick='printHTML(&apos;workareaAppendix&apos;)'>Print</button></div>",
                    "<center><img src='resource/image/cmch_logo1.png' width='500' height='70'>",
                    "<div>Advance Receipt No.:||advid||</div></center><center>"
                ],
                "template": [
                    "<tr><td style='border:1px solid black' class='p-1'><b>Patient ID</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pid||</td><td style='border:1px solid black' class='p-1'><b>Name</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pname||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>Date</b></td><td style='border:1px solid black' class='p-1'>||createdon||</td><td style='border:1px solid black' class='p-1'><b>Mobile No.</b></td><td style='border:1px solid black' class='p-1'>||pmobile||</td></tr>",
                    "<tr><td style='border:1px solid black' class='p-1'><b>Case Type</b></td><td style='border:1px solid black' class='p-1'>||pcase||</td><td style='border:1px solid black' class='p-1'><b>Department:</b></td><td style='border:1px solid black' class='p-1'></td></tr>"

                ],
                "whr": "a.recordstatus=1 and a.id='||ID||'",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;slow"

            }
        }, {
            "id": "13a",
            "name": "Get advance details - HTML",
            "sql": {
                "action": "Get HTML",

                "outputto": "html",
                "output": "#workareaAppendix",
                "appendoutput": 1,
                "tbl": "cmch_advance",
                "fld": "'Advance Received' as remark,advance",
                "parent": "TABLE class='font-ArialNarrow' style='margin-left: auto;margin-right:auto;margin-top:0.5cm;font-size:0.7em;width:80%;'><thead><tr><TH style='text-align:left;'>Reamrk</TH><TH style='text-align:left;'>Amount</TH></TR",
                "template": "<TR><TD style='text-align:left;'> ||remark||</TD><TD style='text-align:left;'> ||advance||</TD></TR>",
                "whr": "recordstatus=1 and id='||ID||'",
                "append": [
                    "<div class='font-ArialNarrow' style='text-align:left;font-size:0.7em'>",
                    "<span><b>Figure: </b></span>",
                    "<span id='14rftotfigure'></span>",
                    "</div>",
                    "<script>$('#14rftotfigure').html(ConvertNumberToWords($('#14rftotal').text()));</script>",
                    "<div class='row mt-4 font-ArialNarrow' style='font-size:0.7em'><div class='cell'>Prepared by</div><div class='cell font-ArialNarrow'>Checked By</div></div>"
                ],
                "onsuccess": "cmd:dom,fun:function;printHTML;workareaAppendix"
            }
        }, {
            "id": "14rg",
            "name": "Get Refund Bill - HTML",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [{
                        "action": "Get Row",
                        "outputto": "php",
                        "output": "refundtbl",
                        "tbl": "cmch_refund",
                        "fld": "DATE_FORMAT(createdon,'%d-%m-%Y %H:%i') as rfdate,remark",
                        "whr": "id='||id||'"

                    }, {
                        "action": "Get HTML",
                        "outputto": "html",
                        "output": "#workareaAppendix",
                        "tbl": "cmch_refund a",
                        "fld": "b.pname,b.pmobile,c.pcase,a.pid",
                        "join": "INNER JOIN cmch_patient b ON a.pid=b.pid LEFT JOIN (SELECT pcase,pid FROM cmch_appointment WHERE pdate<'||date||' ORDER BY pdate DESC LIMIT 1) c ON c.pid=b.pid",
                        "parent": "TABLE style='border:1px solid black;border-collapse:collapse;margin-left:auto;margin-right:auto;font-size:0.7em'",
                        "prepend": [
                            "<div><button class='button secondary no-print' onclick='printHTML(&apos;workareaAppendix&apos;)'>Print</button></div>",
                            "<center><img src='resource/image/cmch_logo1.png' width='500' height='70'>",
                            "<div>Refund No. : ||rfnum||</div></center><center>"
                        ],
                        "template": [
                            "<tr><td style='border:1px solid black' class='p-1'><b>Patient ID</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pid||</td><td style='border:1px solid black' class='p-1'><b>Name</b></td><td style='border:1px solid black;width:5cm' class='p-1'>||pname||</td></tr>",
                            "<tr><td style='border:1px solid black' class='p-1'><b>Date</b></td><td style='border:1px solid black' class='p-1'>||GET_refundtbl_rfdate||</td><td style='border:1px solid black' class='p-1'><b>Mobile No.</b></td><td style='border:1px solid black' class='p-1'>||pmobile||</td></tr>",
                            "<tr><td style='border:1px solid black' class='p-1'><b>Case Type</b></td><td style='border:1px solid black' class='p-1'>||pcase||</td><td style='border:1px solid black' class='p-1'><b>Department:</b></td><td style='border:1px solid black' class='p-1'></td></tr>"

                        ],
                        "whr": "a.recordstatus=1 and a.rfnum=||rfnum||",
                        "onsuccess": "cmd:dom,fun:function;convertSelect;#workareaTablebox-cmd:dom,fun:show;#workareaFilter1;slow-cmd:dom,fun:show;#workareaAppendix;slow"

                    }
                ]
            }
        }, {
            "id": "14rfr",
            "name": "refund from advance(Reduction)",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "output": "res",
                "multistmt": [{
                        "action": "Save Row",
                        "outputto": "php",
                        "output": "res",
                        "tbl": "cmch_advance",
                        "fld": "balance",
                        "value": "(||GET_balance_balance||-||refund||)",
                        "fldtype": "n",
                        "command": "update",
                        "whr": "advanceid='||GET_balance_advanceid||'",
                        "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                        "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed1"
                    }, {
                        "action": "Save Row",
                        "tbl": "cmch_refund",
                        "fld": "pid,refund,remark,rfnum",
                        "value": "||pid||,||refund||,||remark||,||GET_rfnum||",
                        "fldtype": "s,n,s,n",
                        "command": "insert",
                        "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful-cmd:dom,fun:val;input[name=pid];BLANK",
                        "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
                    }
                ]
            }
        },{
            "id": "15svdi",
            "name": "Save Discharge Summary",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_ipdischarge",
                "fld": "details,cause,labreport,dischargenotes,advice,issuefollowup,nextdate,bowelhabits,micturition,sleep,diet,calciumintake,physicalactivity,sunlightexplosure,currentmedication,height,weight,pulse,bp,pallor,lymphnodes,goiter,oedema,skin,peripheralpulses,feet,cvs,trachea,respiratorymovements,percussion,auscultation,abdomen,cns,fundi,reflexes,plantar,vibrationsense,chvostekssign,proximalweaknesss,dexareport,xray,ecg",
                "value": "||details||,||cause||,||labreport||,||dischargenotes||,||advice||,||issuefollowup||,||nextdate||,||bowelhabits||,||micturition||,||sleep||,||diet||,||calciumintake||,||physicalactivity||,||sunlightexplosure||,||currentmedication||,||height||,||weight||,||pulse||,||bp||,||pallor||,||lymphnodes||,||goiter||,||oedema||,||skin||,||peripheralpulses||,||feet||,||cvs||,||trachea||,||respiratorymovements||,||percussion||,||auscultation||,||abdomen||,||cns||,||fundi||,||reflexes||,||plantar||,||vibrationsense||,||chvostekssign||,||proximalweaknesss||,||dexareport||,||xray||,||ecg||",
                "fldtype": "s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,n,n,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s",
                "command": "update",
                "whr": "ipid='||ipid||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful-15sdp",
                "onfailure": "15sdp"
            }
        }, {
            "id": "15sdp",
            "name": "Save Discharge Summary(Patient table)",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_patient",
                "fld": "pasthistory,pastsurgery,familyhistory",
                "value": "||pasthistory||,||pastsurgery||,||familyhistory||",
                "fldtype": "s,s,s",
                "command": "update",
                "whr": "pid='||pid||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful"
            }
        }, {
            "id": "15dr1",
            "name": "Save Discharge Summary",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_ipdischarge",
                "fld": "reflexesbicepsrt",
                "value": "||r1||",
                "fldtype": "s",
                "command": "update",
                "whr": "ipid='||ipid||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "15svd1",
            "name": "Save Discharge Summary",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "cmch_iptreatment",
                "fld": "diagnosis",
                "value": "||diagnosis||",
                "fldtype": "s",
                "command": "update",
                "whr": "ipid='||ipid||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "15gtip",
            "name": "Get Discharge Details",
            "sql": {
                "action": "Get Row",
                "outputto": "html",
                "output": "edit",
                "tbl": "cmch_ipdischarge a",
                "fld": "a.ipid,a.pid,a.details,a.cause,a.labreport,a.dischargenotes,a.advice,a.issuefollowup,a.nextdate,a.bowelhabits,a.micturition,a.sleep,a.diet,a.calciumintake,a.physicalactivity,a.sunlightexplosure,a.currentmedication,a.height,a.weight,a.pulse,a.bp,a.pallor,a.lymphnodes,a.goiter,a.oedema,a.skin,a.peripheralpulses,a.feet,a.cvs,a.trachea,a.respiratorymovements,a.percussion,a.auscultation,a.abdomen,a.cns,a.fundi,a.reflexes,a.plantar,a.vibrationsense,a.chvostekssign,a.proximalweaknesss,a.dexareport,a.xray,a.ecg,b.pasthistory,b.familyhistory,b.pastsurgery",
                "join": "INNER JOIN cmch_patient b ON a.pid=b.pid",
                "whr": "ipid='||ID||'",
                "jsfunction": "edit1"
            }
        }, {
            "id": "15g",
            "name": "Get Discharge Details",
            "sql": {
                "action": "Get Row",
                "outputto": "html",
                "output": "edit",
                "tbl": "cmch_ip",
                "fld": "pid",
                "whr": "id='||ID||'",
                "jsfunction": "edit1"
            }
        }, {
            "id": "15pr1",
            "name": "Get Discharge HTML(Patient details)",
            "sql": {
                "action": "MULTISTMT",
                "outputto": "php",
                "multistmt": [{
                        "action": "Get Row",
                        "outputto": "php",
                        "output": "ndate",
                        "tbl": "cmch_ipdischarge",
                        "fld": "DATE_FORMAT(nextdate,'%d-%m-%Y %H:%i') as nextdate",
                        "whr": "ipid='||id||'"
                    }, {
                        "action": "Get Row",
                        "outputto": "php",
                        "output": "dates",
                        "tbl": "cmch_ip",
                        "fld": "DATE_FORMAT(addate,'%d-%m-%Y %H:%i') as addate, DATE_FORMAT(didate,'%d-%m-%Y %H:%i') as didate",
                        "whr": "id='||id||'"
                    }
                ]
            }
        }, {
            "id": "15pr",
            "name": "Get Discharge HTML(Patient details)",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#workareaAppendix",
                "prepend": [
                    "<center><img src='resource/image/cmch_logo1.png' width='400' height='60'></center>",
                    "<DIV class='font-ArialNarrow'><center><h6>Discharge Summary<h6></center></DIV>"
                ],
                "template": [
                    "<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:2cm;margin-right:3cm;margin-top:10px;width:80%;font-size:0.8em'>",
                    "<tr><td style='border:1px solid black;width:110px' class='pl-1'><b>Name</b></td><td style='border:1px solid black;' class='p-1'>||pname||</td><td style='border:1px solid black;width:110px' class='p-1'><b>Patient ID</b></td><td style='border:1px solid black' class='p-1'>||pid||</td></tr>",
                    "<tr><td style='border:1px solid black;width:110px ' class='p-1'><b>Gender</b></td>", 
					"<td style='border:1px solid black' class='p-1'>||pgender||</td>",					
                    "<td style='border:1px solid black;width:110px' class='pl-1'><b>Admission Date</b></td><td style='border:1px solid black' class='p-1'>||GET_dates_addate||</td><tr>",
                    "<tr><td style='border:1px solid black;width:110px' class='pl-1'><b>Age</b></td><td style='border:1px solid black;' class='p-1'>||age||</td><td style='border:1px solid black;width:110px' class='p-1'><b>Discharge Date</b></td><td style='border:1px solid black;' class='p-1'>||GET_dates_didate||</td></tr>",
                    "<tr><td style='border:1px solid black;width:110px' class='pl-1'><b>Follow Up Date</b></td><td style='border:1px solid black' class='p-1'>||GET_ndate_nextdate||</td><td style='border:1px solid black;width:110px' class='p-1'><b>Address<b></td><td style='border:1px solid black' class='p-1'>||pward||,||pcity||,||pdistrict||,||pstate||</td></tr>",
                    "</table>"
                ],
                "tbl": "cmch_ipdischarge a",
                "fld": "a.pid,a.bowelhabits,a.micturition,a.sleep,a.diet,a.calciumintake,a.physicalactivity,a.sunlightexplosure,a.currentmedication,a.height,a.weight,a.pulse,a.bp,a.pallor,a.lymphnodes,a.goiter,a.oedema,a.skin,a.peripheralpulses,a.feet,a.cvs,a.trachea,a.respiratorymovements,a.percussion,a.auscultation,a.abdomen,a.fundi,a.cns,a.reflexes,a.plantar,a.vibrationsense,a.chvostekssign,a.proximalweaknesss,a.dexareport,a.xray,a.ecg,b.pname,(YEAR(CURDATE())-b.pyob) as age,b.pasthistory,b.pastsurgery,b.familyhistory,e.addate,e.didate,a.nextdate,d.diagnosis,a.cause,a.labreport,d.medicare,d.medicare1,a.dischargenotes,a.advice,a.issuefollowup,a.nextdate,a.details,b.pward,b.pcity,b.pdistrict,b.pstate,b.pgender",
                "join": [
                    "LEFT JOIN cmch_patient b ON a.pid= b.pid",
                    "LEFT JOIN cmch_iptreatment d ON a.ipid=d.ipid",
                    "LEFT JOIN cmch_ip e ON a.ipid=e.id",
                    "LEFT JOIN cmch_doctors c ON e.docid=c.id"
                ],
                "whr": "a.ipid='||id||'",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast"
            }

        }, {
            "id": "20",
            "name": "Print Discharge Form",
            "sql": {
                "action": "Print Form",
                "appendoutput": 1,
                "output": "#workareaAppendix",
                "tbl": "cmch_ipdischarge a",
                "fld": "a.pid,a.bowelhabits,a.micturition,a.sleep,a.diet,a.calciumintake,a.physicalactivity,a.sunlightexplosure,a.currentmedication,a.height,a.weight,a.pulse,a.bp,a.pallor,a.lymphnodes,a.goiter,a.oedema,a.skin,a.peripheralpulses,a.feet,a.cvs,a.trachea,a.respiratorymovements,a.percussion,a.auscultation,a.abdomen,a.fundi,a.cns,a.reflexes,a.plantar,a.vibrationsense,a.chvostekssign,a.proximalweaknesss,a.dexareport,a.xray,a.ecg,b.pname,(YEAR(CURDATE())-b.pyob) as age,b.pasthistory,b.pastsurgery,b.familyhistory,e.addate,e.didate,a.nextdate,d.diagnosis,a.cause,a.labreport,d.medicare,d.medicare1,a.dischargenotes,a.advice,a.issuefollowup,a.nextdate,a.details,b.pward,b.pcity,b.pdistrict,b.pstate,b.pgender,ROUND(((a.weight/a.height/a.height)*10000),2) as bmi,IF(b.pgender=0,ROUND((50+(0.91*(a.height-152.4))),2),'') ibwm,IF(b.pgender=1,ROUND((45.5+(0.91*(a.height-152.4))),2),'') ibwf,IF(b.pgender=0,ROUND((a.weight-(50+(0.91*(a.height-152.4)))),2),'') overweightm,IF(b.pgender=1,ROUND((a.weight-(45.5+(0.91*(a.height-152.4)))),2),'') overweightf",
                "join": [
                    "LEFT JOIN cmch_patient b ON a.pid= b.pid",
                    "LEFT JOIN cmch_iptreatment d ON a.ipid=d.ipid",
                    "LEFT JOIN cmch_ip e ON a.ipid=e.id",
                    "LEFT JOIN cmch_doctors c ON e.docid=c.id"
                ],
                "append": [
                    "<div class='font-ArialNarrow' style='margin-left:2cm;margin-top:60px;font-size:0.8em'>Signature of the Attending Physician/Doctor:</div>",
                    "<div class='font-ArialNarrow' style='margin-left:2cm;font-size:0.8em'>Date:</div>",
                    "<div class='font-ArialNarrow' style='margin-left:2cm;font-size:0.8em'>Dept of Medicine,CMCH</div>"
                ],
                "whr": "a.ipid='||id||'",
                "formname": "discharge",
                "parent": "table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:2cm;margin-right:3cm;margin-top:30px;width:80%;font-size:0.8em'",
                "template": "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>||label||</b></td></tr><tr><td style='padding:4px' class='pl-2'>||value||</td></tr>",
                "templateforgroup": "<b>||label||</b>: ||value||<br>",
                "template1": "<span class='mr-3'><b>||label||</b>: ||value||</span>",
                "structure": [
                    "diagnosis", "details", "cause", "pasthistory", "pastsurgery", "familyhistory", {
                        "label": "Habits",
                        "grp": [
                            "bowelhabits",
                            "micturition",
                            "sleep",
                            "diet",
                            "calciumintake",
                            "sunlightexplosure",
                            "physicalactivity"
                        ]
                    },
                    "currentmedication", {
                        "label": "On Examination",
                        "template": "template1",
                        "grp": [
                            "height",
                            "weight",
                            "bmi",
                            "ibwf",
                            "ibwm",
                            "overweightf",
                            "overweightm",
                            "pulse",
                            "bp",
                            "pallor",
                            "lymphnodes",
                            "goiter",
                            "oedema",
                            "skin",
                            "peripheralpulses",
                            "feet",
                            "cvs",
                            "respiratorymovements",
                            "percussion",
                            "auscultation",
                            "abdomen",
                            "cns",
                            "fundi",
                            "reflexes",
                            "plantar",
                            "vibrationsense",
                            "chvostekssign",
                            "proximalweaknesss"
                        ]
                    },
                    "dexareport",
                    "xray",
                    "ecg",
                    "labreport", {
                        "label": "Treatment Detail",
                        "grp": [
                            "medicare",
                            "medicare1"
                        ]
                    },
                    "dischargenotes",
                    "advice",
                    "issuefollowup"

                ],
                "printemptyvalue": 0,
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;slow-cmd:dom,fun:function;printHTML;workareaAppendix"
            }
        }, {
            "id": "15prd1",
            "name": "Get Discharge HTML(Patient details)",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#workareaAppendix",
                "appendoutput": 1,
                "template": [
                    "<table class='font-ArialNarrow' style='border:1px solid black;border-collapse:collapse;margin-left:2cm;margin-right:3cm;font-size:0.9em;width:80%;margin-top:30px'>",
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Diagnosis<bb></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||diagnosis||</td></tr>",
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Details at Presentation</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||details||</td></tr>",
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Cause for Admission</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||cause||</td></tr>",

                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Past History</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||pasthistory||</td></tr>",
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Past Surgery</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||pastsurgery||</td></tr>",
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Family History</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||familyhistory||</td></tr>",

                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Habits</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'><b>Bowel Habits:</b>&nbsp;||bowelhabits||<br>",
                    "<b>Micturition:&nbsp;</b>||micturition||<br><b>Sleep:</b>&nbsp;||sleep||<br><b>Diet:</b>&nbsp;||diet||<br><b>Calcium Intake:</b>&nbsp;||calciumintake||<br>",
                    "<b>Physical Activity:</b>&nbsp;||physicalactivity||<br><b>Sunlight Explosure:&nbsp;</b>||sunlightexplosure||<br>",

                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Current Medication</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||currentmedication||</td></tr>",

                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>On Examination</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'><b>Height:</b>&nbsp;||height||&nbsp;cm&nbsp;&nbsp; <b>Weight:</b>&nbsp;||weight||&nbsp;kg &nbsp;&nbsp;<b>BMI:</b>&nbsp;||bmi||&nbsp;kgs<br>",
                    "<b>Ideal body weight:</b>", {
                        "if": "||pgender|| = Male",                        
                        "then": "&nbsp;&nbsp;||ibwm||&nbsp;kg<b>&nbsp;&nbsp;Overweight:&nbsp;&nbsp;</b>||overweightm||&nbsp;kg<br>",
                        "else": "&nbsp;&nbsp;||ibwf||&nbsp;kg<b>&nbsp;&nbsp;Overweight:&nbsp;&nbsp;</b>||overweightf||&nbsp;kg<br>"
                    },
                    "<b>Pulse:</b>&nbsp;&nbsp;||pulse||&nbsp;per min <b>&nbsp;&nbsp;&nbsp;&nbsp;BP:</b>||bp||&nbsp;mm of Hg<br>",
                    "<b>Pallor:</b>&nbsp;&nbsp;||pallor|| <b>&nbsp;&nbsp;&nbsp;&nbsp;Lymph nodes:</b>&nbsp;&nbsp;||lymphnodes|| <b>&nbsp;&nbsp;&nbsp;&nbsp;Goiter:</b>&nbsp;&nbsp;||goiter|| &nbsp;&nbsp;&nbsp;&nbsp;<b>Oedema:</b>&nbsp;&nbsp;||oedema||<br>",
                    "<b>Skin:&nbsp;&nbsp;</b>||skin||<br>",
                    "<b>Peripheral Pulses:</b>&nbsp;&nbsp;||peripheralpulses||<br>",
                    "<b>Feet:</b>&nbsp;&nbsp;||feet||<br>",
                    "<b>CVS:</b>&nbsp;&nbsp;||cvs||<br>",
                    "<b>Respiratory System</b><br>",
                    "<b>Trachea:</b>&nbsp;&nbsp;||trachea||<br>",
                    "<b>Respiratory Movements:</b>&nbsp;&nbsp;||respiratorymovements||<br>",
                    "<b>Percussion:</b>&nbsp;&nbsp;||percussion||<br>",
                    "<b>Auscultation:</b>&nbsp;&nbsp;||auscultation||<br>",
                    "<b>Abdomen:</b>&nbsp;&nbsp;||abdomen||<br>",
                    "<b>CNS:&nbsp;&nbsp;</b>||cns||<br><b>Fundi:</b>&nbsp;&nbsp;||fundi||<br>",
                    "<b>Reflexes:&nbsp;&nbsp;</b>||reflexes||",
                    "<b>Plantar</b>:&nbsp;&nbsp;||plantar||<br>",
                    "<b>Vibration Sense:&nbsp;&nbsp;</b>||vibrationsense||<br>",
                    "<b>Chvosteks Sign:&nbsp;&nbsp;</b>||chvostekssign||<br>",
                    "<b>Proximal Weaknesss:</b>&nbsp;&nbsp;||proximalweaknesss||<br>"
                ],
                "tbl": "cmch_ipdischarge a",
                "fld": "a.pid,a.bowelhabits,a.micturition,a.sleep,a.diet,a.calciumintake,a.physicalactivity,a.sunlightexplosure,a.currentmedication,a.height,a.weight,a.pulse,a.bp,a.pallor,a.lymphnodes,a.goiter,a.oedema,a.skin,a.peripheralpulses,a.feet,a.cvs,a.trachea,a.respiratorymovements,a.percussion,a.auscultation,a.abdomen,a.fundi,a.cns,a.reflexes,a.plantar,a.vibrationsense,a.chvostekssign,a.proximalweaknesss,a.dexareport,a.xray,a.ecg,b.pname,(YEAR(CURDATE())-b.pyob) as age,b.pasthistory,b.pastsurgery,b.familyhistory,e.addate,e.didate,a.nextdate,d.diagnosis,a.cause,a.labreport,d.medicare,d.medicare1,a.dischargenotes,a.advice,a.issuefollowup,a.nextdate,a.details,b.pward,b.pcity,b.pdistrict,b.pstate,b.pgender,((a.weight/a.height/a.height)*10000) as bmi,(50+(0.91*(a.height-152.4))) as ibwm,(45.5+(0.91*(a.height-152.4))) as ibwf,(a.weight-(50+(0.91*(a.height-152.4)))) as overweightm,(a.weight-(45.5+(0.91*(a.height-152.4)))) as overweightf",
                "join": [
                    "LEFT JOIN cmch_patient b ON a.pid= b.pid",
                    "LEFT JOIN cmch_iptreatment d ON a.ipid=d.ipid",
                    "LEFT JOIN cmch_ip e ON a.ipid=e.id",
                    "LEFT JOIN cmch_doctors c ON e.docid=c.id"
                ],
                "whr": "a.ipid='||id||'",
                "onsuccess": "15prd2"
            }
        }, {
            "id": "15prd2",
            "name": "Get Discharge HTML(Patient details)",
            "sql": {
                "action": "Get HTML",
                "outputto": "html",
                "output": "#workareaAppendix",
                "appendoutput": 1,
                "template": [
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>DEXA REPORT</b><td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||dexareport||</td></tr>",

                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>X-RAY</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||xray||</td></tr>",

                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>ECG</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||ecg||</td></tr>",

                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Lab Reports</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||labreport||</td></tr>",
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Treatment Details</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'><b>Regular:</b>||medicare||</td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'><b>Important:</b>||medicare1||</td></tr>",
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Discharge Notes</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||dischargenotes||</td></tr>",
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Advice at Discharge</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||advice||</td></tr>",
                    "<tr><td style='Background-color:#A3A3A3;padding:4px' class='pl-2'><b>Issues to be Addressed at follow up</b></td></tr>",
                    "<tr><td style='border:1px solid black;padding:4px' class='pl-2'>||issuefollowup||</td></tr>",
                    "</table>"
                ],
                "append": [
                    "<div class='font-ArialNarrow' style='margin-left:2cm;margin-top:60px;font-size:0.8em'>Signature of the Attending Physician/Doctor:</div>",
                    "<div class='font-ArialNarrow' style='margin-left:2cm;font-size:0.8em'>Date:</div>",
                    "<div class='font-ArialNarrow' style='margin-left:2cm;font-size:0.8em'>Dept of Medicine,CMCH</div>"
                ],
                "tbl": "cmch_ipdischarge a",
                "fld": "a.pid,a.bowelhabits,a.micturition,a.sleep,a.diet,a.calciumintake,a.physicalactivity,a.sunlightexplosure,a.currentmedication,a.height,a.weight,a.pulse,a.bp,a.pallor,a.lymphnodes,a.goiter,a.oedema,a.skin,a.peripheralpulses,a.feet,a.cvs,a.trachea,a.respiratorymovements,a.percussion,a.auscultation,a.abdomen,a.fundi,a.cns,a.reflexes,a.plantar,a.vibrationsense,a.chvostekssign,a.proximalweaknesss,a.dexareport,a.xray,a.ecg,b.pname,(YEAR(CURDATE())-b.pyob) as age,b.pasthistory,b.pastsurgery,b.familyhistory,e.addate,e.didate,a.nextdate,d.diagnosis,a.cause,a.labreport,d.medicare,d.medicare1,a.dischargenotes,a.advice,a.issuefollowup,a.nextdate,a.details,b.pward,b.pcity,b.pdistrict,b.pstate,b.pgender",
                "join": [
                    "LEFT JOIN cmch_patient b ON a.pid= b.pid",
                    "LEFT JOIN cmch_iptreatment d ON a.ipid=d.ipid",
                    "LEFT JOIN cmch_ip e ON a.ipid=e.id",
                    "LEFT JOIN cmch_doctors c ON e.docid=c.id"
                ],
                "whr": "a.ipid='||id||'",
                "onsuccess": "cmd:dom,fun:show;#workareaAppendix;fast-cmd:dom,fun:function;printHTML;workareaAppendix"
            }
        }, {
            "id": "16",
            "name": "Settings",
            "sql": {
                "action": "Get Table",
                "outputto": "html",
                "output": "table",
                "tbl": "eirene_meta",
                "fld": "pname",
                "functionfield": [{
                        "type": "text",
                        "value": "<pdata>",
                        "caption": "Departments",
                        "onblur": "Eirene.runStmt('svdpt',{ID:'<id>',value:$(this).val()})"
                    }

                ],
                "header": "Department",
                "commaseperatedfld": true,
                "whr": "recordstatus=1 and pluginid1='||pluginid||'",
                "onsuccess": "cmd:dom,fun:show;#workareaFilter;slow-cmd:dom,fun:empty;#workareaFilter1;slow-cmd:dom,fun:hide;#workareaAppendix;slow"
            }
        }, {
            "id": "16btn",
            "name": "Settings button",
            "sql": {
                "action": "Return",
                "output": "php",
                "outputto": "demo",
                "elem": {
                    "parent": "div",
                    "output": "#workareaFilter",
                    "elem": [{
                            "name": "f1",
                            "type": "button",
                            "value": "General",
                            "onclick": "Eirene.runStmt('16')"
                        }, {
                            "name": "f2",
                            "type": "button",
                            "value": "Evaluation Chart",
                            "onclick": "Eirene.runStmt('12b-12bp1')"
                        }
                    ]
                },
                "onsuccess": "cmd:dom,fun:show;#workareaFilter1;slow"
            }
        }, {
            "id": "svdpt",
            "name": "Save Departmets",
            "sql": {
                "action": "Save Row",
                "outputto": "php",
                "output": "res",
                "tbl": "eirene_meta",
                "fld": "pdata",
                "value": "||value||",
                "fldtype": "s",
                "command": "update",
                "whr": "id='||ID||'",
                "onsuccess": "cmd:dom,fun:showtoast;success;Saving Successful",
                "onfailure": "cmd:dom,fun:showtoast;alert;Saving Failed"
            }
        }, {
            "id": "19sum",
            "name": "Pending Bill Summary",
            "sql": {
                "action": "Get Matrix",
                "row": "department",
                "col": "category",
                "val": "pending",
                "outputto": "html",
                "output": "#workareaTablebox",
                "appendoutput": 1,
                "horizontalsum": "1",
                "verticalsum": "1",
                "tbl": "cmch_printbill a",
                "join": [
                    "INNER JOIN cmch_bill b ON a.billno=b.billno",
                    "LEFT JOIN cmch_payment c on a.billno=c.billno"
                ],
                "fld": "a.department,b.category,SUM(b.total) as pending",
                "whr": [
                    "a.recordstatus=1",
                    "and DATE(a.createdon)>='||fromdate||' and DATE(a.createdon)<='||todate||'",
                    "and c.amount is null"
                ],
                "grp": "a.department,b.category",
                "class": "dataTable font-ArialNarrow",
                "style": "border:1px solid black;border-collapse:collapse;margin-left:2cm;margin-top:0.5cm;width:75%;font-size:0.8em",
                "horizontalsum": "1",
                "verticalsum": "1",
                "class": "eirene-table dataTable",
                "prepend": "<center><h6 class='mt-3'>Pending Payment Report</h6>From: ||fromdate|| to ||todate||</center>"
            }
        }, {
            "id": "20",
            "name": "Report Buttons",
            "sql": {
                "action": "Return",
                "outputto": "php",
                "output": "res",
                "value": [{
                        "elem": {
                            "outputto": "html",
                            "output": "#workareaFilter",
                            "elem": [{
                                    "name": "20b1",
                                    "id": "20b1",
                                    "type": "buttonspan",
                                    "icon": "mif-printer",
                                    "onclick": "printHTML('workareaTablebox')"
                                }, {
                                    "name": "20b2",
                                    "id": "20b2",
                                    "type": "button",
                                    "value": "Income-Monthly",
                                    "onclick": "Eirene.runStmt('20a')"
                                }
                            ]
                        }

                    }
                ],
                "onsuccess": "cmd:dom,fun:show;#workareaFilter"
            }
        }, {
            "id": "20a",
            "name": "Report-Income-Monthly",
            "sql": {
                "action": "Get Matrix",
                "output": "#workareaTablebox",
                "row": "category",
                "col": "dt",
                "val": "tot",
                "horizontalsum": 1,
                "verticalsum": 1,                
                "tbl": "cmch_printbill a",
                "join": "INNER JOIN cmch_bill b ON a.billno=b.billno",
                "fld": "DATE_FORMAT(a.createdon, '%b-%Y') as dt,b.category,SUM(b.total) as tot",
                "whr": "DATE(a.createdon) between DATE_ADD(CURDATE(),interval -1 year) and curdate()",
                "grp": "DATE_FORMAT(a.createdon, '%b-%Y'),a.paystatus,b.category",
                "srt": "a.createdon",
                "prepend": "<h2 class='mt-3'>Report - Income Monthly</h2>",
                "header": "Status,Amount",
                "class": "eirene-table dataTable"
            }
        },
		{
			"id":"patser",
			"name":"Patient Service",
			"sql":{
				"action":"Get HTML",
				"tbl":"cmch_ip a","output":"#workareaTablebox",
				"validate":"none",
				"join":[
					"INNER JOIN cmch_iptreatment c ON a.id=c.ipid",
					"INNER JOIN cmch_patient d on a.pid=d.pid"
				],
				"fld":"a.pid,d.pname,c.diagnosis,c.medicare,c.medicare1,nursecare,newlabtests",
				"template":[
					"||pid||: <b>||pname||</b><br>",
					"<b>Diagnosis</b><br>||diagnosis||<br><br>",
					"<b>Med Care</b><br>||medicare||<br><br>",
					"<b>Important Med Care</b><br>||medicare1||<br><br>",
					"<b>Nursing Care</b><br>||nursecare||<br><br>",
					"<b>New Lab Tests</b><br>||newlabtests||"
				],
				"whr":"a.pid='||pid||'",
				"srt":"a.createdon desc",
				"limit":"1"
			}
		}
    ]
}