Fix patient creation error: extract nested arrays before insert
- Extract PatIdt, PatCom, PatAtt arrays before patient insert to prevent MySQL error 1241 - Fix Custodian handling when InternalPID is null - Apply same fix to updatePatient method
This commit is contained in:
parent
a9384fbe96
commit
64646293dc
@ -119,9 +119,20 @@ class PatientModel extends BaseModel {
|
||||
$modelPatCom = new PatComModel();
|
||||
$modelPatIdt = new PatIdtModel();
|
||||
|
||||
// Extract nested data before filtering
|
||||
$patIdt = $input['PatIdt'] ?? null;
|
||||
$patCom = $input['PatCom'] ?? null;
|
||||
$patAtt = $input['PatAtt'] ?? null;
|
||||
|
||||
// Remove nested arrays that don't belong to patient table
|
||||
unset($input['PatIdt'], $input['PatCom'], $input['PatAtt']);
|
||||
|
||||
if (!empty($input['Custodian'])) {
|
||||
if (is_array($input['Custodian']) && isset($input['Custodian']['InternalPID'])) {
|
||||
$input['Custodian'] = (int) $input['Custodian']['InternalPID'];
|
||||
if (is_array($input['Custodian'])) {
|
||||
$input['Custodian'] = $input['Custodian']['InternalPID'] ?? null;
|
||||
if ($input['Custodian'] !== null) {
|
||||
$input['Custodian'] = (int) $input['Custodian'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,23 +145,22 @@ class PatientModel extends BaseModel {
|
||||
$db->transBegin();
|
||||
|
||||
try {
|
||||
|
||||
$this->insert($input);
|
||||
$newInternalPID = $this->getInsertID();
|
||||
$this->checkDbError($db, 'Insert patient');
|
||||
|
||||
if (!empty($input['PatIdt'])) {
|
||||
$modelPatIdt->createPatIdt($input['PatIdt'], $newInternalPID);
|
||||
if (!empty($patIdt)) {
|
||||
$modelPatIdt->createPatIdt($patIdt, $newInternalPID);
|
||||
$this->checkDbError($db, 'Insert PatIdt');
|
||||
}
|
||||
|
||||
if (!empty($input['PatCom'])) {
|
||||
$modelPatCom->createPatCom($input['PatCom'], $newInternalPID);
|
||||
if (!empty($patCom)) {
|
||||
$modelPatCom->createPatCom($patCom, $newInternalPID);
|
||||
$this->checkDbError($db, 'Insert PatCom');
|
||||
}
|
||||
|
||||
if (!empty($input['PatAtt'])) {
|
||||
$modelPatAtt->createPatAtt($input['PatAtt'], $newInternalPID);
|
||||
if (!empty($patAtt)) {
|
||||
$modelPatAtt->createPatAtt($patAtt, $newInternalPID);
|
||||
$this->checkDbError($db, 'Insert PatAtt');
|
||||
}
|
||||
|
||||
@ -171,8 +181,11 @@ class PatientModel extends BaseModel {
|
||||
$modelPatAtt = new PatAttModel();
|
||||
|
||||
if (!empty($input['Custodian'])) {
|
||||
if (is_array($input['Custodian']) && isset($input['Custodian']['InternalPID'])) {
|
||||
$input['Custodian'] = (int) $input['Custodian']['InternalPID'];
|
||||
if (is_array($input['Custodian'])) {
|
||||
$input['Custodian'] = $input['Custodian']['InternalPID'] ?? null;
|
||||
if ($input['Custodian'] !== null) {
|
||||
$input['Custodian'] = (int) $input['Custodian'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user