0
I’m making a system for my pharmacy: dispensing prescription-controlled drugs.
I made the table patients (id, name, Cpf, telephone, address, photo_document), dispensation (id_patient, id_medicament, quantity, crm, dat_prescription, dat_dispensation, photo_prescription) and medicines (id, medicine, laboratory).
Just who when I’m going to do the listing, would want all medications of the same prescription, 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 for my listing. Can someone help me?
Result so far: www.blocodochapolin.com.br/Fp_new/patients.php
The result I want to reach would be this: http://blocodochapolin.com.br/FP_novo/
Patient list
Ex: a patient may have multiple prescriptions, and each prescription would be a list of the medications in that prescription (dispensing).
Listen, I don’t quite understand the question, especially about the term dispensation. Anyway, what I understand is that you want the listing to show the list of medicines for each dispensation of this link? If so, you can make the medicine table Join in the sql shown, to recover the name of it
– Isaias Lima
This way I told you you’ll have the same patient and dispensing information being repeated for each medicine, so you’ll have to group it later. If that’s the case, just say the word and I’ll answer the question
– Isaias Lima
Dispensation is the technical term of selling the remedy to a person. How would this grouping?
– Guilherme Lirio
Oops, I just saw that the medicine table is already on Join
– Isaias Lima
Yes, but look at the result: it shows the same patient 2x, and the drugs 2x. Wanted me to show the patient, and the medications dispensed to him in the same consultation.
– Guilherme Lirio