Commit fa9d5a96 authored by Lorex's avatar Lorex
Browse files

feat: List observation in patient detail page

parent d1978c7d
......@@ -53,8 +53,85 @@ const getPatient = (id) => {
</div>
</div>
`);
// 抓 Observation 資料
fetch(`${baseUrl}/Observation?subject=${id}`)
.then(res => res.json())
.then(response => {
let ObservationList = response.entry;
// 建立表格
content.append(`
<h2>檢驗記錄</h2>
<p>共找到 ${response.total} 筆資料</p>
<table class="table table-hover">
<thead>
<tr>
<th>id</th>
<th>檢驗項目</th>
<th>檢驗值</th>
<th>查看</th>
</tr>
</thead>
<tbody id="ObservationTableBody"> </tbody>
</table>`);
ObservationList.map( entry => {
$('#ObservationTableBody').append(`
<tr>
<td>${entry.resource.id}</td>
<td>${(entry.resource.code)?(entry.resource.code.coding[0].display):""}</td>
<td>${entry.resource.valueQuantity.value} ${entry.resource.valueQuantity.unit}</td>
<td><button class="btn btn-info btn-sm" onclick="getObservation(${entry.resource.id})">查看</button></td>
</tr>
`);
});
// 顯示下一頁資料
if(response.link.length > 1 && response.link[1].relation === 'next'){
content.append(`<a onclick="listObservationInPatient('${response.link[1].url}')" class="btn btn-primary" id="nextPage">下一頁</a>`);
}
});
});
};
const listObservationInPatient = (url) => {
let table = $('#ObservationTableBody');
// 清空表格
table.empty();
// 抓資料
fetch(`${url}`)
.then(res => res.json())
.then(json => {
let ObservationList = json.entry;
ObservationList.map(entry => {
$('#ObservationTableBody').append(`
<tr>
<td>${entry.resource.id}</td>
<td>${(entry.resource.code)?(entry.resource.code.coding[0].display):""}</td>
<td>${entry.resource.valueQuantity.value} ${entry.resource.valueQuantity.unit}</td>
<td><button class="btn btn-info btn-sm" onclick="getObservation(${entry.resource.id})">查看</button></td>
</tr>
`);
});
// 清空按紐
$('#nextPage').remove();
$('#prevPage').remove();
// 顯示上一頁資料
if(json.link.length === 2 && json.link[1].relation === 'previous'){ // 最末頁
content.append(`<a onclick="listObservationInPatient('${json.link[1].url}')" class="btn btn-primary" id="prevPage">上一頁</a>`);
} else if (json.link.length === 3 && json.link[2].relation === 'previous'){
content.append(`<a onclick="listObservationInPatient('${json.link[2].url}')" class="btn btn-primary" id="prevPage">上一頁</a>`);
}
// 顯示下一頁資料
if(json.link.length > 1 && json.link[1].relation === 'next'){
content.append(`<a onclick="listObservationInPatient('${json.link[1].url}')" class="btn btn-primary" id="nextPage">下一頁</a>`);
}
});
}
\ No newline at end of file
......@@ -16,6 +16,7 @@
<script src="assets/js-fhir/listPatient.js"></script>
<script src="assets/js-fhir/listObservation.js"></script>
<script src="assets/js-fhir/getPatient.js"></script>
<script src="assets/js-fhir/getObservation.js"></script>
<script src="assets/js-fhir/uploadPatient.js"></script>
<script src="assets/js-fhir/uploadObservation.js"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment