fix location param, add occupation dummy data
This commit is contained in:
parent
ba9e386b4d
commit
7b093aefb3
@ -28,10 +28,10 @@ class Location extends Controller {
|
||||
->join("locationaddress la", "l.LocationID=la.LocationID", 'left')
|
||||
->join("valueset v", "v.VSetID=12 and v.VValue=l.loctype", 'left');
|
||||
|
||||
if($LocName != '') { $sql->like('LocFull', $LocName, 'both'); $rows[] = 'LocName'; }
|
||||
if($LocCode != '') { $sql->like('LocCode', $LocCode, 'both'); $rows[] = 'LocCode'; }
|
||||
if($LocName != '') { $sql->like('LocFull', $LocName, 'both'); }
|
||||
if($LocCode != '') { $sql->like('LocCode', $LocCode, 'both'); }
|
||||
|
||||
$rows[] = $sql->get()->getResultArray();
|
||||
$rows = $sql->get()->getResultArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
|
||||
@ -50,7 +50,7 @@ class CreateContactTable extends Migration {
|
||||
'AbbTex' => [ 'type' => 'VARCHAR', 'constraint' => 5, 'null' => true ],
|
||||
'FullText' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true ],
|
||||
'Description' => [ 'type' => 'TEXT', 'null' => true ],
|
||||
'CreateDate' => [ 'type' => 'DATETIME', 'null' => true ],
|
||||
'CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
||||
]);
|
||||
$this->forge->addKey('OccupationID', true);
|
||||
$this->forge->createTable('occupation');
|
||||
|
||||
@ -34,6 +34,11 @@ class DummySeeder extends Seeder {
|
||||
['SiteID'=>3,'ContactID'=>2, 'ContactCode'=>'C342', 'ContactEmail'=>'qdoc@email.com', 'OccupationID'=>'', 'JobTitle'=>'', 'Department'=>'Hati Sehat' ]
|
||||
];
|
||||
$this->db->table('contactdetail')->insertBatch($data);
|
||||
$data = [
|
||||
['OccupationID'=>1, 'AbbTex'=>'OC0001', 'FullText'=>'Medical Doctor', 'Description'=>'Diagnoses and treats, injuries and illnesses' ],
|
||||
['OccupationID'=>2, 'AbbTex'=>'OC0002', 'FullText'=>'Trainee Medical Technician', 'Description'=>'Performing basic laboratory task' ],
|
||||
['OccupationID'=>3, 'AbbTex'=>'OC0003', 'FullText'=>'Medical Laboratory Technician', 'Description'=>'Perform routine laboratory tests' ]
|
||||
];
|
||||
|
||||
// patient
|
||||
$data = [
|
||||
|
||||
113
app/Models/OccupationModel.php
Normal file
113
app/Models/OccupationModel.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ContactModel extends Model {
|
||||
protected $table = 'occupation';
|
||||
protected $primaryKey = 'OccupationID';
|
||||
protected $allowedFields = ['AbbTex', 'FullText', 'Description'];
|
||||
|
||||
public function getContactsWithDetail() {
|
||||
$rows = $this->select("contact.ContactID, cd.SiteID, cd.ContactCode, NameFirst, NameLast, Specialty")
|
||||
->join("contactdetail cd", "contact.ContactID=cd.ContactID", "left")
|
||||
->join("occupation o","cd.OccupationID=o.OccupationID", "left")
|
||||
->get()->getResultArray();
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function getContacts($ContactName, $Specialty) {
|
||||
$sql = $this->select("ContactID, NameFirst, NameLast, Title, Initial, Specialty");
|
||||
if($ContactName !='') { $sql->like('NameFirst',$ContactName,'both')->orLike('NameLast',$ContactName,'both'); }
|
||||
if($Specialty != '') { $sql->like('Specialty',$Specialty); }
|
||||
$rows = $sql->get()->getResultArray();
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function getContactWithDetail($ContactID) {
|
||||
$rows = $this->where('contact.ContactID', $ContactID)->join('contactdetail cd', 'contact.ContactID=cd.ContactID','left')->get()->getResultArray();
|
||||
$contact = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if(empty($contact['NameFirst'])) {
|
||||
$contact = [
|
||||
'ContactID' => $ContactID,
|
||||
'NameFirst' => $row['NameFirst'] ?? null,
|
||||
'NameLast' => $row['NameLast'] ?? null,
|
||||
'Title' => $row['Title'] ?? null,
|
||||
'Initial' => $row['Initial'] ?? null,
|
||||
'Birthdate' => $row['Birthdate'] ?? null,
|
||||
'EmailAddress1' => $row['EmailAddress1'] ?? null,
|
||||
'EmailAddress2' => $row['EmailAddress2'] ?? null,
|
||||
'Phone' => $row['Phone'] ?? null,
|
||||
'MobilePhone1' => $row['MobilePhone1'] ?? null,
|
||||
'MobilePhone2' => $row['MobilePhone2'] ?? null,
|
||||
'Specialty' => $row['Specialty'] ?? null,
|
||||
'SubSpecialty' => $row['SubSpecialty'] ?? null,
|
||||
'Details' => []
|
||||
];
|
||||
}
|
||||
if (!empty($row['ContactDetID'])) {
|
||||
$contact['Details'][] = [
|
||||
'SiteID' => $row['SiteID'] ?? null,
|
||||
'ContactDetID' => $row['ContactDetID'],
|
||||
'ContactCode' => $row['ContactCode'] ?? null,
|
||||
'ContactEmail' => $row['ContactEmail'] ?? null,
|
||||
'OccupationID' => $row['OccupationID'] ?? null,
|
||||
'JobTitle' => $row['JobTitle'] ?? null,
|
||||
'Department' => $row['Department'] ?? null,
|
||||
'ContactStartDate' => $row['ContactStartDate'] ?? null,
|
||||
'ContactEndDate' => $row['ContactEndDate'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $contact;
|
||||
}
|
||||
|
||||
public function saveWithDetails(array $data): array {
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
|
||||
try {
|
||||
if (!empty($data['ContactID'])) {
|
||||
$contactId = $data['ContactID'];
|
||||
$this->update($contactId, $data);
|
||||
} else {
|
||||
$contactId = $this->insert($data, true);
|
||||
}
|
||||
|
||||
if (!$contactId) {
|
||||
throw new \RuntimeException('Failed to save contact');
|
||||
}
|
||||
|
||||
if (!empty($data['Details'])) {
|
||||
$detailModel = new \App\Models\ContactDetailModel();
|
||||
$result = $detailModel->syncDetails($contactId, $data['Details']);
|
||||
|
||||
if ($result['status'] !== 'success') {
|
||||
throw new \RuntimeException('SyncDetails failed: ' . $result['message']);
|
||||
}
|
||||
}
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'ContactID' => $contactId,
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
$db->transRollback();
|
||||
|
||||
log_message('error', 'saveWithDetails error: ' . $e->getMessage());
|
||||
|
||||
return [
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user