insert coc_zy_gzl_ryjl_jzs
(

yljgdm, hzbh, jzlsh, jlsj, jzs_ywjzycbs, jzs_jzycbs, jzs_ywjzzlbs, jzs_jzzlbs

)
select 
'42502658000' yljgdm
,SFZH hzbh
,IPBLH jzlsh
,XGRQ jlsj, 
-- 骨肿瘤_家族史
max( 
CASE     WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '家族遗传病史-有无'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '家族遗传病史-有无'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jzs_ywjzycbs-- 有无家族遗传病史
,'否认家族遗传病史' jzs_jzycbs
,max( 
CASE     WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '家族肿瘤病史-有无'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '家族肿瘤病史-有无'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jzs_ywjzzlbs-- 有无家族肿瘤病史
,'否认家族肿瘤病史' jzs_jzzlbs
    from coc_db.patient_jgbl_info
where DocumentName like '%骨肿瘤%入院%'
    group by 
	id,
	ipblh,
	sfzh,
	PatientName
,XGRQ;


-- 骨肿瘤_入院记录
INSERT INTO coc_db.coc_zy_gzl_ryjl
(yljgdm, hzbh, jzlsh, jlsj, zyh, kh, klx, yjlxh, xgbz, hzxm, hzxb, hznl, hzks, hzch, hzbq, hzzy, hzcsd, hzhf,hzjg, hzmz, ryrq, cjrq, jlrq, bscsz, zs, fzjc, cbzd)
select
'42502658000' yljgdm
,SFZH hzbh
,IPBLH jzlsh
,XGRQ jlsj
,IPBLH zyh
,KH kh
,KLX klx
,YJLXH yjlxh
,1 xgbz, 
max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '病人姓名'    THEN DisplayString ELSE null END ) hzxm,-- 患者姓名
max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '性别'    THEN DisplayString ELSE null END ) hzxb,-- 性别
max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '年龄'    THEN DisplayString ELSE null END ) hznl,-- 年龄
    '-' hzks
    ,'-' hzch
    ,'-'  hzbq
,max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '职业'    THEN DisplayString ELSE null END ) hzzy,-- 职业
max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '出生地'    THEN DisplayString ELSE null END ) hzcsd,-- 出生地
max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '婚姻情况'    THEN DisplayString ELSE null END ) hzhf,-- 婚否
    max(JG) hzjg
,max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '民族'    THEN DisplayString ELSE null END ) hzmz,-- 民族
max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '入院日期'    THEN DisplayString ELSE null END ) ryrq,-- 入院日期
max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '入院日期'    THEN DisplayString ELSE null END ) cjrq,-- 采集日期
max( 
    CASE WHEN ParagraphName = '患者基本信息'      AND ValueItemName = '入院日期'    THEN DisplayString ELSE null END ) jlrq,-- 记录日期
    '本人' bscsz
,max( 
    CASE WHEN ParagraphName = '主诉'      AND ValueItemName = '主诉'    THEN DisplayString ELSE null END ) zs,-- 主诉
max( 
    CASE WHEN ValueItemName = '辅助检查'    THEN DisplayString ELSE null END ) fzjc,-- 辅助检查
max( 
    CASE WHEN  ValueItemName = '初步诊断'    THEN DisplayString ELSE null END ) cbzd-- 初步诊断
    from coc_db.patient_jgbl_info
where DocumentName like '%骨肿瘤%入院%'
    group by 
	id,
	ipblh,
	sfzh,
	PatientName
,XGRQ
,YJLXH
,KH
,KLX
;


-- 骨肿瘤_体格检查
INSERT INTO coc_db.coc_zy_gzl_ryjl_tgjc
(yljgdm, hzbh, jzlsh, jlsj, tgjc_t, tgjc_p, tgjc_r, tgjc_bp, tgjc_sg, tgjc_tz, tgjc_bmi, tgjc_sz, tgjc_fy
, tgjc_yy, tgjc_hd, tgjc_tw, tgjc_ct, tgjc_rbffs, tgjc_qspfzmyc, tgjc_gz, tgjc_qsqblbjzd, tgjc_pxcxd, tgjc_pz
, tgjc_tljx, tgjc_yj, tgjc_ljmyc, tgjc_gmhr, tgjc_sctk, tgjc_dgfs, tgjc_ekjx, tgjc_wedycfmw, tgjc_rtyt, tgjc_wbjx
, tgjc_btq, tgjc_bzgpq, tgjc_bysd, tgjc_lcfbdqyt, tgjc_kczg, tgjc_ssxqzd, tgjc_j, tgjc_dk, tgjc_jjmnz, tgjc_qg, tgjc_jzxzd
, tgjc_xkdcjx, tgjc_xgyt, tgjc_sfhxy, tgjc_gsxly, tgjc_xl, tgjc_l, tgjc_f, tgjc_fb, tgjc_qfyt, tgjc_jjzjftt, tgjc_gplx
, tgjc_gszjt, tgjc_cmy, tgjc_gmjwszqyc, tgjc_jzjx, tgjc_szjx, tgjc_gjhz, tgjc_czz, tgjc_sxzsz, tgjc_jl, tgjc_jzl, tgjc_slfs, tgjc_blfs)

select 
'42502658000' yljgdm
,SFZH hzbh
,IPBLH jzlsh
,XGRQ jlsj, 
max( 
    CASE WHEN ParagraphName = '体格检查'      AND ValueItemName = 'T'    THEN DisplayString ELSE null END ) tgjc_t,-- 体格检查-T
max( 
    CASE WHEN ParagraphName = '体格检查'      AND ValueItemName = 'P'    THEN DisplayString ELSE null END ) tgjc_p,-- 体格检查-P
max( 
    CASE WHEN ParagraphName = '体格检查'      AND ValueItemName = 'R：'    THEN DisplayString ELSE null END ) tgjc_r,-- 体格检查-R
max( concat(
    CASE WHEN ParagraphName = '体格检查'      AND ValueItemName = '收缩压'    THEN DisplayString ELSE null END 
    ,'/'
    , CASE WHEN ParagraphName = '体格检查'      AND ValueItemName = '舒张压'    THEN DisplayString ELSE null END 
    )
    ) tgjc_bp,-- 体格检查-BP
