---
# System prepended metadata

title: '0406'
tags: [教學]

---

### 0406 Observation heart Rate上傳範例
```html=
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    使用者id:<input type="text" id="patientId">
    監測日期: <input type="date" id="date">
    心率: <input type="number" id="heartRateData">每分鐘/下
    <input type="button" onclick="heartRatePost()" value="post">
    <script>
        async function heartRatePost() {
            var patientId = document.getElementById('patientId').value;
            var date = document.getElementById('date').value;
            var heartRateData = document.getElementById('heartRateData').value;

            var heartRateData = {
                resourceType: "Observation",
                status: "final",
                category: [
                    {
                        coding: [
                            {
                                system:
                                    "http://terminology.hl7.org/CodeSystem/observation-category",
                                code: "vital-signs",
                                display: "Vital Signs",
                            },
                        ],
                        text: "Vital Signs",
                    },
                ],
                code: {
                    coding: [
                        {
                            system: "http://loinc.org",
                            code: "8867-4",
                            display: "Heart rate",
                        },
                    ],
                    text: "Heart rate",
                },
                subject: {
                    reference: "Patient/" + patientId,
                },
                effectiveDateTime: date,
                valueQuantity: {
                    value: heartRateData,
                    unit: "beats/minute",
                    system: "http://unitsofmeasure.org",
                    code: "/min",
                },
            };

            let fetchPromise = fetch(`https://fhir.tcumi.com:58443/r5/fhir/Observation`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/fhir+json",
                },
                body: JSON.stringify(heartRateData),
            })
                .then((response) => response.json())
                .then((heartRateData) => {
                    alert(JSON.stringify(heartRateData));
                })
                .catch((error) => {
                    console.error("Error:", error);
                    alert(error);
                });
        }

    </script>
</body>

</html>
```