|
|
|
@ -4,6 +4,7 @@ const cpf = _req.getString("cpf") |
|
|
|
const data_de_nascimento = _req.getString("data_de_nascimento") |
|
|
|
const endereco = _req.getString("endereco") |
|
|
|
const telefone = _req.getString("telefone") |
|
|
|
const convenios = _req.getList("convenios"); |
|
|
|
|
|
|
|
const dbPaciente = _db.form('paciente') |
|
|
|
.where(_db.where('c_p_f').equal(cpf).or('r_g').equal(rg)) |
|
|
|
@ -15,6 +16,18 @@ if (dbPaciente) { |
|
|
|
_exec.stop(); |
|
|
|
} |
|
|
|
|
|
|
|
for (const convenio_uid of convenios) { |
|
|
|
const dbConvenio = _db.form('convenio') |
|
|
|
.where(_db.where('uid').equal(convenio_uid)) |
|
|
|
.first(); |
|
|
|
|
|
|
|
if (!dbConvenio) { |
|
|
|
_header.status(404); |
|
|
|
_out.json({result: false, error: true, reason: 'convenio-não-encontrado'}); |
|
|
|
_exec.stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const insertedData = _db.insertIfNotExists( |
|
|
|
'paciente', |
|
|
|
_val.map() |
|
|
|
@ -26,4 +39,21 @@ const insertedData = _db.insertIfNotExists( |
|
|
|
.set("telefone", telefone) |
|
|
|
); |
|
|
|
|
|
|
|
const paciente_id = _db.form('paciente') |
|
|
|
.where(_db.where('c_p_f').equal(cpf)) |
|
|
|
.first() |
|
|
|
.get('id'); |
|
|
|
|
|
|
|
for (const convenio_uid of convenios) { |
|
|
|
const convenio_id = _db.form('convenio') |
|
|
|
.where(_db.where('uid').equal(convenio_uid)) |
|
|
|
.first() |
|
|
|
.get('id'); |
|
|
|
|
|
|
|
_db.insertIfNotExists( |
|
|
|
'paciente_convenio', |
|
|
|
{ paciente_id, convenio_id } |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
_out.json({insertedData}) |