<?php
if (!isset($_SESSION)) {
    session_start();
}

require_once("Connections/constants.php");
include("function/function.php");
$apikey = $_SESSION['apikey'];
$username = $_SESSION['facility_name'];
$password = $_SESSION['password'];
$providerId = $_SESSION['provider_id'];
$member_no = $_POST['id'];
$fullname = $_POST['idd2'];
$action = $_POST['act'];

$GET_VISIT_HISTORY_ALLERGY_SINGLE = array(
    'METHOD' => urlencode('GET_VISIT_HISTORY_ALLERGY_SINGLE'),
    'APIKEY' => $apikey,
    'USERNAME' => $username,
    'PASSWORD' => $password,
    'PROVIDERID' => $providerId,
    'ITEM_ID' => $member_no,

);
$get_saved_record_local = APICall($GET_VISIT_HISTORY_ALLERGY_SINGLE);
$get_saved_record_json_local = json_decode($get_saved_record_local,"true");
$savedRecord_local = $get_saved_record_json_local['RESULT'];

if ($get_saved_record_json_local['STATCODE'] == "200") {
    foreach ($savedRecord_local as $savedRecords) {
        $medication_id = $savedRecords['id'];
        $drug = $savedRecords['drug'];
        $food = $savedRecords['food'];
        $date_of_consultation = $savedRecords['date_time'];
        $reaction_status = $savedRecords['reaction_status'];
        $true_allergy_description = $savedRecords['true_allergy_description'];
        $adverse_effect_description = $savedRecords['adverse_effect_description'];
        $medication_medium = $savedRecords['medication_medium'];
        $reaction_duration = $savedRecords['reaction_duration'];
        $reaction_duration_ago = $savedRecords['reaction_duration_ago'];
        $reaction_medication_status = $savedRecords['reaction_medication_status'];
        $consultation_location = $savedRecords['consultation_location'];
        $stopped_by_doctor = $savedRecords['stopped_by_doctor'];
        $similar_medication = $savedRecords['similar_medication'];
        $same_problem = $savedRecords['same_problem'];

    }
}
//print_r(json_encode($savedRecord_local));
?>
<style>
    #bold_item{
        font-weight: 600;
        font-size:16px;
    }
</style>
<div class="kt-portlet__body" style="background-color: #ffff; color: #000000">
    <div class="row">
    <div class="col-md-12">
