const nome = _req.getString("nome");
|
|
const cpf = _req.getString("cpf");
|
|
const campos = _req.getString("campos").split(",");
|
|
|
|
const dbPacientes = _db.query(`
|
|
SELECT id, uid, nome, c_p_f, data_de_nascimento, endereco, telefone
|
|
FROM paciente
|
|
WHERE nome LIKE ? AND c_p_f LIKE ?
|
|
`,
|
|
`%${nome}%`,
|
|
`%${cpf}%`
|
|
);
|
|
|
|
const lista = _val.list();
|
|
|
|
for (const dbPaciente of dbPacientes) {
|
|
const paciente = _val.map()
|
|
.set("uid", dbPaciente.getUID("uid"))
|
|
.set("nome", dbPaciente.getString("nome"))
|
|
.set("cpf", dbPaciente.getString("c_p_f"))
|
|
.set("data de nascimento", dbPaciente.getSQLDate("data_de_nascimento"))
|
|
.set("endereço", dbPaciente.getString("endereco"))
|
|
.set("telefone", dbPaciente.getString("telefone"));
|
|
|
|
const paciente_id = dbPaciente.getInt("id");
|
|
|
|
if (campos.includes("convenios")) {
|
|
const dbPacienteConvenios = _db.form("paciente_convenio")
|
|
.where(_db.where("paciente_id").equal(paciente_id))
|
|
.link("convenio")
|
|
.get("convenio.uid", "convenio_uid")
|
|
.all();
|
|
|
|
const convenios = [];
|
|
for (dbPacienteConvenio of dbPacienteConvenios) {
|
|
convenios.push(dbPacienteConvenio.getUID("convenio_uid"));
|
|
}
|
|
|
|
paciente.set("convenios", convenios);
|
|
}
|
|
|
|
lista.add(paciente);
|
|
}
|
|
|
|
_out.json(lista);
|