<div moe extra-huge id="bp-management-settings">
    <a href="#" start show>Update</a>
    <form url="/api/client/updateBpManagementSettingsValue">
        <input type="hidden" name="uid" value="{{$patient->uid}}">
        <p class="text-secondary font-weight-bold font-size-14">BP Management</p>

        <div class="row mx-0">
            <div class="col-6 pl-0 pr-2 border-right">
                <div class="text-secondary font-weight-bold mb-3">Usual BP:</div>
                <div class="pl-3 mb-2">
                    <div class="text-secondary font-weight-bold mb-2">
                        <i class="fa fa-sun"></i>
                        AM
                    </div>
                    <div class="pl-3">
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">SBP:</span>
                            <span class="text-secondary mr-2 text-center text-sm">ranging between</span>
                            <div class="width-70px mr-2"><?= vsElement('usual_am_resting_sbp_min', 'number', 'usualAmRestingSbpMin', $patient) ?></div>
                            <span class="text-secondary mr-2">and</span>
                            <div class="width-70px"><?= vsElement('usual_am_resting_sbp_max', 'number', 'usualAmRestingSbpMax', $patient) ?></div>
                        </div>
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">DBP:</span>
                            <span class="text-secondary mr-2 text-center text-sm">ranging between</span>
                            <div class="width-70px mr-2"><?= vsElement('usual_am_resting_dbp_min', 'number', 'usualAmRestingDbpMin', $patient) ?></div>
                            <span class="text-secondary mr-2">and</span>
                            <div class="width-70px"><?= vsElement('usual_am_resting_dbp_max', 'number', 'usualAmRestingDbpMax', $patient) ?></div>
                        </div>
                        <div class="mb-1 d-flex align-items-center">
                            <span class="text-secondary width-70px">Pulse:</span>
                            <span class="text-secondary mr-2 text-center text-sm">ranging between</span>
                            <div class="width-70px mr-2"><?= vsElement('usual_am_resting_pulse_min', 'number', 'usualAmRestingPulseMin', $patient) ?></div>
                            <span class="text-secondary mr-2">and</span>
                            <div class="width-70px"><?= vsElement('usual_am_resting_pulse_max', 'number', 'usualAmRestingPulseMax', $patient) ?></div>
                        </div>
                    </div>
                </div>
                <div class="pl-3 mb-3">
                    <div class="text-secondary font-weight-bold mb-2">
                        <i class="fa fa-moon"></i>
                        PM
                    </div>
                    <div class="pl-3">
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">SBP:</span>
                            <span class="text-secondary mr-2 text-center text-sm">ranging between</span>
                            <div class="width-70px mr-2"><?= vsElement('usual_pm_resting_sbp_min', 'number', 'usualPmRestingSbpMin', $patient) ?></div>
                            <span class="text-secondary mr-2">and</span>
                            <div class="width-70px"><?= vsElement('usual_pm_resting_sbp_max', 'number', 'usualPmRestingSbpMax', $patient) ?></div>
                        </div>
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">DBP:</span>
                            <span class="text-secondary mr-2 text-center text-sm">ranging between</span>
                            <div class="width-70px mr-2"><?= vsElement('usual_pm_resting_dbp_min', 'number', 'usualPmRestingDbpMin', $patient) ?></div>
                            <span class="text-secondary mr-2">and</span>
                            <div class="width-70px"><?= vsElement('usual_pm_resting_dbp_max', 'number', 'usualPmRestingDbpMax', $patient) ?></div>
                        </div>
                        <div class="mb-1 d-flex align-items-center">
                            <span class="text-secondary width-70px">Pulse:</span>
                            <span class="text-secondary mr-2 text-center text-sm">ranging between</span>
                            <div class="width-70px mr-2"><?= vsElement('usual_pm_resting_pulse_min', 'number', 'usualPmRestingPulseMin', $patient) ?></div>
                            <span class="text-secondary mr-2">and</span>
                            <div class="width-70px"><?= vsElement('usual_pm_resting_pulse_max', 'number', 'usualPmRestingPulseMax', $patient) ?></div>
                        </div>
                    </div>
                </div>
                <hr class="my-3">

                <div class="text-secondary font-weight-bold mb-3">Ideal BP:</div>
                <div class="pl-3 mb-3">
                    <div class="pl-3">
                        <div class="mb-1 d-flex align-items-center">
                            <span class="text-secondary min-width-70px">SBP:</span>
                            <div class="width-70px mr-2"><?= vsElement('ideal_am_resting_sbp', 'number', 'idealAmRestingSbp', $patient) ?></div>
                            <span class="text-secondary">Goal: &nbsp;</span>
                            <div class="flex-grow-1">
                                <select class="form-control form-control-sm min-width-unset rounded-0" name="sbpManagementGoalCategory">
                                    <option value="">-- select --</option>
                                    <option {{$patient->sbp_management_goal_category === 'LOWER' ? 'selected' : ''}} value="LOWER">Lower</option>
                                    <option {{$patient->sbp_management_goal_category === 'INCREASE' ? 'selected' : ''}} value="INCREASE">Increase</option>
                                    <option {{$patient->sbp_management_goal_category === 'MAINTAIN' ? 'selected' : ''}} value="MAINTAIN">Maintain</option>
                                </select>
                            </div>
                        </div>
                        <div class="mb-1 d-flex align-items-center">
                            <span class="text-secondary min-width-70px">DBP:</span>
                            <div class="width-70px mr-2"><?= vsElement('ideal_am_resting_dbp', 'number', 'idealAmRestingDbp', $patient) ?></div>
                            <span class="text-secondary">Goal: &nbsp;</span>
                            <div class="flex-grow-1">
                                <select class="form-control form-control-sm min-width-unset rounded-0" name="dbpManagementGoalCategory">
                                    <option value="">-- select --</option>
                                    <option {{$patient->dbp_management_goal_category === 'LOWER' ? 'selected' : ''}} value="LOWER">Lower</option>
                                    <option {{$patient->dbp_management_goal_category === 'INCREASE' ? 'selected' : ''}} value="INCREASE">Increase</option>
                                    <option {{$patient->dbp_management_goal_category === 'MAINTAIN' ? 'selected' : ''}} value="MAINTAIN">Maintain</option>
                                </select>
                            </div>
                        </div>
                        <div class="mb-1 d-flex align-items-center">
                            <span class="text-secondary min-width-70px">Pulse:</span>
                            <div class="width-70px mr-2"><?= vsElement('ideal_am_resting_pulse', 'number', 'idealAmRestingPulse', $patient) ?></div>
                            <span class="text-secondary">Goal: &nbsp;</span>
                            <div class="flex-grow-1">
                                <select class="form-control form-control-sm min-width-unset rounded-0" name="pulseManagementGoalCategory">
                                    <option value="">-- select --</option>
                                    <option {{$patient->pulse_management_goal_category === 'LOWER' ? 'selected' : ''}} value="LOWER">Lower</option>
                                    <option {{$patient->pulse_management_goal_category === 'INCREASE' ? 'selected' : ''}} value="INCREASE">Increase</option>
                                    <option {{$patient->pulse_management_goal_category === 'MAINTAIN' ? 'selected' : ''}} value="MAINTAIN">Maintain</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <hr class="my-3">
            </div>
            <div class="col-6 pr-0 pl-2">
                <div class="text-secondary font-weight-bold mb-3">Alerts</div>
                <div class="pl-3 mb-3">
                    <div class="text-secondary font-weight-bold mb-2">
                        <i class="fa fa-circle text-danger"></i>
                        Red
                    </div>
                    <div class="pl-3">
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">SBP: </span>
                            <span class="text-secondary text-sm mr-2">above</span> <div class="width-70px mr-2"> <?= vsElement('red_alert_when_sbp_above', 'number', 'redAlertWhenSbpAbove', $patient) ?></div>
                            <span class="text-secondary text-sm text-nowrap mr-2">or below</span>
                            <div class="width-70px"><?= vsElement('red_alert_when_sbp_below', 'number', 'redAlertWhenSbpBelow', $patient) ?></div>
                        </div>
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">DBP: </span>
                            <span class="text-secondary text-sm mr-2">above</span> <div class="width-70px mr-2"> <?= vsElement('red_alert_when_dbp_above', 'number', 'redAlertWhenDbpAbove', $patient) ?></div>
                            <span class="text-secondary text-sm text-nowrap mr-2">or below</span>
                            <div class="width-70px"><?= vsElement('red_alert_when_dbp_below', 'number', 'redAlertWhenDbpBelow', $patient) ?></div>
                        </div>
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">Pulse: </span>
                            <span class="text-secondary text-sm mr-2">above</span> <div class="width-70px mr-2"><?= vsElement('red_alert_when_pulse_above', 'number', 'redAlertWhenPulseAbove', $patient) ?></div>
                            <span class="text-secondary text-sm text-nowrap mr-2">or below</span>
                            <div class="width-70px"><?= vsElement('red_alert_when_pulse_below', 'number', 'redAlertWhenPulseBelow', $patient) ?></div>
                        </div>
                    </div>
                </div>
                <div class="pl-3 mb-2">
                    <div class="text-secondary font-weight-bold mb-2">
                        <i class="fa fa-circle text-warning-mellow"></i>
                        Yellow
                    </div>
                    <div class="pl-3">
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">SBP: </span>
                            <span class="text-secondary text-sm mr-2">above</span> <div class="width-70px mr-2"><?= vsElement('yellow_alert_when_sbp_above', 'number', 'yellowAlertWhenSbpAbove', $patient) ?></div>
                            <span class="text-secondary text-sm text-nowrap mr-2">or below</span>
                            <div class="width-70px"><?= vsElement('yellow_alert_when_sbp_below', 'number', 'yellowAlertWhenSbpBelow', $patient) ?></div>
                        </div>
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">DBP: </span>
                            <span class="text-secondary text-sm mr-2">above</span> <div class="width-70px mr-2"><?= vsElement('yellow_alert_when_dbp_above', 'number', 'yellowAlertWhenDbpAbove', $patient) ?></div>
                            <span class="text-secondary text-sm text-nowrap mr-2">or below</span>
                            <div class="width-70px"><?= vsElement('yellow_alert_when_dbp_below', 'number', 'yellowAlertWhenDbpBelow', $patient) ?></div>
                        </div>
                        <div class="mb-2 d-flex align-items-center">
                            <span class="text-secondary width-70px">Pulse: </span>
                            <span class="text-secondary text-sm mr-2">above</span> <div class="width-70px mr-2"><?= vsElement('yellow_alert_when_pulse_above', 'number', 'yellowAlertWhenPulseAbove', $patient) ?></div>
                            <span class="text-secondary text-sm text-nowrap mr-2">or below</span>
                            <div class="width-70px"><?= vsElement('yellow_alert_when_pulse_below', 'number', 'yellowAlertWhenPulseBelow', $patient) ?></div>
                        </div>
                    </div>
                </div>
                <hr class="my-3">

                <div class="mb-2 d-flex align-items-start">
                    <span class="text-secondary min-width-140px w-50">Reports prehypertension?</span>
                    <div class="w-50">
                        <select type="text" class="form-control form-control-sm min-width-unset" name="hasPrehypertensionDx">
                            <option value="">-- select --</option>
                            <option {{$patient->has_prehypertension_dx === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                            <option {{$patient->has_prehypertension_dx === 'NO' ? 'selected' : ''}} value="NO">No</option>
                            <option {{$patient->has_prehypertension_dx === 'UNKNOWN' ? 'selected' : ''}} value="UNKNOWN">Unknown</option>
                        </select>
                    </div>
                </div>
                <div class="mb-2 d-flex align-items-start">
                    <span class="text-secondary min-width-140px w-50">Reports HTN?</span>
                    <div class="w-50">
                        <select type="text" class="form-control form-control-sm min-width-unset" name="hasHypertensionDx">
                            <option value="">-- select --</option>
                            <option {{$patient->has_hypertension_dx === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                            <option {{$patient->has_hypertension_dx === 'NO' ? 'selected' : ''}} value="NO">No</option>
                            <option {{$patient->has_hypertension_dx === 'UNKNOWN' ? 'selected' : ''}} value="UNKNOWN">Unknown</option>
                        </select>
                    </div>
                </div>
                <div class="mb-2 d-flex align-items-start">
                    <span class="text-secondary min-width-140px w-50">Reports HTN medicine?</span>
                    <div class="w-50">
                        <select type="text" class="form-control form-control-sm min-width-unset" name="isPrescribedHypertensionMedicine">
                            <option value="">-- select --</option>
                            <option {{$patient->is_prescribed_hypertension_medicine === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                            <option {{$patient->is_prescribed_hypertension_medicine === 'NO' ? 'selected' : ''}} value="NO">No</option>
                            <option {{$patient->is_prescribed_hypertension_medicine === 'UNKNOWN' ? 'selected' : ''}} value="UNKNOWN">Unknown</option>
                        </select>
                    </div>
                </div>
                <div class="mb-2 d-flex align-items-start">
                    <span class="text-secondary min-width-140px w-50">Goal to reduce HTN medicine?</span>
                    <div class="w-50">
                        <select type="text" class="form-control form-control-sm min-width-unset" name="isGoalToReduceHypertensionMedicine">
                            <option value="">-- select --</option>
                            <option {{$patient->is_goal_to_reduce_hypertension_medicine === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                            <option {{$patient->is_goal_to_reduce_hypertension_medicine === 'NO' ? 'selected' : ''}} value="NO">No</option>
                            <option {{$patient->is_goal_to_reduce_hypertension_medicine === 'UNKNOWN' ? 'selected' : ''}} value="UNKNOWN">Unknown</option>
                        </select>
                    </div>
                </div>

                <div class="text-secondary min-width-140px mb-1">Describe the goal:</div>
                <input type="text" class="form-control form-control-sm min-width-unset" name="goalToReduceHypertensionMedicineMemo" value="{{$patient->goal_to_reduce_hypertension_medicine_memo}}">

                <div class="my-3 d-flex align-items-center">
            <span class="text-secondary min-width-140px w-50">
                <strong>BP monitoring prescribed?</strong>
            </span>
                    <div class="w-50">
                        <select type="text" class="form-control form-control-sm min-width-unset" name="isBpMonitoringNeeded">
                            <option value="">-- select --</option>
                            <option {{$patient->is_bp_monitoring_needed === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                            <option {{$patient->is_bp_monitoring_needed === 'NO' ? 'selected' : ''}} value="NO">No</option>
                            <option {{$patient->is_bp_monitoring_needed === 'UNKNOWN' ? 'selected' : ''}} value="UNKNOWN">Unknown</option>
                        </select>
                    </div>
                </div>

                {{--
                <hr class="my-3">
                <div class="text-secondary min-width-140px mb-1">ICDs</div>
                <table class="table table-sm table-striped table-bordered mb-3">
                    <thead>
                    <tr class="bg-light text-secondary">
                        <th class="border-bottom-0 width-30px">#</th>
                        <th class="border-bottom-0 w-25">Code</th>
                        <th class="border-bottom-0">Description</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td class="p-0 align-middle text-center">1</td>
                        <td class="p-0 align-middle text-center"><?= vsElement('why_is_bp_monitoring_needed_icd1', 'text', 'whyIsBpMonitoringNeededIcd1', $patient) ?></td>
                        <td class="p-0 align-middle text-center"><?= vsElement('why_is_bp_monitoring_needed_description1', 'text', 'whyIsBpMonitoringNeededDescription1', $patient) ?></td>
                    </tr>
                    <tr>
                        <td class="p-0 align-middle text-center">2</td>
                        <td class="p-0 align-middle text-center"><?= vsElement('why_is_bp_monitoring_needed_icd2', 'text', 'whyIsBpMonitoringNeededIcd2', $patient) ?></td>
                        <td class="p-0 align-middle text-center"><?= vsElement('why_is_bp_monitoring_needed_description2', 'text', 'whyIsBpMonitoringNeededDescription2', $patient) ?></td>
                    </tr>
                    <tr>
                        <td class="p-0 align-middle text-center">3</td>
                        <td class="p-0 align-middle text-center"><?= vsElement('why_is_bp_monitoring_needed_icd3', 'text', 'whyIsBpMonitoringNeededIcd3', $patient) ?></td>
                        <td class="p-0 align-middle text-center"><?= vsElement('why_is_bp_monitoring_needed_description3', 'text', 'whyIsBpMonitoringNeededDescription3', $patient) ?></td>
                    </tr>
                    <tr>
                        <td class="p-0 align-middle text-center">4</td>
                        <td class="p-0 align-middle text-center"><?= vsElement('why_is_bp_monitoring_needed_icd4', 'text', 'whyIsBpMonitoringNeededIcd4', $patient) ?></td>
                        <td class="p-0 align-middle text-center"><?= vsElement('why_is_bp_monitoring_needed_description4', 'text', 'whyIsBpMonitoringNeededDescription4', $patient) ?></td>
                    </tr>
                    </tbody>
                </table>
                --}}
                <div class="text-secondary min-width-140px mb-1">Remarks on clinical need:</div>
                <input type="text" class="form-control form-control-sm min-width-unset" name="whyIsBpMonitoringNeeded" value="{{$patient->why_is_bp_monitoring_needed}}">

            </div>
        </div>

        <div class="pt-2">
            <button class="btn btn-primary btn-sm" submit>Submit</button>
            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
        </div>
    </form>
</div>
<script>
    (function() {

        function initICDAutoSuggest(_codeElem, _descElem) {
            if(_codeElem.is('[ac-initialized]')) return false;
            var elem = _codeElem[0], descElem = _descElem[0], dynID = 'icd-' + Math.ceil(Math.random() * 1000000);
            $(elem).attr('id', dynID);
            new window.Def.Autocompleter.Search(dynID,
                'https://clinicaltables.nlm.nih.gov/api/icd10cm/v3/search?sf=code,name&ef=name', {
                    tableFormat: true,
                    valueCols: [0],
                    colHeaders: ['Code', 'Name'],
                }
            );
            window.Def.Autocompleter.Event.observeListSelections(dynID, function() {
                let acData = elem.autocomp.getSelectedItemData();
                if(!acData[0] || !acData[0].data) return false;
                $(elem).val(acData[0].code);
                $(descElem).val(acData[0].data.name);
                return false;
            });
            $(elem).attr('ac-initialized', 1);
        }

        function init() {
            // for (let i = 1; i <= 4; i++) {
            //     initICDAutoSuggest($('[name="whyIsBpMonitoringNeededIcd' + i + '"]'), $('[name="whyIsBpMonitoringNeededDescription' + i + '"]'));
            // }
        }

        addMCInitializer('bp-management-settings', init, '#bp-management-settings');

    }).call(window);
</script>