<form name="" id="add_allergies" method="post">
    <div class="row">
        <div class="col-12">
            <input type="hidden" name="member_no" id="member_no" value="<?php echo $member_no ?>">
            <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">Have you ever taken any medication(s) or Food that have caused a reaction ?</label>
            <div class="form-group row">
                <div class="col-10">
                    <?php if ($reaction_status == "Yes") { ?>


                    <label class="kt-radio kt-radio--bold kt-radio--success">
                        <input type="radio"  name="reaction_medication" id="reaction_medication" value="Yes" <?php if ($reaction_status == "Yes"){echo "checked";} ?> >Yes
                        <span></span>
                    </label>
                    <?php }else{ ?>
                    &nbsp;&nbsp;&nbsp;
                    <label class="kt-radio kt-radio--bold kt-radio--danger">
                        <input type="radio"  name="reaction_medication" id="reaction_medication" value="No" <?php if ($reaction_status == "No"){echo "checked";} ?>> No
                        <span></span>
                    </label>
                    <?php } ?>
                </div>
            </div>
        </div>
    </div>

    <span style="width:100%">
                            <div class="row">
                            <div class="col-md-6" style="width:100%">
                                <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">What medication(s) caused the reaction</label>
                                <div class="form-group row">
                                    <div class="col-12">
                                        <?php $reaction_drug = explode(",", $drug);
                                        for ($i = 0; $i < count($reaction_drug)-1; $i++) { ?>
                                            <label class="kt-radio kt-radio--bold kt-radio--success">
                                       <input type="radio"  name="reaction_medication_drug2<?php echo $i ?>" id="reaction_medication_drug2<?php echo $i ?>" checked><?php echo $reaction_drug[$i] ?>
                                    <span></span>
                                        </label><br>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>

                                <div class="col-md-6">
                                    <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">What food(s) caused the reaction Eg.(Rice, Apple)</label>
                                <div class="form-group row">
                                    <div class="col-12">
                                        <div class="col-12">
                                        <?php $reaction_food = explode(",", $food);
                                        for ($i = 0; $i < count($reaction_food)-1; $i++) { ?>
                                            <label class="kt-radio kt-radio--bold kt-radio--success">
                                       <input type="radio"  name="reaction_medicationfood2<?php echo $i ?>" id="reaction_medicationfood2<?php echo $i ?>" checked><?php echo $reaction_food[$i] ?>
                                    <span></span>
                                        </label><br>
                                        <?php } ?>
                                    </div>
                                    </div>
                                </div>
                                </div>
                        </div>

    <span id="display_if_yes" style="width:100%">

                            <div class="row">
                            <div class="col-md-6" style="width:100%">
                                <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">Describe the reaction you had (True Allergy)</label>
                                <div class="form-group row">
                                    <div class="col-12">
                                        <?php $reaction12 = explode(",", $true_allergy_description);
                                        for ($i = 0; $i < count($reaction12)-1; $i++) { ?>
                                        <label class="kt-radio kt-radio--bold kt-radio--success">
                                       <input type="radio"  name="reaction_medication<?php echo $i ?>" id="reaction_medication<?php echo $i ?>" checked><?php echo $reaction12[$i] ?>
                                    <span></span>
                                        </label><br>
                                             <?php } ?>
                                    </div>
                                </div>
                            </div>

                                <div class="col-md-6">
                                    <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">Describe the reaction you had (Side Effects)</label>
                                <div class="form-group row">
                                    <div class="col-12">
                                        <?php $reaction12 = explode(",", $adverse_effect_description);
                                        for ($i = 0; $i < count($reaction12)-1; $i++) { ?>
                                            <label class="kt-radio kt-radio--bold kt-radio--success">
                                       <input type="radio"  name="reaction_medication1<?php echo $i ?>" id="reaction_medication1<?php echo $i ?>" checked><?php echo $reaction12[$i] ?>
                                    <span></span>
                                        </label><br>
                                        <?php } ?>
                                    </div>
                                </div>
                                </div>
                        </div>


                                                        <div class="row">
                            <div class="col-md-6" style="width:100%">
                                <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">How did you take this medication</label>
                                <div class="form-group row">
                                   <div class="col-12">
                                        <?php $reaction12 = explode(",", $medication_medium);
                                        for ($i = 0; $i < count($reaction12)-1; $i++) { ?>
                                            <label class="kt-radio kt-radio--bold kt-radio--success">
                                       <input type="radio"  name="reaction_medication2<?php echo $i ?>" id="reaction_medication2<?php echo $i ?>" checked><?php echo $reaction12[$i] ?>
                                    <span></span>
                                        </label><br>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>

                                <div class="col-md-6">
                                    <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">How Soon after starting the medication did the reaction happen ?</label>
                                <div class="form-group row">
                                    <div class="col-6">
                                        <label class="kt-radio kt-radio--bold kt-radio--success">
                                       <input type="radio"  name="reaction_medication22" id="reaction_medication22" checked><?php echo $reaction_duration ?>
                                    <span></span>
                                        </label>

                                    </div>
                                </div>
                                </div>
                        </div>



                            <div class="row">
                            <div class="col-md-6" style="width:100%">
                                <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">How long ago did this reaction happen ?</label>
                                <div class="form-group row">
                                    <div class="col-12">
                                               <label class="kt-radio kt-radio--bold kt-radio--success">
                                       <input type="radio"  name="reaction_medication222" id="reaction_medication222" checked><?php if(empty($reaction_duration_ago)){echo "NOT SPECIFIED"; }else{ echo $reaction_duration_ago; } ?>
                                    <span></span>
                                        </label>
                                    </div>
                                </div>
                            </div>

                                <div class="col-md-6">
                                    <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">Did you seek medical Attention for the reaction ?</label>
                                    <?php if ($reaction_medication_status == "Yes"){ ?>
                                    <label class="kt-radio kt-radio--bold kt-radio--success">
                                            <input type="radio"  name="reaction_medical_attention" id="reaction_medical_attention" value="Yes" checked> Yes
                                            <span></span>
                                        </label>
&nbsp;&nbsp;&nbsp;                                  <?php }else{ ?>

                                    <label class="kt-radio kt-radio--bold kt-radio--danger">
                                        <input type="radio"  name="reaction_medical_attention" id="reaction_medical_attention" value="No" checked > No
                                        <span></span>
                                    </label>
                                    <?php } ?>
                                </div>
                        </div>

                            <span id="question_six_a_display" style="width:100%;">
                                 <div class="row">
                            <div class="col-md-6" style="width:100%">
                                <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">Where were you seen ?</label>
                                <div class="form-group row">
                                    <div class="col-12">
                                               <label class="kt-radio kt-radio--bold kt-radio--success">
                                       <input type="radio"  name="reaction_medication2222" id="reaction_medication2222" checked><?php if(empty($consultation_location)){echo "NOT SPECIFIED"; }else{ echo $consultation_location; } ?>
                                    <span></span>
                                        </label>
                                    </div>
                                </div>
                            </div>

                                <div class="col-md-6">
                                    <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">Was the medication stopped by a doctor ?</label>
                                <div class="form-group row">
                                    <div class="col-12">
                                          <?php if ($stopped_by_doctor == "Yes"){ ?>
                                            <label class="kt-radio kt-radio--bold kt-radio--success">
                                            <input type="radio"  name="medication_stopped" id="medication_stopped" value="Yes" checked> Yes
                                            <span></span>
                                        </label>
                                          <?php }else{ ?>   &nbsp;&nbsp;&nbsp;
                                        <label class="kt-radio kt-radio--bold kt-radio--danger">
                                            <input type="radio"  name="medication_stopped" id="medication_stopped" value="No" checked> No
                                            <span></span>
                                        </label>
                                          <?php } ?>
                                    </div>
                                </div>
                                </div>
                        </div>
                            </span>



                        <div class="row">
                            <div class="col-md-6" style="width:100%">
                                <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">Have you ever taken this medication or similar one again ?</label>
                                <div class="form-group row">
                                    <div class="col-12">
                                              <?php if ($similar_medication == "Yes"){ ?>
                                                  <label class="kt-radio kt-radio--bold kt-radio--success">
                                            <input type="radio"  name="similar_medication" id="similar_medication" value="Yes" checked> Yes
                                            <span></span>
                                        </label>
                                              <?php }else{ ?>  &nbsp;&nbsp;&nbsp;
                                                  <label class="kt-radio kt-radio--bold kt-radio--danger">
                                            <input type="radio"  name="similar_medication" id="similar_medication" value="No" checked> No
                                            <span></span>
                                        </label>
                                              <?php } ?>
                                    </div>
                                </div>
                            </div>

                                <div class="col-md-6">
                                    <label for="hirePurchase" class="col-12 col-form-label" id="bold_item">If yes, did you experience the same problem ?</label>
                                <div class="form-group row">
                                    <div class="col-12">
                                            <?php if ($same_problem == "Yes"){ ?>
                                                <label class="kt-radio kt-radio--bold kt-radio--success">
                                            <input type="radio"  name="new_problem" id="new_problem" value="Yes" checked> Yes
                                            <span></span>
                                        </label>
                                            <?php }else{ ?>    &nbsp;&nbsp;&nbsp;
                                                <label class="kt-radio kt-radio--bold kt-radio--danger">
                                            <input type="radio"  name="new_problem" id="new_problem" value="No" checked> No
                                            <span></span>
                                        </label>
                                            <?php } ?>
                                    </div>
                                </div>
                                </div>
                        </div>
                        </span>
                        </div>
                    </div>
</div>

</form>