max( 
    CASE WHEN ParagraphName = '体格检查'    AND StatementName = '骨肿瘤-入院体格检查'    AND ValueItemName in( '体格检查-身高','' )   THEN DisplayString ELSE null END ) tgjc_sg,-- 体格检查-身高
max( 
    CASE WHEN ParagraphName = '体格检查'    AND StatementName = '骨肿瘤-入院体格检查'    AND ValueItemName = '体格检查-体重'    THEN DisplayString ELSE null END ) tgjc_tz,-- 体格检查-体重
max( 
    CASE WHEN ParagraphName = '体格检查'      AND ValueItemName = 'BMI'    THEN DisplayString ELSE null END ) tgjc_bmi,-- 体格检查-BMI
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '神志'    AND DisplayString LIKE '%清楚%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '神志'    AND DisplayString LIKE '%嗜睡%'    THEN  '2' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '神志'    AND DisplayString LIKE '%昏迷%'    THEN  '3' 
ELSE '1' END ) tgjc_sz,-- 体格检查-神志
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '发育'    AND DisplayString LIKE '%正常%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '发育'    AND DisplayString LIKE '%不良%'    THEN  '0' 
ELSE '1' END ) tgjc_fy,-- 体格检查-发育
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '营养'    AND DisplayString LIKE '%好%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '营养'    AND DisplayString LIKE '%差%'    THEN  '0' 
ELSE '1' END ) tgjc_yy,-- 体格检查-营养
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '回答'    AND DisplayString LIKE '%切题%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '回答'    AND DisplayString LIKE '%不切题%'    THEN  '2' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '回答'    AND DisplayString LIKE '%无应答%'    THEN  '3' 
ELSE '1' END ) tgjc_hd,-- 体格检查-回答
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '体位'    AND DisplayString LIKE '%自动%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '体位'    AND DisplayString LIKE '%被动%'    THEN  '2' 
ELSE '1' END ) tgjc_tw,-- 体格检查-体位
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '查体'    AND DisplayString LIKE '%合作%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '查体'    AND DisplayString LIKE '%不合作%'    THEN  '0' 
ELSE '1' END ) tgjc_ct,-- 体格检查-查体
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '步入/推入病房'    AND DisplayString LIKE '%步入%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '步入/推入病房'    AND DisplayString LIKE '%推入%'    THEN  '2' 
ELSE '1' END ) tgjc_rbffs,-- 体格检查-入病房方式
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '全身皮肤黏膜见/未见异常'    AND DisplayString LIKE '%见%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '全身皮肤黏膜见/未见异常'    AND DisplayString LIKE '%未见%'    THEN  '0' 
ELSE '1' END ) tgjc_qspfzmyc,-- 体格检查-全身皮肤粘 膜异常
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无肝掌'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无肝掌'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_gz,-- 体格检查-肝掌
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '全身浅表淋巴结有/无肿大'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '全身浅表淋巴结有/无肿大'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_qsqblbjzd,-- 体格检查-全身浅表淋 巴结肿大
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '见/未见皮下出血点'    AND DisplayString LIKE '%见%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '见/未见皮下出血点'    AND DisplayString LIKE '%未见%'    THEN  '0' 
ELSE '0' END ) tgjc_pxcxd,-- 体格检查-皮下出血点
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '见/未见皮疹'    AND DisplayString LIKE '%见%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '见/未见皮疹'    AND DisplayString LIKE '%未见%'    THEN  '0' 
ELSE '0' END ) tgjc_pz,-- 体格检查-皮疹
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无头颅畸形'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无头颅畸形'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_tljx,-- 体格检查-头颅畸形
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '眼睑正常/异常'    AND DisplayString LIKE '%正常%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '眼睑正常/异常'    AND DisplayString LIKE '%异常%'    THEN  '0' 
ELSE '1' END ) tgjc_yj,-- 体格检查-眼睑
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '眼结膜见/未见异常'    AND DisplayString LIKE '%见%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '眼结膜见/未见异常'    AND DisplayString LIKE '%未见%'    THEN  '0' 
ELSE '0' END ) tgjc_ljmyc,-- 体格检查-睑结膜异常
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '巩膜有无黄染'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '巩膜有无黄染'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_gmhr,-- 体格检查-巩膜黄染
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '双侧瞳孔等大等圆/不对称'    AND DisplayString LIKE '%等大等圆%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '双侧瞳孔等大等圆/不对称'    AND DisplayString LIKE '%不对称%'    THEN  '2' 
ELSE '1' END ) tgjc_sctk,-- 体格检查-双侧瞳孔
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '对光反射灵敏/不灵敏'    AND DisplayString LIKE '%灵敏%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '对光反射灵敏/不灵敏'    AND DisplayString LIKE '%不灵敏%'    THEN  '0' 
ELSE '1' END ) tgjc_dgfs,-- 体格检查-对光反射
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '耳廓有无畸形'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '耳廓有无畸形'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_ekjx,-- 体格检查-耳廓畸形
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '外耳道有无异常分泌物'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '外耳道有无异常分泌物'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_wedycfmw,-- 体格检查-外耳道异常 分泌物
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无乳突压痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无乳突压痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_rtyt,-- 体格检查-乳突压痛
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '外鼻有无畸形'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '外鼻有无畸形'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_wbjx,-- 体格检查-外鼻畸形
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '鼻通气良好/差'    AND DisplayString LIKE '%良好%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '鼻通气良好/差'    AND DisplayString LIKE '%差%'    THEN  '0' 
ELSE '1' END ) tgjc_btq,-- 体格检查-鼻通气
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '鼻中隔有无偏曲'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '鼻中隔有无偏曲'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_bzgpq,-- 体格检查-鼻中隔偏曲
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '鼻翼有无扇动'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '鼻翼有无扇动'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_bysd,-- 体格检查-鼻翼煽动
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '两侧副鼻窦区有无压痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '两侧副鼻窦区有无压痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_lcfbdqyt,-- 体格检查-两侧副鼻窦 区压痛
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '口唇有无紫绀'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '口唇有无紫绀'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_kczg,-- 体格检查-口唇紫绀
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '双腮腺区有无肿大'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '双腮腺区有无肿大'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_ssxqzd,-- 体格检查-双腮腺区肿 大
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '颈软硬'    AND DisplayString LIKE '%硬%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '颈软硬'    AND DisplayString LIKE '%软%'    THEN  '2' 
ELSE '2' END ) tgjc_j,-- 体格检查-颈
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无抵抗'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无抵抗'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_dk,-- 体格检查-抵抗
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '颈静脉有无怒张'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '颈静脉有无怒张'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_jjmnz,-- 体格检查-颈静脉怒张
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '气管居中/偏向左侧/偏向右侧'    AND DisplayString LIKE '%居中%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '气管居中/偏向左侧/偏向右侧'    AND DisplayString LIKE '%偏向左侧%'    THEN  '2' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '气管居中/偏向左侧/偏向右侧'    AND DisplayString LIKE '%偏向右侧%'    THEN  '3' 
ELSE '1' END ) tgjc_qg,-- 体格检查-气管
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '甲状腺有无肿大'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '甲状腺有无肿大'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_jzxzd,-- 体格检查-甲状腺肿大
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '胸廓对称有无畸形'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '胸廓对称有无畸形'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_xkdcjx,-- 体格检查-胸廓对称畸 形
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '胸骨有无压痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '胸骨有无压痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_xgyt,-- 体格检查-胸骨压痛
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '双肺呼吸音清晰/粗糙'    AND DisplayString LIKE '%清晰%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '双肺呼吸音清晰/粗糙'    AND DisplayString LIKE '%粗糙%'    THEN  '2' 
ELSE '1' END ) tgjc_sfhxy,-- 体格检查-双肺呼吸音
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '未闻及/闻及干、湿性啰音'    AND DisplayString LIKE '%未闻及%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '未闻及/闻及干、湿性啰音'    AND DisplayString LIKE '%闻及%'    THEN  '1' 
ELSE '0' END ) tgjc_gsxly,-- 体格检查-干湿性罗音
max( 
    CASE WHEN ParagraphName = '体格检查'      AND ValueItemName = '心率'    THEN DisplayString ELSE null END ) tgjc_xl,-- 体格检查-心率
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '律齐/不齐'    AND DisplayString LIKE '%齐%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '律齐/不齐'    AND DisplayString LIKE '%不齐%'    THEN  '0' 
ELSE '1' END ) tgjc_l,-- 体格检查-律
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '腹平坦/膨隆/凹陷'    AND DisplayString LIKE '%平坦%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '腹平坦/膨隆/凹陷'    AND DisplayString LIKE '%膨隆%'    THEN  '2' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '腹平坦/膨隆/凹陷'    AND DisplayString LIKE '%凹陷%'    THEN  '3' 
ELSE '1' END ) tgjc_f,-- 体格检查-腹
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '腹壁软硬'    AND DisplayString LIKE '%硬%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '腹壁软硬'    AND DisplayString LIKE '%软%'    THEN  '2' 
ELSE '2' END ) tgjc_fb,-- 体格检查-腹壁
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '全腹有无压痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '全腹有无压痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_qfyt,-- 体格检查-全腹压痛
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无肌紧张及反跳痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '有无肌紧张及反跳痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_jjzjftt,-- 体格检查-肌紧张及反 跳痛
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '肝脾肋下未触及'    AND DisplayString LIKE '%触及%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '肝脾肋下未触及'    AND DisplayString LIKE '%未触及%'    THEN  '0' 
ELSE '0' END ) tgjc_gplx,-- 体格检查-肝脾肋下
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '肝肾脏有无叩击痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '肝肾脏有无叩击痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_gszjt,-- 体格检查-肝肾脏击痛
max( 
    CASE WHEN ParagraphName = '体格检查'      AND ValueItemName = '肠鸣音'    THEN DisplayString ELSE null END ) tgjc_cmy,-- 体格检查-肠鸣音
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '肛门及外生殖器见/未见异常'    AND DisplayString LIKE '%见%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '肛门及外生殖器见/未见异常'    AND DisplayString LIKE '%未见%'    THEN  '0' 
ELSE '0' END ) tgjc_gmjwszqyc,-- 体格检查-肛门及外生 殖器异常
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '脊柱、四肢有无畸形'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '脊柱、四肢有无畸形'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_jzjx,-- 体格检查-脊柱畸形
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '脊柱、四肢有无畸形'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '脊柱、四肢有无畸形'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_szjx,-- 体格检查-四肢畸形
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '关节有无红肿'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '关节有无红肿'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_gjhz,-- 体格检查-关节红肿
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '体格检查-杵状指(趾)'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '体格检查-杵状指(趾)'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_czz,-- 体格检查-杵状指(趾)
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '双下肢有无水肿'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '双下肢有无水肿'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) tgjc_sxzsz,-- 体格检查-双下肢水肿
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '肌力正常/异常'    AND DisplayString LIKE '%正常%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '肌力正常/异常'    AND DisplayString LIKE '%异常%'    THEN  '0' 
ELSE '1' END ) tgjc_jl,-- 体格检查-肌力
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '肌张力正常/异常'    AND DisplayString LIKE '%正常%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '肌张力正常/异常'    AND DisplayString LIKE '%异常%'    THEN  '0' 
ELSE '1' END ) tgjc_jzl,-- 体格检查-肌张力
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '生理反射正常/异常'    AND DisplayString LIKE '%正常%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '生理反射正常/异常'    AND DisplayString LIKE '%异常%'    THEN  '0' 
ELSE '1' END ) tgjc_slfs,-- 体格检查-生理反射
max( 
CASE     WHEN ParagraphName = '体格检查'      AND ValueItemName = '病理反射引出/未引出'    AND DisplayString LIKE '%引出%'    THEN  '1' 
    WHEN ParagraphName = '体格检查'      AND ValueItemName = '病理反射引出/未引出'    AND DisplayString LIKE '%未引出%'    THEN  '0' 
ELSE '0' END ) tgjc_blfs-- 体格检查-病理反射
##select * 
from coc_db.patient_jgbl_info
where DocumentName like '%骨肿瘤%入院%'
    group by 
	id,
	ipblh,
	sfzh,
	PatientName
