create or replace view `自理能力评估视图`
as
SELECT
`ehr_zlnlpg`.`ID` AS `ID`,
`ehr_zlnlpg`.`GRID` AS `GRID`,
`ehr_zlnlpg`.`TJID` AS `TJID`,
`ehr_grjbxx`.`Name` AS `姓名`,
`ehr_grjbxx`.`Sex` AS `性别`,
`ehr_grjbxx`.`Cardnum` AS `身份证号`,
`ehr_zlnlpg`.`SCORESUM` AS `总分`,
`ehr_zlnlpg`.`ZrysZL` AS `责任医生`,
`ehr_zlnlpg`.`ZrysZLID` AS `责任医生ID`,
-- CASE WHEN `a`.`upstate` = 0 THEN '失败' WHEN `a`.`upstate` = -1 THEN '未上传' WHEN `a`.`upstate` = 1 OR `a`.`upstate` > 1 THEN '已上传' ELSE '未知状态' END AS `状态`,
COALESCE(`a`.`upstate`, -1) AS `状态`,
`ehr_zlnlpg`.`TijianDate` AS `日期`
FROM
((
`ehr_zlnlpg`
JOIN `ehr_grjbxx` ON ( `ehr_zlnlpg`.`GRID` = `ehr_grjbxx`.`ID` ))
LEFT JOIN (
SELECT
*
FROM
`ehr_ybs_log`
WHERE
`ehr_ybs_log`.`uptype` = 2
) `a` ON ( `a`.`jktjId` = `ehr_zlnlpg`.`TJID` ))