I am making a system for my pharmacy: prescription drug dispensing.
I made the table patients (id, name, cpf, phone, address, photo_document), dispensing (patient_id, medication_id, quantity, crm, date_receita, ) and medicines (id, medicine, laboratory).
Only when I make the listing, I wanted all the same prescription drugs, for the same patient, with the same CRM, on the same date of prescription and dispensing.
<?php
header('Access-Control-Allow-Origin: *');
include 'init.php';
$sql = "SELECT *, pacientes.id AS id_pac FROM pacientes INNER JOIN dispensacao ON pacientes.id = dispensacao.id_paciente INNER JOIN medicamentos ON medicamentos.id = dispensacao.id_medicamento ORDER BY nome";
$query = $mysqli->query($sql);
while($ln = $query->fetch_array()){
$id_pac = $ln['id_pac'];
$nome_pac = $ln['nome'];
$cpf = $ln['cpf'];
$tel = $ln['telefone'];
$end = $ln['endereco'];
$imgdocumento = $ln['documento'];
$crm = $ln['crm'];
$data_receita = $ln['data_receita'];
$data_dispensacao = $ln['data_dispensacao'];
$imgreceita = $ln['receita'];
$nome_medic = $ln['medicamento'];
$qnt = $ln['quantidade'];
echo '<li class="accordion-item"><a href="#" class="item-content item-link">
<div class="item-inner">
<div class="item-title"><i class="icon f7-icons size-22">person</i> '.$nome_pac.'</div>
</div></a>
<div class="accordion-item-content">
<div class="content-block">
<p><hr></p>
<div class="row" style="margin-bottom: 15px">
<div class="col-50"><i class="icon f7-icons size-16">sort</i> <b>CPF</b></div>
<div class="col-50">'.$cpf.'</div>
</div>
<div class="row" style="margin-bottom: 15px">
<div class="col-50"><i class="icon f7-icons size-16">phone</i> <b>Telefone</b></div>
<div class="col-50">'.$tel.'</div>
</div>
<div class="row" style="margin-bottom: 15px">
<div class="col-50"><i class="icon f7-icons size-16">compose</i> <b>Endereço</b></div>
<div class="col-50">'.$end.'</div>
</div>
<div class="row" style="margin-bottom: 15px">
<div class="col-50"><i class="icon f7-icons size-16">today</i> <b>Data da Receita</b></div>
<div class="col-50"><a href="#" class="data-vencimento">'.date('d/m/Y', strtotime($data_receita)).'</a></div>
</div>
<div class="row" style="margin-bottom: 15px">
<div class="col-50"><i class="icon f7-icons size-16">today_fill</i> <b>Data da Dispensação</b></div>
<div class="col-50">'.date('d/m/Y', strtotime($data_dispensacao)).'</div>
</div>
<div class="row" style="margin-bottom: 15px">
<div class="col-50"><i class="icon f7-icons size-16">card</i> <b>CRM</b></div>
<div class="col-50">'.$crm.'</div>
</div>
<div class="row" style="margin-bottom: 15px">
<div class="col-50"><i class="icon f7-icons size-16">list</i> <b>Medicamentos Dispensados</b></div>
<div class="col-50">
<div class="data-table card centralized">
<table>
<thead>
<tr>
<th class="label-cell">Medicamento</th>
<th class="numeric-cell">Quantidade</th>
</tr>
</thead>
<tbody id="list_med">';
<tr>
<td class="label-cell">'.$nome_med.'</td>
<td class="numeric-cell">'.$qnt.'</td>
</tr>
echo '</tbody>
</table>
</div>
</div>
</div>
<div class="row" style="margin-bottom: 15px">
<div class="col-50"><i class="icon f7-icons size-16">images</i> <b>Receita</b></div>
<div class="col-50"><img src="receitas/'.$imgreceita.'" width="50" height="50"></div>
</div>
<div class="row" style="margin-bottom: 15px">
<div class="col-50"><i class="icon f7-icons size-16">images_fill</i> <b>Documento</b></div>
<div class="col-50"><img src="receitas/'.$imgdocumento.'" width="50" height="50"></div>
</div>';
}
I'm not finding a solution to my listing. Can anyone help me?
Results so far: www.blocodochapolin.com.br/FP_novo/pacientes.php
The result I want to get here is this: link
Patient List
Ex: A patient can have several recipes, and each recipe would be a list with the drugs of this recipe (dispensation).