,XGRQ
,YJLXH
,KH
,KLX
;

-- 骨肿瘤_本科检查
INSERT INTO coc_db.coc_zy_gzl_ryjl_bkjc
(yljgdm, hzbh, jzlsh, jlsj, bkjc_sz_bw, bkjc_sz_bt, bkjc_sz_zz, bkjc_sz_pfjmnz, bkjc_sz_ztws, bkjc_sz_gjqqjx, bkjc_sz_skhdd, bkjc_sz_sknxfmw, bkjc_cz_bw, bkjc_cz_jbpwsg, bkjc_cz_yt, bkjc_cz_ttjb, bkjc_cz_ychdjgcg, bkjc_cz_jbwdsg, bkjc_cz_zkhd, bkjc_cz_bdg, bkjc_kz_bw, bkjc_kz_kjtt, bkjc_kz_zxkjtt, bkjc_dz_bw, bkjc_dz_bwfx, bkjc_dz_jl, bkjc_dz_zdhd, bkjc_dz_hdfw, bkjc_dz_gjqz, bkjc_dz_jgjhd, bkjc_lz_sxz, bkjc_lz_zyc, bkjc_lz_cd, bkjc_lz_zkzj, bkjc_lz_gjhdd)
select
'42502658000' yljgdm
,SFZH hzbh
,IPBLH jzlsh
,XGRQ jlsj, 
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%髋关节%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%膝关节%'    THEN  '2' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%踝关节%'    THEN  '3' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%肩关节%'    THEN  '4' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%肘关节%'    THEN  '5' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%腕关节%'    THEN  '6' 
ELSE '9' END ) bkjc_sz_bw,-- 本科检查-视诊-部位
max( 
    CASE WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    THEN DisplayString ELSE null END ) bkjc_sz_bt,-- 本科检查-视诊-步态
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无肿胀'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无肿胀'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_sz_zz,-- 本科检查-视诊-肿胀
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊可未皮肤静脉怒张'    AND DisplayString LIKE '%可%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊可未皮肤静脉怒张'    AND DisplayString LIKE '%未%'    THEN  '0' 
ELSE '0' END ) bkjc_sz_pfjmnz,-- 本科检查-视诊-皮肤静 脉怒张
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_sz_ztws,-- 本科检查-视诊-肢体萎 缩
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_sz_gjqqjx,-- 本科检查-视诊-关节屈 曲畸形
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无伤口或窦道'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无伤口或窦道'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_sz_skhdd,-- 本科检查-视诊-伤口或 窦道
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无伤口脓性分泌物'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-视诊有无伤口脓性分泌物'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_sz_sknxfmw,-- 本科检查-视诊-伤口脓 性分泌物
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%髋关节%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%膝关节%'    THEN  '2' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%踝关节%'    THEN  '3' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%肩关节%'    THEN  '4' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%肘关节%'    THEN  '5' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%腕关节%'    THEN  '6' 
ELSE '0' END ) bkjc_cz_bw,-- 本科检查-触诊-部位
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊有无局部皮温升高'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊有无局部皮温升高'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_cz_jbpwsg,-- 本科检查-触诊-局部皮 温升高
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊有无压痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊有无压痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_cz_yt,-- 本科检查-触诊-压痛
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊轻度/中度/剧烈'    AND DisplayString LIKE '%轻度%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊轻度/中度/剧烈'    AND DisplayString LIKE '%中度%'    THEN  '2' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊轻度/中度/剧烈'    AND DisplayString LIKE '%剧烈%'    THEN  '3' 
ELSE '1' END ) bkjc_cz_ttjb,-- 本科检查-触诊-疼痛级 别
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '有无异常活动及骨擦感'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '有无异常活动及骨擦感'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_cz_ychdjgcg,-- 本科检查-触诊-异常活 动及骨擦感
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊有无局部温度升高'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊有无局部温度升高'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_cz_jbwdsg,-- 本科检查-触诊-局部温 度升高
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊是否活动'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊是否活动'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) bkjc_cz_zkhd,-- 本科检查-触诊-肿块活 动
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊有无'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊有无'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_cz_bdg,-- 本科检查-触诊-波动感
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%髋关节%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%膝关节%'    THEN  '2' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%踝关节%'    THEN  '3' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%肩关节%'    THEN  '4' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%肘关节%'    THEN  '5' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    AND DisplayString LIKE '%腕关节%'    THEN  '6' 
ELSE '9' END ) bkjc_kz_bw,-- 本科检查-叩诊-部位
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-叩诊有无叩击疼痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-叩诊有无叩击疼痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_kz_kjtt,-- 本科检查-叩诊-叩击疼 痛
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-叩诊有无轴向叩击疼痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-叩诊有无轴向叩击疼痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_kz_zxkjtt,-- 本科检查-叩诊-轴向叩 击疼痛
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊左侧/右侧'    AND DisplayString LIKE '%髋关节%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊左侧/右侧'    AND DisplayString LIKE '%膝关节%'    THEN  '2' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊左侧/右侧'    AND DisplayString LIKE '%踝关节%'    THEN  '3' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊左侧/右侧'    AND DisplayString LIKE '%肩关节%'    THEN  '4' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊左侧/右侧'    AND DisplayString LIKE '%肘关节%'    THEN  '5' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊左侧/右侧'    AND DisplayString LIKE '%腕关节%'    THEN  '6' 
ELSE '9' END ) bkjc_dz_bw,-- 本科检查-动诊-部位
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊级别'    AND DisplayString LIKE '%左侧%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-触诊级别'    AND DisplayString LIKE '%右侧%'    THEN  '2' 
ELSE '9' END ) bkjc_dz_bwfx,-- 本科检查-动诊-部位方 向
max( 
    CASE WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-步态'    THEN DisplayString ELSE null END ) bkjc_dz_jl,-- 本科检查-动诊-肌力
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊受限/尚可'    AND DisplayString LIKE '%受限%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊受限/尚可'    AND DisplayString LIKE '%尚可%'    THEN  '2' 
ELSE '2' END ) bkjc_dz_zdhd,-- 本科检查-动诊-主动活 动
max( 
    CASE WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊活动度'    THEN DisplayString ELSE null END ) bkjc_dz_hdfw,-- 本科检查-动诊-活动范 围
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊有无关节强直'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊有无关节强直'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_dz_gjqz,-- 本科检查-动诊-关节强 直
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-假关节活动'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-假关节活动'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) bkjc_dz_jgjhd,-- 本科检查-动诊-假关节 活动
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-量诊上肢/下肢'    AND DisplayString LIKE '%上肢%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-量诊上肢/下肢'    AND DisplayString LIKE '%下肢%'    THEN  '2' 
ELSE '1' END ) bkjc_lz_sxz,-- 本科检查-量诊-上下肢
max( 
CASE     WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊左侧/右侧'    AND DisplayString LIKE '%左侧%'    THEN  '1' 
    WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-动诊左侧/右侧'    AND DisplayString LIKE '%右侧%'    THEN  '2' 
ELSE '9' END ) bkjc_lz_zyc,-- 本科检查-量诊-左右侧
max( 
    CASE WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-量诊长度（厘米）'    THEN DisplayString ELSE 0 END ) bkjc_lz_cd,-- 本科检查-量诊-长度
max( 
    CASE WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-关节活动度'    THEN DisplayString ELSE 0 END ) bkjc_lz_zkzj,-- 本科检查-量诊-肿块周 径
max( 
    CASE WHEN ParagraphName = '本科检查'      AND ValueItemName = '骨肿瘤-量诊长度（厘米）'    THEN DisplayString ELSE 0 END ) bkjc_lz_gjhdd-- 本科检查-量诊-关节活 动度
##select * 
from coc_db.patient_jgbl_info
where DocumentName like '%骨肿瘤%入院%' 
##and ipblh='0001615341'
    group by 
	id,
	ipblh,
	sfzh,
	PatientName
,XGRQ
,YJLXH
,KH
,KLX
;
    
    
-- 骨肿瘤_既往史
INSERT INTO coc_db.coc_zy_gzl_ryjl_jws
(
yljgdm, hzbh, jzlsh, jlsj, jws_ywgxy, jws_ywtnb, jws_ywgxb, jws_ywxjgss, jws_ywnzz, jws_ywjwxgzls, jws_ywjwfzljbs, jws_jwfxgzlfxsj
, jws_yfxzlcszdrq, jws_ywyfffzy, jws_yfffqk, jws_crbs_ywbdxgy, jws_crbs_ywjh, jws_crbs_ywqt, jws_sss_ywsss, jws_sss_ywzlsss
, jws_sss_zlssqk, jws_wss_ywwss, jws_sxs_ywsxs, jws_gms_ywywswgms, jws_gms_ywswgmsqk, jws_yfjzs_ymjz
)
select
'42502658000' yljgdm
,SFZH hzbh
,IPBLH jzlsh
,XGRQ jlsj
,max( 
CASE     WHEN ParagraphName = '既往史'      AND ValueItemName = '有无高血压史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '既往史'      AND ValueItemName = '有无高血压史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_ywgxy,-- 既往史-有无高血压
max( 
CASE     WHEN ParagraphName = '既往史'      AND ValueItemName = '无/有糖尿病病史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '既往史'      AND ValueItemName = '无/有糖尿病病史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_ywtnb,-- 既往史-有无糖尿病
max( 
CASE     WHEN ParagraphName = '既往史'      AND ValueItemName = '有无冠心病病史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '既往史'      AND ValueItemName = '有无冠心病病史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_ywgxb,-- 既往史-有无冠心病
max( 
CASE     WHEN ParagraphName = '既往史'      AND ValueItemName = '有无心肌梗塞'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '既往史'      AND ValueItemName = '有无心肌梗塞'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_ywxjgss,-- 既往史-有无心肌梗塞 史
max( 
CASE     WHEN ParagraphName = '既往史'      AND ValueItemName = '有无脑卒中史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '既往史'      AND ValueItemName = '有无脑卒中史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_ywnzz,-- 既往史-有无脑卒中
max( 
CASE     WHEN ParagraphName = '既往史'      AND ValueItemName = '骨肿瘤-既往相关肿瘤史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '既往史'      AND ValueItemName = '骨肿瘤-既往相关肿瘤史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_ywjwxgzls,-- 有无既往相关肿瘤史
max( 
CASE     WHEN ParagraphName = '既往史'      AND ValueItemName = '骨肿瘤-有无既往非肿瘤疾病史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '既往史'      AND ValueItemName = '骨肿瘤-有无既往非肿瘤疾病史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_ywjwfzljbs,-- 有无既往非肿瘤疾病史
max( 
    CASE WHEN ParagraphName = '既往相关肿瘤史'      AND ValueItemName = '骨肿瘤-既往相关肿瘤史'    THEN substring(DisplayString,locate('√ ',DisplayString)+1,1) ELSE '无' END ) jws_jwfxgzlfxsj,-- 既往非相关肿瘤发现时 间
max( 
    CASE WHEN ParagraphName = '既往非肿瘤疾病史'      AND ValueItemName = '骨肿瘤-有无既往非肿瘤疾病史'    THEN substring(DisplayString,locate('√ ',DisplayString)+1,1) ELSE '无' END ) jws_yfxzlcszdrq,-- 原发性肿瘤初始诊断日 期
    0 jws_ywyfffzy,'无' jws_yfffqk,
max( 
CASE     WHEN ParagraphName = '既往相关肿瘤史'      AND ValueItemName = '骨肿瘤-病毒性肝炎'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '既往相关肿瘤史'      AND ValueItemName = '骨肿瘤-病毒性肝炎'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_crbs_ywbdxgy,-- 传染病史-有无病毒性 肝炎
max( 
CASE     WHEN ParagraphName = '骨肿瘤-入院既往史'      AND ValueItemName = '骨肿瘤-结核'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '骨肿瘤-入院既往史'      AND ValueItemName = '骨肿瘤-结核'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_crbs_ywjh,-- 传染病史-有无结核
max( 
CASE     WHEN ParagraphName = '骨肿瘤-入院既往史'      AND ValueItemName = '骨肿瘤-有无其他'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '骨肿瘤-入院既往史'      AND ValueItemName = '骨肿瘤-有无其他'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_crbs_ywqt,-- 传染病史-有无其他
max( 
CASE     WHEN ParagraphName = '骨肿瘤-手术史'      AND ValueItemName = '手术史-有无复选-ppa'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '骨肿瘤-手术史'      AND ValueItemName = '手术史-有无复选-ppa'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_sss_ywsss,-- 手术史-有无手术史
max( 
CASE     WHEN ParagraphName = '骨肿瘤-手术史'      AND ValueItemName = '肿瘤手术史-有无复选-ppa'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '骨肿瘤-手术史'      AND ValueItemName = '肿瘤手术史-有无复选-ppa'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_sss_ywzlsss,-- 手术史-有无肿瘤手术 史
'否认肿瘤手术史' jws_sss_zlssqk,
max( 
CASE     WHEN ParagraphName = '骨肿瘤-外伤史'      AND ValueItemName = '有/无外伤史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '骨肿瘤-外伤史'      AND ValueItemName = '有/无外伤史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_wss_ywwss,-- 外伤史-有无外伤史
max( 
CASE     WHEN ParagraphName = '骨肿瘤-输血史'      AND ValueItemName = '有无输血史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '骨肿瘤-输血史'      AND ValueItemName = '有无输血史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_sxs_ywsxs,-- 输血史-有无输血史
max( 
CASE     WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '有无药物食物过敏史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '有无药物食物过敏史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) jws_gms_ywywswgms,-- 过敏史-有无药物食物 过敏史
'否认药物食物过敏史' jws_gms_ywswgmsqk
,
max( 
CASE     WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '疫苗接种规范/不规范'    AND DisplayString LIKE '%不规范%'    THEN  '0' 
    WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '疫苗接种规范/不规范'    AND DisplayString LIKE '%规范%'    THEN  '1' 
ELSE '1' END ) jws_yfjzs_ymjz-- 预防接种史-疫苗接种
##select * 
from coc_db.patient_jgbl_info
where DocumentName like '%骨肿瘤%入院%' 
##and ipblh='0001615341'
    group by 
	id,
	ipblh,
	sfzh,
	PatientName
,XGRQ
,YJLXH
,KH
,KLX
;



-- 骨肿瘤_现病史insert coc_db.coc_zy_gzl_ryjl_xbs
insert coc_db.coc_zy_gzl_ryjl_xbs
(
yljgdm, hzbh, jzlsh, jlsj, xbs_fbsj, xbs_ywyy, xbs_ttbw, xbs_ywhdss, xbs_zkdx, xbs_zkzd, xbs_hdd, xbs_ywyt
, xbs_vaspf, xbs_bszz, xbs_sfzyyjz, xbs_jzyy, xbs_jzyyyxjc_mshbg, xbs_sfcszl, xbs_cszlwbms, xbs_sfcchj, xbs_cchj_rq
, xbs_cchj_yy, xbs_cchj_bw, xbs_cchj_ccbl, xbs_cchj_ccjgms, xbs_sfsqzl, xbs_sfsqhl, xbs_sqhl_yy, xbs_sqhl_rq, xbs_sqhl_ywhjl
, xbs_sqhl_lx, xbs_sqhl_ffy, xbs_sqhl_ffyjb, xbs_sqhl_sflymy, xbs_sqhl_sflybx, xbs_sfsqfl, xbs_sqfl_yy, xbs_sqfl_rq
, xbs_sqfl_ywhjl, xbs_sqfl_lx, xbs_sqfl_ffy, xbs_sqfl_ffyjb, xbs_sfsszl, xbs_ss_yy, xbs_ss_rq, xbs_ss_ssfs, xbs_ss_ssnr
, xbs_ss_sfszsx, xbs_ss_shfy, xbs_ss_shbl, xbs_sffzzl, xbs_fzzl_hl_yy, xbs_fzzl_hl_rq, xbs_fzzl_hl_ywhjl, xbs_fzzl_hl_lx
, xbs_fzzl_hl_ffy, xbs_fzzl_hl_ffyjb, xbs_fzzl_fl_yy, xbs_fzzl_fl_rq, xbs_fzzl_fl_bw, xbs_fzzl_fl_jl, xbs_fzzl_fl_ffy
, xbs_fzzl_fl_ffyjb, xbs_sfshlymy, xbs_sfshlybx, xbs_sfsf, xbs_sfrq, xbs_sfjg, xbs_pg, xbs_sfffzy, xbs_ffzy_rq, xbs_ffzy_bw
, xbs_ffzy_sfzl, xbs_ffzy_zl_yy, xbs_ffzy_zl_rq, xbs_ffzy_zl_zlfs, xbs_ffzy_hl_rq, xbs_ffzy_hl_yy, xbs_ffzy_hl_ywhjl
, xbs_ffzy_hl_lx, xbs_ffzy_hl_ffy, xbs_ffzy_hl_ffyjb, xbs_ffzy_fl_yy, xbs_ffzy_fl_rq, xbs_ffzy_fl_bw, xbs_ffzy_fl_jl
, xbs_ffzy_fl_ffy, xbs_ffzy_fl_ffyjb, xbs_ffzy_ss_yy, xbs_ffzy_ss_rq, xbs_ffzy_ss_ssfs, xbs_ffzy_ss_ssnr, xbs_ffzy_jr_nr
, xbs_ffzy_sflymy, xbs_ffzy_sflybx, xbs_ryjd, xbs_hlcs
)
select
'42502658000' yljgdm
,SFZH hzbh
,IPBLH jzlsh
,XGRQ jlsj
,null xbs_fbsj
,max( 
CASE     WHEN ParagraphName = '骨肿瘤-现病史'      AND ValueItemName = '发病日期'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '骨肿瘤-现病史'      AND ValueItemName = '发病日期'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) xbs_ywyy,-- 现病史-有无诱因
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%手%'    THEN  '1' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%腕%'    THEN  '2' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%尺骨%'    THEN  '3' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%桡骨%'    THEN  '4' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%肘关节%'    THEN  '5' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%肱骨%'    THEN  '6' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%上臂%'    THEN  '7' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%前臂%'    THEN  '8' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%肩关节%'    THEN  '9' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%腋窝%'    THEN  '10' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%颈部%'    THEN  '11' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%背部%'    THEN  '12' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%腰部%'    THEN  '13' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%颈椎%'    THEN  '14' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%胸椎%'    THEN  '15' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%腰椎%'    THEN  '16' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%胸壁%'    THEN  '17' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%腹壁%'    THEN  '18' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%骶骨%'    THEN  '19' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%髂骨%'    THEN  '20' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%髋臼%'    THEN  '21' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%耻骨%'    THEN  '22' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%股骨%'    THEN  '23' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%膝关节%'    THEN  '24' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%胫骨%'    THEN  '25' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%腓骨%'    THEN  '26' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%踝关节%'    THEN  '27' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%足%'    THEN  '28' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%大腿%'    THEN  '29' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%小腿%'    THEN  '30' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-疼痛部位'    AND DisplayString LIKE '%其他%'    THEN  '99' 
ELSE '99' END ) xbs_ttbw,-- 现病史-疼痛部位
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '有无'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '有无'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) xbs_ywhdss,-- 现病史-有无活动受限
max( 
    CASE WHEN ParagraphName = '现病史'      AND ValueItemName = '肿块大小'    THEN DisplayString ELSE null END ) xbs_zkdx,-- 现病史-肿块大小
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-肿块质地'    AND DisplayString LIKE '%硬%'    THEN  '1' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-肿块质地'    AND DisplayString LIKE '%软%'    THEN  '2' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '前列腺-肿块质地'    AND DisplayString LIKE '%韧%'    THEN  '3' 
ELSE '3' END ) xbs_zkzd,-- 现病史-肿块质地
max( 
    CASE WHEN ParagraphName = '现病史'      AND ValueItemName = '可/差'    THEN DisplayString ELSE '1' END ) xbs_hdd,-- 现病史-活动度
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-有无压痛'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-有无压痛'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) xbs_ywyt,-- 现病史-有无压痛
max( 
    CASE WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-VAS评分'    THEN DisplayString ELSE null END ) xbs_vaspf,-- 现病史-VAS评分
max( 
    CASE WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-伴随症状'    THEN DisplayString ELSE null END ) xbs_bszz,-- 现病史-伴随症状
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否医院就诊'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否医院就诊'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) xbs_sfzyyjz,-- 现病史-是否至医院就 诊
max( 
    CASE WHEN ParagraphName = '现病史'      AND ValueItemName = '现病史-就诊医院'    THEN DisplayString ELSE null END ) xbs_jzyy,-- 现病史-就诊医院
max( 
    CASE WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-就诊医院描述'    THEN DisplayString ELSE null END ) xbs_jzyyyxjc_mshbg,-- 现病史-就诊医院影像  检查的检查描述和报告
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否初始治疗'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否初始治疗'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfcszl,-- 现病史-是否初始治疗
max( 
    CASE WHEN ParagraphName = '现病史'      AND ValueItemName = '初始治疗描述'    THEN DisplayString ELSE null END ) xbs_cszlwbms,-- 现病史-初始治疗文本 描述
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否穿刺活检'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否穿刺活检'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfcchj-- 现病史-是否穿刺活检
,'未进行穿刺活检' xbs_cchj_rq
,'未进行穿刺活检' xbs_cchj_yy
,99 xbs_cchj_bw
,'未进行穿刺活检' xbs_cchj_ccbl
,'未进行穿刺活检' xbs_cchj_ccjgms
,max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否术前治疗'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否术前治疗'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfsqzl,-- 现病史-是否术前治疗
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否术前化疗'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否术前化疗'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfsqhl-- 现病史-是否术前化疗
,'我院' xbs_sqhl_yy
,null xbs_sqhl_rq
,'未进行术前化疗' xbs_sqhl_ywhjl
,9 xbs_sqhl_lx
,99 xbs_sqhl_ffy
,'' xbs_sqhl_ffyjb
,max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否免疫治疗药物'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否免疫治疗药物'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sqhl_sflymy,-- 现病史-术前化疗-是否 联用免疫
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否靶向药物治疗'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否靶向药物治疗'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sqhl_sflybx,-- 现病史-术前化疗-是否 联用靶向
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否术前放疗'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否术前放疗'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfsqfl-- 现病史-是否术前放疗
,'我院' xbs_sqfl_yy
,null xbs_sqfl_rq
,'未进行术前放疗' xbs_sqfl_ywhjl
,null xbs_sqfl_lx
,99 xbs_sqfl_ffy
,null bs_sqfl_ffyjb
,max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否手术治疗'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否手术治疗'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfsszl-- 现病史-是否手术治疗
,'我院' xbs_ss_yy
,null xbs_ss_rq
,'未进行手术' xbs_ss_ssfs
,'未进行手术' bs_ss_ssnr
,max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否术中输血'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否术中输血'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_ss_sfszsx-- 现病史-手术-是否术中 输血
,'未进行手中输血' xbs_ss_shfy
,'未进行手中输血' xbs_ss_shbl
,max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否辅助治疗'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否辅助治疗'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sffzzl-- 现病史-是否辅助治疗
,'我院' xbs_fzzl_hl_yy
,null xbs_fzzl_hl_rq
,'未进行辅助治疗'  xbs_fzzl_hl_ywhjl
,null xbs_fzzl_hl_lx
,99 xbs_fzzl_hl_ffy
,null xbs_fzzl_hl_ffyjb
,'未进行辅助治疗'  xbs_fzzl_fl_yy
,null xbs_fzzl_fl_rq
,'未进行辅助治疗'  xbs_fzzl_fl_bw
,'未进行辅助治疗'  xbs_fzzl_fl_jl
,99 xbs_fzzl_fl_ffy
,null xbs_fzzl_fl_ffyjb
,max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否联用免疫治疗药物'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否联用免疫治疗药物'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfshlymy,-- 现病史-是否术后联用 免疫治疗药物
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否联用靶向治疗药物'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否联用靶向治疗药物'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfshlybx,-- 现病史-是否术后联用 靶向治疗药物
max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否随访'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否随访'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfsf-- 现病史-是否随访
,null xbs_sfrq
,null xbs_sfjg
,null xbs_pg
,max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否复发/转移'    AND DisplayString LIKE '%否%'    THEN  '0' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-是否复发/转移'    AND DisplayString LIKE '%是%'    THEN  '1' 
ELSE '0' END ) xbs_sfffzy-- 现病史-是否复发/转移
,null	xbs_ffzy_rq
,null	xbs_ffzy_bw
,0	xbs_ffzy_sfzl
,'我院'	xbs_ffzy_zl_yy
,null	xbs_ffzy_zl_rq
,null	xbs_ffzy_zl_zlfs
,null	xbs_ffzy_hl_rq
,'我院'	xbs_ffzy_hl_yy
,null	xbs_ffzy_hl_ywhjl
,null	xbs_ffzy_hl_lx
,99	xbs_ffzy_hl_ffy
,null	xbs_ffzy_hl_ffyjb
,'我院'	xbs_ffzy_fl_yy
,null	xbs_ffzy_fl_rq
,null	xbs_ffzy_fl_bw
,0	xbs_ffzy_fl_jl
,99	xbs_ffzy_fl_ffy
,0	xbs_ffzy_fl_ffyjb
,'我院'	xbs_ffzy_ss_yy
,null	xbs_ffzy_ss_rq
,null	xbs_ffzy_ss_ssfs
,'未记录'	xbs_ffzy_ss_ssnr
,'未记录'	xbs_ffzy_jr_nr
,0	xbs_ffzy_sflymy
,0	xbs_ffzy_sflybx

,max( 
CASE     WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-术前、术后、复发后、转移'    AND DisplayString LIKE '%术前%'    THEN  '1' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-术前、术后、复发后、转移'    AND DisplayString LIKE '%术后%'    THEN  '2' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-术前、术后、复发后、转移'    AND DisplayString LIKE '%复发后%'    THEN  '3' 
    WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-术前、术后、复发后、转移'    AND DisplayString LIKE '%转移%'    THEN  '4' 
ELSE '' END ) xbs_ryjd,-- 现病史-入院阶段
max( 
    CASE WHEN ParagraphName = '现病史'      AND ValueItemName = '骨肿瘤-`n`'    THEN DisplayString ELSE '0' END ) xbs_hlcs-- 现病史-化疗次数
##select * 
from coc_db.patient_jgbl_info
where DocumentName like '%骨肿瘤%入院%'  and ValueItemName='原发/复发转移-有无复选-ppa'
##and ipblh='0001615341'
    group by 
	id,
	ipblh,
	sfzh,
	PatientName
,XGRQ
,YJLXH
,KH
,KLX
;


insert coc_db.coc_zy_gzl_ryjl_grs
(
yljgdm, hzbh, jzlsh, jlsj, grs_ywxys, grs_ksxyrq, grs_jyrq, grs_mrxyl, grs_xyns, grs_sfbdxys, grs_jy, grs_jyns, grs_ywyjs, grs_ksyjrq
, grs_jjrq, grs_mtyjzl, grs_mtyjl, grs_hys_hyqk, grs_hys_yy, grs_yjs_lmp, grs_yjs_cc, grs_yjs_zq, grs_yjs_jq
)
-- 骨肿瘤_个人史
select
'42502658000' yljgdm
,SFZH hzbh
,IPBLH jzlsh
,XGRQ jlsj
,
max( 
CASE     WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '有无吸烟史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '有无吸烟史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) grs_ywxys-- 个人史-有无吸烟史
,'' grs_ksxyrq
,'' grs_jyrq
,0 grs_mrxyl
,0 grs_xyns
,0 grs_sfbdxys
,0 grs_jy
,0 grs_jyns
,max( 
CASE     WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '有/无饮酒史'    AND DisplayString LIKE '%无%'    THEN  '0' 
    WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '有/无饮酒史'    AND DisplayString LIKE '%有%'    THEN  '1' 
ELSE '0' END ) grs_ywyjs-- 个人史-有无饮酒史
,'' grs_ksyjrq
,'' grs_jjrq
,'否认饮酒史' grs_mtyjzl
,0 grs_mtyjl

,max( 
CASE     WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '已婚/未婚'    AND DisplayString LIKE '%已婚%'    THEN  '1' 
    WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '已婚/未婚'    AND DisplayString LIKE '%未婚%'    THEN  '0' 
ELSE '0' END ) grs_hys_hyqk,-- 婚育史-婚姻情况
max( 
CASE     WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '已育/未育'    AND DisplayString LIKE '%已育%'    THEN  '1' 
    WHEN ParagraphName = '原发/复发转移'      AND ValueItemName = '已育/未育'    AND DisplayString LIKE '%未育%'    THEN  '0' 
ELSE '0' END ) grs_hys_yy-- 婚育史-孕育
,0 grs_yjs_lmp
,0 grs_yjs_cc
,0 grs_yjs_zq
,0 grs_yjs_jq


##select * 
from coc_db.patient_jgbl_info
where DocumentName like '%骨肿瘤%入院%' 
##and ipblh='0001615341'
    group by 
	id,
	ipblh,
	sfzh,
	PatientName
,XGRQ
,YJLXH
,KH
,KLX
;



-- 骨肿瘤_既往非肿瘤疾病史
insert coc_db.coc_zy_gzl_ryjl_jwfzljbs
(
yljgdm, hzbh, jzlsh, jlsj, jwfzljbs_xh, jwfzljbs_jbmc, jwfzljbs_zdrq, jwfzljbs_zlqk
)
select
'42502658000' yljgdm
,SFZH hzbh
,IPBLH jzlsh
,XGRQ jlsj
,0 jwxgzls_xh
,null jwxgzls_zlmc
,null jwxgzls_zllx
,null wxgzls_zlzdrq
##select * 
from coc_db.patient_jgbl_info
where DocumentName like '%骨肿瘤%入院%' 
##and ipblh='0001615341'
    group by 
	id,
	ipblh,
	sfzh,
	PatientName
,XGRQ
,YJLXH
,KH
,KLX
;




-- 骨肿瘤_既往相关肿瘤史
INSERT INTO coc_db.coc_zy_gzl_ryjl_jwxgzls
(yljgdm, hzbh, jzlsh, jlsj, jwxgzls_xh, jwxgzls_zlmc, jwxgzls_zllx, jwxgzls_zlzdrq)
select
'42502658000' yljgdm
,SFZH hzbh
,IPBLH jzlsh
,XGRQ jlsj
,0 jwfzljbs_xh
,'否认相关肿瘤史' jwfzljbs_jbmc
,null jwfzljbs_zdrq
,null jwfzljbs_zlqk
##select * 
from coc_db.patient_jgbl_info
where DocumentName like '%骨肿瘤%入院%' 
##and ipblh='0001615341'
    group by 
	id,
	ipblh,
	sfzh,
	PatientName
,XGRQ
,YJLXH
,KH
,KLX
;



