TaskController.class.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. error_reporting(0);
  3. if (!defined('IS_INITPHP')) exit('Access Denied!');
  4. class TaskController extends BaseController {
  5. public function IndexAction(){
  6. $this->display();
  7. }
  8. //下发Sms
  9. public function goSMSAction(){
  10. $key =I('key');
  11. if($key=="gosms")
  12. {
  13. //$url='http://121.14.17.208/Server/SMS_Send.aspx?sn=SDK-NFY-020-00011&pwd=NFYYYYGHAPP&mobile=18011770183&content=%e4%bd%a0%e5%a5%bd&ext=1';
  14. //$html = file_get_contents($url);
  15. //echo $html;
  16. }
  17. }
  18. //下发DDPUSH
  19. public function goDDPushAction(){
  20. $key =I('key');
  21. if($key=="goddpushtask")
  22. {
  23. includeIfExist(C('APP_FULL_PATH').'/Lib/DDPusher.class.php');
  24. try {
  25. $serverIp =C('PushServerIp');
  26. $serverPort =C('PushServerPort');
  27. $appId =C('PushAppId');
  28. $version =C('PushVersion');
  29. $ddpush = new DDpusher($serverIp,$serverPort);
  30. $sqlString = "SELECT * FROM hz_pushtask p,hz_customeruser c WHERE p.customerUserId=c.id AND c.timestamp+180000>UNIX_TIMESTAMP() AND c.uuid<>'' AND devType='android' AND p.pushStatus='run' AND p.pushTime>=DATE_SUB(SYSDATE(),INTERVAL 0 MINUTE) AND p.pushTime<=DATE_ADD(SYSDATE(),INTERVAL 1 MINUTE)";
  31. //$sqlString = "SELECT p.*,c.uuid FROM hz_pushtask p,hz_customeruser c WHERE p.customerUserId=c.id AND c.timestamp+1800000>UNIX_TIMESTAMP() AND p.pushStatus='run'";
  32. $sqlData = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"list");
  33. foreach($sqlData as $key=>$v){
  34. //规则 uid※keyid※content※url※parameter※type※pushTime
  35. //规则 uid※keyid※contente※pushTime※eventType※parameter
  36. $data = $v["customerUserId"]."※".$v["id"]."※".$v["content"]."※".$v["pushTime"]."※".$v["eventType"]."※".$v["parameter"];
  37. $ddpush->push0x20($v["uuid"],$data,$version,$appId);
  38. }
  39. } catch (Exception $ex) {
  40. echo $ex->getMessage();
  41. }
  42. echo '下发成功';
  43. }
  44. }
  45. //同步HIS号源,删除今天之前的号源记录
  46. //生成用药计划
  47. public function goHospitalAppointsAction(){
  48. $key =I('key');
  49. if($key=="gohospitalappointstask")
  50. {
  51. $hospitalId =C('HOSPITALID');
  52. $hisUrl =C('HIS_URL');
  53. $maxRegDays =C('maxRegDays');
  54. $appKey= md5(C('APPKEY')."|".date("Y-m-d", time()));
  55. //$this->getHospitalInfo($hospitalId,$hisUrl,$appKey);
  56. $this->getDeptInfo($hospitalId,$hisUrl,$appKey);
  57. $this->getDoctorInfo($hospitalId,$hisUrl,$appKey);
  58. //$this->getRegInfo($hospitalId,$hisUrl,$appKey,$maxRegDays);
  59. //删除今天前的数据
  60. //$this->delRegList();
  61. }
  62. }
  63. //同步HIS号源,删除今天之前的号源记录
  64. //生成用药计划
  65. public function goAllRegInfoAction(){
  66. $key =I('key');
  67. if($key=="goallreginfotask")
  68. {
  69. $hospitalId =C('HOSPITALID');
  70. $hisUrl =C('HIS_URL');
  71. $maxRegDays =C('maxRegDays');
  72. $appKey= md5(C('APPKEY')."|".date("Y-m-d", time()));
  73. $this->getRegInfo($hospitalId,$hisUrl,$appKey,$maxRegDays);
  74. }
  75. }
  76. //生成用药计划
  77. public function goMedicineAction(){
  78. $key =I('key');
  79. if($key=="gomedicinetask")
  80. {
  81. $this->codeMedicine();
  82. }
  83. }
  84. //删除短信列表
  85. public function goVerifySmsCodeAction(){
  86. $key =I('key');
  87. if($key=="goverifysmscodetask")
  88. {
  89. $this->delVerifySmsCode();
  90. }
  91. }
  92. public function goFavoriteNumAction(){
  93. $key =I('key');
  94. if($key=="gofavoritenumtask")
  95. {
  96. $this->getFavoriteNum();
  97. }
  98. }
  99. //同步HIS号源,删除今天之前的号源记录
  100. //生成用药计划
  101. public function goSynRegInfoAction(){
  102. $key =I('key');
  103. if($key=="gosynreginfotask")
  104. {
  105. $hospitalId =C('HOSPITALID');
  106. $hisUrl =C('HIS_URL');
  107. $appKey= md5(C('APPKEY')."|".date("Y-m-d", time()));
  108. $this->getRegSynInfo($hospitalId,$hisUrl,$appKey);
  109. }
  110. }
  111. //删除号源表今天前的数据
  112. public function delRegList() {
  113. $sqlString ="DELETE FROM hz_reginfo WHERE regDate<DATE('".date("Y-m-d", time())."')";
  114. $sqlData = call_user_func(array($_ENV["dbDao"],"delete"),$sqlString,"entity");
  115. }
  116. //删除短信验证码今天前的数据
  117. public function delVerifySmsCode() {
  118. $sqlString ="DELETE FROM hz_verifysmscode WHERE DATE(createtime)<DATE('".date("Y-m-d", time())."')";
  119. $sqlData = call_user_func(array($_ENV["dbDao"],"delete"),$sqlString,"entity");
  120. }
  121. //医院信息查询接口
  122. public function getHospitalInfo($hospitalId,$hisUrl,$appKey) {
  123. $postData="<?xml version=\"1.0\" encoding=\"UTF-8\"?><req><hospitalId>$hospitalId</hospitalId></req>";
  124. $postUrl = $hisUrl."doReqToHis.aspx?service=getHospitalInfo&appkey=".$appKey;
  125. $xmldata = call_user_func(array($_ENV["commonClass"],"sendDataByCurl"),$postUrl,$postData);
  126. $sqlString ="select id from hz_hospitalinfo where hospitalId='$hospitalId'";
  127. $sqlData = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"entity");
  128. if ($sqlData) {
  129. $sqlString ="update hz_hospitalinfo set hospitalName='".trim(strval($xmldata->hospitalName))."',addr='".trim(strval($xmldata->addr))."',tel='".trim(strval($xmldata->tel))."',webSite='".trim(strval($xmldata->webSite))."',hospitalLevel='".trim(strval($xmldata->hospLevel))."',hospitalArea='".trim(strval($xmldata->hospArea))."',info='".trim(strval($xmldata->desc))."',maxRegDays='".trim(strval($xmldata->maxRegDays))."',startRegTime='".trim(strval($xmldata->startRegTime))."',stopRegTime='".trim(strval($xmldata->stopRegTime))."',stopBookTimeM='".trim(strval($xmldata->stopBookTimeM))."',stopBookTimeA='".trim(strval($xmldata->stopBookTimeA))."' where hospitalId='$hospitalId'";
  130. call_user_func(array($_ENV["dbDao"],"update"),$sqlString,"return");
  131. }else{
  132. $sqlString ="insert into hz_hospitalinfo(hospitalId,hospitalName,addr,tel,webSite,hospitalLevel,hospitalArea,info,maxRegDays,startRegTime,stopRegTime,stopBookTimeM,stopBookTimeA,createDate) VALUES('".$hospitalId."','".trim(strval($xmldata->hospitalName))."','".trim(strval($xmldata->addr))."','".trim(strval($xmldata->tel))."','".trim(strval($xmldata->webSite))."','".trim(strval($xmldata->hospLevel))."','".trim(strval($xmldata->hospArea))."','".trim(strval($xmldata->desc))."','".trim(strval($xmldata->maxRegDays))."','".trim(strval($xmldata->startRegTime))."','".trim(strval($xmldata->stopRegTime))."','".trim(strval($xmldata->stopBookTimeM))."','".trim(strval($xmldata->stopBookTimeA))."','".date("Y-m-d H:i:s", time())."')";
  133. call_user_func(array($_ENV["dbDao"],"insert"),$sqlString,"return");
  134. }
  135. }
  136. //科室信息查询接口
  137. public function getDeptInfo($hospitalId,$hisUrl,$appKey) {
  138. $postData="<?xml version=\"1.0\" encoding=\"UTF-8\"?><req><hospitalId>$hospitalId</hospitalId><deptId></deptId></req>";
  139. $postUrl = $hisUrl."?c=NfyyApi&a=getDeptInfo&appkey=".$appKey;
  140. $xmldata = call_user_func(array($_ENV["commonClass"],"sendDataByCurl"),$postUrl,$postData);
  141. foreach($xmldata as $key=>$value){
  142. $sqlString ="select id from hz_deptinfo where hospitalId='$hospitalId' and deptId ='$value->deptId'";
  143. $sqlData = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"entity");
  144. if ($sqlData) {
  145. $sqlString ="update hz_deptinfo set deptId='$value->deptId',deptName='$value->deptName',parentId='$value->parentId',visitAddress='$value->visitAddress',info='$value->desc' where id='".$sqlData['id']."'";
  146. call_user_func(array($_ENV["dbDao"],"update"),$sqlString,"return");
  147. }else{
  148. $sqlString ="insert into hz_deptinfo(hospitalId,deptId,deptName,parentId,visitAddress,info) VALUES('$hospitalId','$value->deptId','$value->deptName','$value->parentId','$value->visitAddress','$value->desc')";
  149. call_user_func(array($_ENV["dbDao"],"insert"),$sqlString,"return");
  150. }
  151. }
  152. }
  153. //医生信息查询接口
  154. public function getDoctorInfo($hospitalId,$hisUrl,$appKey){
  155. $postData="<?xml version=\"1.0\" encoding=\"UTF-8\"?><req><hospitalId>$hospitalId</hospitalId><deptId/><doctorId/></req>";
  156. $postUrl = $hisUrl."?c=NfyyApi&a=getDoctorInfo&appkey=".$appKey;
  157. $xmldata = call_user_func(array($_ENV["commonClass"],"sendDataByCurl"),$postUrl,$postData);
  158. foreach($xmldata as $key=>$value){
  159. $sqlString ="select id from hz_doctorinfo where hospitalId='$hospitalId' and deptId ='$value->deptId' and doctorId ='$value->doctorId'";
  160. $sqlData = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"entity");
  161. if ($sqlData) {
  162. $sqlString ="update hz_doctorinfo set deptId='$value->deptId',doctorId='$value->doctorId',doctorName='$value->doctorName',title='$value->Title',fee='$value->Fe',sex='".trim($value->Gender == "M" ? "男":"女")."',info='$value->desc' where id='".$sqlData['id']."'";
  163. call_user_func(array($_ENV["dbDao"],"update"),$sqlString,"return");
  164. }else{
  165. $sqlString ="insert into hz_doctorinfo(hospitalId,deptId,doctorId,doctorName,title,fee,sex,info) VALUES('$hospitalId','$value->deptId','$value->doctorId','$value->doctorName','$value->Title','$value->Fee','".trim($value->Gender == "M" ? "男":"女")."','$value->desc')";
  166. call_user_func(array($_ENV["dbDao"],"insert"),$sqlString,"return");
  167. }
  168. }
  169. }
  170. //医生号源信息查询接口
  171. public function getRegInfo($hospitalId,$hisUrl,$appKey,$maxRegDays){
  172. $sqlString ="select id,deptId from hz_deptinfo where hospitalId='$hospitalId' and parentId <>'-1'";
  173. $sqlDataList = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"list");
  174. foreach($sqlDataList as $key=>$deptInfo){
  175. $postData="<?xml version=\"1.0\" encoding=\"UTF-8\"?><req><hospitalId>$hospitalId</hospitalId><deptId>".$deptInfo['deptId']."</deptId><doctorId></doctorId><startDate>".date("Y-m-d",strtotime("+6 day"))."</startDate><endDate>".date("Y-m-d", strtotime("+".$maxRegDays." day"))."</endDate></req>";
  176. $postUrl = $hisUrl."?c=NfyyApi&a=getRegInfo&appkey=".$appKey;
  177. $xmldata = call_user_func(array($_ENV["commonClass"],"sendDataByCurl"),$postUrl,$postData);
  178. $xmldata = $xmldata->Schedules->Schedule;
  179. foreach($xmldata as $key=>$v){
  180. $sqlString ="select id from hz_reginfo where hospitalId='$hospitalId' and deptId='".$deptInfo['deptId']."' and doctorId='$v->DoctorCode' and regDate='$v->ServiceDate' and timeFlag ='$v->SessionCode'";
  181. $sqlData = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"entity");
  182. if ($sqlData) {
  183. //strval($v->TimeRangeFlag=="Y" ? "1": "0")
  184. $sqlString ="update hz_reginfo set deptId='".$deptInfo['deptId']."',doctorId='$v->DoctorCode',doctorName='$v->DoctorName',regDate='$v->ServiceDate',regWeekDay='$v->WeekDay',timeFlag='$v->SessionCode',regStatus='$v->ScheduleStatus',regTotalCount='$v->AvailableTotalNum',regLeaveCount='$v->AvailableLeftNum',regFee='(float)(strval($v->RegFee))*100',treatFee='(float)(strval($v->CheckupFee))*100',isTimeReg='$v->TimeRangeFlag' where id='".$sqlData['id']."'";
  185. call_user_func(array($_ENV["dbDao"],"update"),$sqlString,"return");
  186. }else{
  187. $sqlString ="insert into hz_reginfo(hospitalId,deptId,doctorId,doctorName,regDate,regWeekDay,timeFlag,regStatus,regTotalCount,regleaveCount,regFee,treatFee,isTimeReg) VALUES('$hospitalId','".$deptInfo['deptId']."','$v->DoctorCode','$v->DoctorName','$v->ServiceDate','$v->WeekDay','$v->SessionCode','$v->ScheduleStatus','$v->AvailableTotalNum','$v->AvailableLeftNum','$v->RegFee','$v->CheckupFee','$v->TimeRangeFlag')";
  188. call_user_func(array($_ENV["dbDao"],"insert"),$sqlString,"return");
  189. }
  190. }
  191. }
  192. }
  193. //生成药接口
  194. public function codeMedicine(){
  195. $sqlString ="SELECT * FROM hz_medicineitemschedulegroup g WHERE DATE_ADD(g.startDate, INTERVAL g.days-1 DAY)>= DATE('".date("Y-m-d", time())."')";
  196. $sqlData = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"list");
  197. foreach($sqlData as $key=>$misg){
  198. $sqlString ="SELECT * FROM hz_medicineschedule g WHERE medicineItemId='".$misg['medicineItemId']."' and scheduleGroupId='".$misg['id']."' and DATE(g.originalDateTime)= DATE('".date("Y-m-d", time())."');";
  199. $sqlData1 = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"entity");
  200. $sqlString ="SELECT * FROM hz_medicineitem g WHERE id='".$misg['medicineItemId']."'";
  201. $sqlData2 = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"entity");
  202. $sqlString ="SELECT * FROM hz_medicine g WHERE id='".$sqlData2['medicineId']."'";
  203. $sqlData3 = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"entity");
  204. if (!$sqlData1) {
  205. $sqlString ="UPDATE hz_medicineitemschedulegroup SET dayConsumption = dayConsumption+1,daysToTake = daysToTake+1 WHERE id ='".$misg['id']."'";
  206. $sqlDatau = call_user_func(array($_ENV["dbDao"],"update"),$sqlString,"return");
  207. $consumptionHoursString = explode(',', $misg['consumptionHoursString']);
  208. $quantityString = explode(',',$misg['quantityString']);
  209. $startTime = date("Y-m-d", time());
  210. $doseType = $misg['doseType'];
  211. $drugName = $sqlData2['drugName'];
  212. $customerUserId =$sqlData3['customerUserId'];
  213. $customerFamilyId =$sqlData3['customerFamilyId'];
  214. $data_values=null;
  215. $data_values1=null;
  216. for ($x=0; $x<=count($consumptionHoursString)-1; $x++) {
  217. $data_values .= "('".$misg['id']."','".$startTime." ".$consumptionHoursString[$x]."','".$startTime." ".$consumptionHoursString[$x]."','pending','".$misg['medicineItemId']."','".$consumptionHoursString[$x]."','".$quantityString[$x]."','".$doseType."'),";
  218. $data_values1 .="('".$misg['id']."','服用','".$drugName.$quantityString[$x].$doseType."','".$customerUserId."','".$customerFamilyId."','2','".$startTime." ".$consumptionHoursString[$x].":00','".date("Y-m-d H:i:s", time())."'),";
  219. }
  220. $data_values = substr($data_values,0,-1); //去掉最后一个逗号
  221. $sqlString= "INSERT INTO hz_medicineschedule (scheduleGroupId,actualDateTime,originalDateTime,status,medicineItemId,consumptionHours,quantity,doseType) VALUES". $data_values;
  222. call_user_func(array($_ENV["dbDao"],"insert"),$sqlString,"return");
  223. $data_values1 = substr($data_values1,0,-1); //去掉最后一个逗号
  224. $sqlString1= "INSERT INTO hz_pushtask (parameter,title,content,customerUserId,customerFamilyId,eventType,pushTime,createTime) VALUES" . $data_values1;
  225. call_user_func(array($_ENV["dbDao"],"insert"),$sqlString1,"return");
  226. }
  227. }
  228. }
  229. //医生号源信息查询接口 5分钟活跃同步
  230. public function getSynRegInfo($hospitalId,$hisUrl,$appKey){
  231. $sqlString ="SELECT deptId,doctorId,regDate FROM hz_appointsorder t WHERE hospitalId='$hospitalId' and resultCode=1 resultCode=1 AND orderTime>=DATE_SUB(SYSDATE(),INTERVAL 5 MINUTE) AND orderTime<=DATE_ADD(SYSDATE(),INTERVAL 0 MINUTE) GROUP BY deptId,doctorId,regDate ";
  232. $sqlDataList = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"list");
  233. foreach($sqlDataList as $key=>$deptInfo){
  234. $postData="<?xml version=\"1.0\" encoding=\"UTF-8\"?><req><hospitalId>$hospitalId</hospitalId><deptId>".$deptInfo['deptId']."</deptId><doctorId>".$deptInfo['doctorId']."</doctorId><startDate>".$deptInfo['regDate']."</startDate><endDate>".$deptInfo['regDate']."</endDate></req>";
  235. $postUrl = $hisUrl."doReqToHis.aspx?service=getRegInfo&appkey=".$appKey;
  236. $xmldata = call_user_func(array($_ENV["commonClass"],"sendDataByCurl"),$postUrl,$postData);
  237. foreach($xmldata as $key=>$ri){
  238. $TimeRegInfoList = $ri->TimeRegInfoList;
  239. foreach($TimeRegInfoList as $key=>$tril){
  240. $timeRegInfo = $tril->timeRegInfo;
  241. foreach($timeRegInfo as $key=>$tri){
  242. $sqlString ="select id from hz_reginfo where hospitalId='$hospitalId' and deptId='".$deptInfo['deptId']."' and doctorId='$ri->doctorId' and regDate='$tril->regDate' and timeFlag ='$tri->timeFlag'";
  243. $sqlData = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"entity");
  244. if ($sqlData) {
  245. $sqlString ="update hz_reginfo set deptId='".$deptInfo['deptId']."',doctorId='$ri->doctorId',doctorName='$ri->doctorName',regDate='$tril->regDate',regWeekDay='$tril->regWeekDay',timeFlag='$tri->timeFlag',regStatus='$tri->regStatus',regTotalCount='$tri->regTotalCount',regLeaveCount='$tri->regleaveCount',regFee='$tri->regFee',treatFee='$tri->treatFee',isTimeReg='$tri->isTimeReg' where id='".$sqlData['id']."'";
  246. call_user_func(array($_ENV["dbDao"],"update"),$sqlString,"return");
  247. }else{
  248. $sqlString ="insert into hz_reginfo(hospitalId,deptId,doctorId,doctorName,regDate,regWeekDay,timeFlag,regStatus,regTotalCount,regleaveCount,regFee,treatFee,isTimeReg) VALUES('$hospitalId','".$deptInfo['deptId']."','$ri->doctorId','$ri->doctorName','$tril->regDate','$tril->regWeekDay','$tri->timeFlag','$tri->regStatus','$tri->regTotalCount','$tri->regleaveCount','$tri->regFee','$tri->treatFee','$tri->isTimeReg')";
  249. call_user_func(array($_ENV["dbDao"],"insert"),$sqlString,"return");
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. //医生号源信息查询接口 60分钟活跃同步
  257. public function getFavoriteNum($hospitalId,$hisUrl,$appKey){
  258. $sqlString ="SELECT COUNT(1) as rows,hospitalId,deptId,doctorId FROM hz_favoritedoctor WHERE STATUS=1 GROUP BY hospitalId,deptId,doctorId ";
  259. $sqlDataList = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"list");
  260. foreach($sqlDataList as $key=>$info){
  261. $sqlString ="update hz_doctorinfo set favoriteNum='".$info['rows']."' where hospitalId='".$info['hospitalId']."' and deptId='".$info['deptId']."' and doctorId='".$info['doctorId']."'";
  262. $sqlData = call_user_func(array($_ENV["dbDao"],"update"),$sqlString,"entity");
  263. }
  264. $sqlString ="SELECT COUNT(1) as rows,hospitalId FROM hz_favoritedoctor WHERE STATUS=1 GROUP BY hospitalId ";
  265. $sqlDataList = call_user_func(array($_ENV["dbDao"],"select"),$sqlString,"list");
  266. foreach($sqlDataList as $key=>$info){
  267. $sqlString ="update hz_hospitalinfo set favoriteNum='".$info['rows']."' where hospitalId='".$info['hospitalId']."'";
  268. $sqlData = call_user_func(array($_ENV["dbDao"],"update"),$sqlString,"entity");
  269. }
  270. }
  271. }