是這樣的,今天我想做一個功能畫面如圖
根據左邊的通知時間來判定狀態是已排床還是未排床
這是我這功能的table,名字叫HD_REQUIRE
這是我需要查詢狀態的table,名字叫PAT_SCHEDULE
目前我能夠找到小於我通知時間的所有資料
這是我的sql
select b.pat_guid,a.notice_datetime,b.dia_date
from hd_require a
join pat_schedule b
on a.PAT_GUID = b.PAT_GUID
WHERE a.notice_datetime>b.dia_date
linq
public List<HDRequireDto> FindRequire( string cid, DateTime StartDate, DateTime EndDate)
{
EndDate = new DateTime(EndDate.Year, EndDate.Month, EndDate.Day, 0, 0, 0).AddDays(1);
var query = (from x in _repo.HD_REQUIRE
from y in _repo.PAT_SCHEDULE where y.PAT_GUID == x.PAT_GUID && x.NOTICE_DATETIME >y.DIA_DATE
where (x.CID == cid && x.NOTICE_DATETIME >= StartDate && x.NOTICE_DATETIME < EndDate)
select new HDRequireDto
{
GUID =x.GUID,
CID =x.CID,
NOTICE_DATETIME =x.NOTICE_DATETIME ,
NOTICE_EMP_ID=x.NOTICE_EMP_ID,
PAT_GUID=x.PAT_GUID,
PAT_SOURCE=x.PAT_SOURCE,
IPD_BED_NO =x.IPD_BED_NO,
HD_METHOD=x.HD_METHOD,
FREQ=x.FREQ,
MEMO=x.MEMO,
CRE_DATE=x.CRE_DATE,
STATUS=x.STATUS,
CRE_UID=x.CRE_UID,
MOD_DATE = x.MOD_DATE,
MOD_UID=x.MOD_UID
}).OrderByDescending(x=>x.NOTICE_DATETIME).ToList<HDRequireDto>();
//方式
List<NCODE> codList = _repo.NCODE.Where(x => x.CID == cid && x.NC_ID == NcId.MethodList).ToList<NCODE>();
//頻率
List<NCODE> codList2 = _repo.NCODE.Where(x => x.CID == cid && x.NC_ID == NcId.FreqList).ToList<NCODE>();
foreach (HDRequireDto dto in query)
{
//護士名字
dto.Name = _repo.EMPLOYEE.Where(x => x.CID == dto.CID && x.EMP_ID == dto.NOTICE_EMP_ID).FirstOrDefault<EMPLOYEE>().EMP_NAME;
//來源
dto.Source = _repo.NCODE.Where(x => x.CID == dto.CID && x.NC_ID == NcId.PatSourceList && x.NC_CODE == dto.PAT_SOURCE).FirstOrDefault<NCODE>().NC_NAME;
//病患名字
dto.PatName = _repo.PATIENT.Where(x => x.CID == dto.CID && x.GUID == dto.PAT_GUID).FirstOrDefault<PATIENT>().PAT_NAME;
var lastitem = query.Last();
foreach (var item in query)
{
if (item == lastitem)
{
return query;
}
}
}
return query;
}
前端
最終執行結果是這樣
已經算是我要的結果了,只是下面空白的部分我該如何取消掉?
1.通知時間:HD_REQUIRE.NOTICE_DATETIME
2.通知者 :HD_REQUIRE.NOTICE_EPM_ID
3.病患姓名:HD_REQUIRE.PAT_GUID
4.病患來源:HD_REQUIRE.PAT_SOURCE 或 PAT_SCHEDULE.PAT_SOURCE
5.病床號碼:HD_REQUIRE.IPD_BED_NO
6.狀 態:HD_REQUIRE.STATUS 或 PAT_SCHEDULE.STATUS
7.若第 4 點 = HD_REQUIRE.PAT_SOURCE 且第 6 點 = HD_REQUIRE.STATUS,
若要 JOIN PAT_SCHEDULE 且 a.notice_datetime>b.dia_date ,
那就 SELECT DISTINCT
8.若第 4 點 = PAT_SCHEDULE.PAT_SOURCE 或第 6 點 = PAT_SCHEDULE.STATUS ,那就可能會出現多筆
9.若是第 8 點而且相同通知時間只要留第一筆,其他相同的空白,那就只能在加工處理了
10.若 HD_REQUIRE.PAT_SOURCE = PAT_SCHEDULE.PAT_SOURCE 或HD_REQUIRE.STATUS = PAT_SCHEDULE.STATUS ,那就要加入條件式內