<?php

// info from patient chart
$drugs = \App\Models\Point::getPointsOfCategory($patient, "MEDICATION");

// filter out drugs without fdb info on them
$drugs = $drugs->filter(function ($_drug) {
    return @$_drug->data &&
        $_drug->data->name &&
        $_drug->data->medId &&
        $_drug->data->routedMedId &&
        $_drug->data->routedDosageFormMedId &&
        $_drug->data->gcnSeqno;
});

// get pivot drug
$pivotDx = json_decode(json_encode([
    "data" => [
        "name" => request()->input('name'),
        "dxid" => request()->input('dxid'),
    ]
]));

// contraindications
// TODO: check against patient's dx
$contraindications = contraindications_info($drugs, [$pivotDx]);

?>

@if(count($contraindications))
    <div class="p-3 mb-3 border bg-white mr-0">
        <p class="font-weight-bold m-0 font-size-14 text-info">Contraindications</p>
        @foreach($contraindications as $drug => $contraindication)
            <div class="mt-3">
                <p class="font-weight-bold mb-2">{{$drug}}</p>
                <div class="flex-grow-1 d-inline-flex flex-wrap">
                    @foreach($contraindication as $ci)
                        <span class="mr-2 px-2 py-0 border bg-light mb-1 {{@$ci['flag'] ? 'text-danger border-danger' : ''}}">{{$ci['dxid_desc56']}}</span>
                    @endforeach
                </div>
            </div>
        @endforeach
    </div>
@endif

