Merge branch 'main' of https://github.com/mahdahar/clqms-be
This commit is contained in:
commit
d28bb3cd4b
@ -47,7 +47,19 @@ $routes->get('/api/location', 'Location::index');
|
||||
$routes->get('/api/location/(:num)', 'Location::show/$1');
|
||||
$routes->post('/api/location', 'Location::create');
|
||||
$routes->patch('/api/location', 'Location::update');
|
||||
$routes->delete('/api/location', 'Patient::delete');
|
||||
$routes->delete('/api/location', 'Location::delete');
|
||||
|
||||
$routes->get('/api/contact', 'Contact::index');
|
||||
$routes->get('/api/contact/(:num)', 'Contact::show/$1');
|
||||
$routes->post('/api/contact', 'Contact::create');
|
||||
$routes->patch('/api/contact', 'Contact::update');
|
||||
$routes->delete('/api/contact', 'Contact::delete');
|
||||
|
||||
$routes->get('/api/occupation', 'Occupation::index');
|
||||
$routes->get('/api/occupation/(:num)', 'Occupation::show/$1');
|
||||
$routes->post('/api/occupation', 'Occupation::create');
|
||||
$routes->patch('/api/occupation', 'Occupation::update');
|
||||
//$routes->delete('/api/occupation', 'Occupation::delete');
|
||||
|
||||
$routes->get('/api/valueset', 'ValueSet::index');
|
||||
$routes->get('/api/valueset/(:num)', 'ValueSet::show/$1');
|
||||
|
||||
@ -16,17 +16,17 @@ class Contact extends Controller {
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$rows = $this->db->table('contact')
|
||||
->select("contact.*, contactdetail.ContactEmail, contactdetail.JobTitle, contactdetail.Department, occupation.AbbTex, occupation.FullText, occupation.Description")
|
||||
->join("contactdetail", "contact.ContactID=contactdetail.ContactID")
|
||||
->join("occupation","occupation.OccupationID=contactdetail.OccupationID")
|
||||
->get()->getRowArray();
|
||||
$sql = $this->db->table('contact');
|
||||
$sql->select("*")
|
||||
->join("contactdetail", "contact.ContactID=contactdetail.ContactID", "left")
|
||||
->join("occupation","contactdetail.OccupationID=occupation.OccupationID", "left");
|
||||
$rows = $sql->get()->getRowArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "no Data.",
|
||||
'data' => [],
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
}
|
||||
|
||||
@ -38,10 +38,10 @@ class Contact extends Controller {
|
||||
}
|
||||
|
||||
public function show($ContactID = null) {
|
||||
$row=$this->db->table('contact')
|
||||
->select("contact.*, contactdetail.ContactEmail, contactdetail.JobTitle, contactdetail.Department, occupation.AbbTex, occupation.FullText, occupation.Description")
|
||||
->join("contactdetail", "contact.ContactID=contactdetail.ContactID")
|
||||
->join("occupation","occupation.OccupationID=contactdetail.OccupationID")
|
||||
$rows=$this->db->table('contact')
|
||||
->select("*")
|
||||
->join("contactdetail", "contact.ContactID=contactdetail.ContactID", "left")
|
||||
->join("occupation","occupation.OccupationID=contactdetail.OccupationID", "left")
|
||||
->where('contact.ContactID', (int) $ContactID)
|
||||
->get()->getRowArray();
|
||||
|
||||
@ -65,40 +65,38 @@ class Contact extends Controller {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
// Prepare data
|
||||
$dataLocation = $this->prepareLocationData($input);
|
||||
$dataLocationAddress = $this->prepareLocationAddressData($input);
|
||||
$dataContact = $this->prepareContactData($input);
|
||||
$dataContactDetail = $this->prepareContactDetailData($input);
|
||||
|
||||
if (!$this->validateData($dataLocation, $this->rules)) {
|
||||
if (!$this->validateData($dataContact, $this->rulesContact)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
// Start transaction
|
||||
$this->db->transStart();
|
||||
$this->db->table('contact')->insert($dataContact);
|
||||
$newContactID = $this->db->insertID();
|
||||
|
||||
// Insert location
|
||||
$this->db->table('location')->insert($dataLocation);
|
||||
$newLocationID = $this->db->insertID();
|
||||
|
||||
// Insert address if available
|
||||
if (!empty($dataLocationAddress)) {
|
||||
$dataLocationAddress['LocationID'] = $newLocationID;
|
||||
$this->db->table('locationaddress')->insert($dataLocationAddress);
|
||||
|
||||
if (!empty($dataContactDetail)) {
|
||||
$dataContactDetail['ContactID'] = $newContactID;
|
||||
$this->db->table('contactdetail')->insert($dataContactDetail);
|
||||
}
|
||||
|
||||
// Complete transaction
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError(
|
||||
'Failed to create location data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
|
||||
'Failed to create data (transaction rolled back): ' . ( $dbError['message'] ?? 'Unknown database error')
|
||||
);
|
||||
}
|
||||
|
||||
// Complete transaction
|
||||
$this->db->transComplete();
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Location created successfully',
|
||||
'data' => $dataLocation,
|
||||
'message' => 'Contact created successfully',
|
||||
'data' => $dataContact,
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
@ -115,23 +113,22 @@ class Contact extends Controller {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
// Prepare data
|
||||
$dataLocation = $this->prepareLocationData($input);
|
||||
$dataLocationAddress = $this->prepareLocationAddressData($input);
|
||||
$dataContact = $this->prepareContactData($input);
|
||||
$dataContactDetail = $this->prepareContactDetailData($input);
|
||||
|
||||
if (!$this->validateData($dataLocation, $this->rules)) {
|
||||
if (!$this->validateData($dataContact, $this->rulesContact)) {
|
||||
return $this->failValidationErrors( $this->validator->getErrors());
|
||||
}
|
||||
|
||||
// Start transaction
|
||||
$this->db->transStart();
|
||||
|
||||
// Insert location
|
||||
$this->db->table('location')->where('LocationID', $dataLocation["LocationID"])->update($dataLocation);
|
||||
$this->db->table('contact')->where('ContactID', $dataContact["ContactID"])->update($dataContact);
|
||||
|
||||
// Insert address if available
|
||||
if (!empty($dataLocationAddress)) {
|
||||
$dataLocationAddress['LocationID'] = $input["LocationID"];
|
||||
$this->db->table('locationaddress')->upsert($dataLocationAddress);
|
||||
if (!empty($dataContactDetail)) {
|
||||
$dataContactDetail['ContactID'] = $input["ContactID"];
|
||||
$this->db->table('contactdetail')->upsert($dataContactDetail);
|
||||
}
|
||||
|
||||
// Complete transaction
|
||||
@ -140,14 +137,14 @@ class Contact extends Controller {
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError(
|
||||
'Failed to update location data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
|
||||
'Failed to update contact data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Location updated successfully',
|
||||
'data' => $dataLocation,
|
||||
'message' => 'Contact updated successfully',
|
||||
'data' => $dataContact,
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
@ -162,22 +159,21 @@ class Contact extends Controller {
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$LocationID = $input["LocationID"];
|
||||
if (!$LocationID) {
|
||||
return $this->failValidationError('LocationID is required.');
|
||||
$ContactID = $input["ContactID"];
|
||||
if (!$ContactID) {
|
||||
return $this->failValidationError('ContactID is required.');
|
||||
}
|
||||
|
||||
|
||||
$location = $this->db->table('location')->where('LocationID', $LocationID)->get()->getRow();
|
||||
if (!$location) {
|
||||
return $this->failNotFound("LocationID with {$LocationID} not found.");
|
||||
$contact = $this->db->table('contact')->where('ContactID', $ContactID)->get()->getRow();
|
||||
if (!$contact) {
|
||||
return $this->failNotFound("data with {$ContactID} not found.");
|
||||
}
|
||||
|
||||
$this->db->table('location')->where('LocationID', $LocationID)->update(['DelDate' => NOW()]);
|
||||
$this->db->table('contact')->where('ContactID', $ContactID)->update(['EndDate' => NOW()]);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => "Location with {$LocationID} deleted successfully."
|
||||
'message' => "Contact with {$ContactID} deleted successfully."
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
@ -189,35 +185,36 @@ class Contact extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareLocationData(array $input): array {
|
||||
$LinkTo = null;
|
||||
if (!empty($input['LinkTo'])) {
|
||||
$ids = array_column($input['LinkTo'], 'InternalPID');
|
||||
$LinkTo = implode(',', $ids);
|
||||
}
|
||||
|
||||
private function prepareContactData(array $input): array {
|
||||
$data = [
|
||||
"LocCode" => $input['LocCode'] ?? null,
|
||||
"Parent" => $input['Parent'] ?? null,
|
||||
"LocFull" => $input['LocFull'] ?? null,
|
||||
"Description" => $input['Description'] ?? null,
|
||||
"NameFirst" => $input['NameFirst'] ?? null,
|
||||
"NameLast" => $input['NameLast'] ?? null,
|
||||
"Title" => $input['Title'] ?? null,
|
||||
"Initial" => $input['Initial'] ?? null,
|
||||
"Birthdate" => $input['Birthdate'] ?? null,
|
||||
"EmailAddress1" => $input['EmailAddress1'] ?? null,
|
||||
"EmailAddress2" => $input['EmailAddress2'] ?? null,
|
||||
"Phone" => $input["Phone"] ?? null,
|
||||
"MobilePhone1" => $input["MobilePhone1"] ?? null,
|
||||
"MobilePhone2" => $input["MobilePhone2"] ?? null,
|
||||
"Specialty" => $input["Specialty"] ?? null,
|
||||
"SubSpecialty" => $input["SubSpecialty"] ?? null,
|
||||
];
|
||||
|
||||
if(!empty($input["LocationID"])) { $data["LocationID"] = $input["LocationID"]; }
|
||||
if(!empty($input["ContactID"])) { $data["ContactID"] = $input["ContactID"]; }
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function prepareLocationAddressData(array $input): array {
|
||||
private function prepareContactDetailData(array $input): array {
|
||||
$data = [
|
||||
"LocationID" => $input['LocationID'] ?? null,
|
||||
"Street1" => $input['Street1'] ?? null,
|
||||
"Street2" => $input['Street2'] ?? null,
|
||||
"City" => $input['City'] ?? null,
|
||||
"Province" => $input['Province'] ?? null,
|
||||
"PostCode" => $input['PostCode'] ?? null,
|
||||
"GeoLocationSystem" => $input['GeoLocationSystem'] ?? null,
|
||||
"GeoLocationData" => $input['GeoLocationData'] ?? null,
|
||||
"Code" => $input['Code'] ?? null,
|
||||
"ContactEmail" => $input['ContactEmail'] ?? null,
|
||||
"OccupationID" => $input['OccupationID'] ?? null,
|
||||
"JobTitle" => $input['JobTitle'] ?? null,
|
||||
"Department" => $input['Department'] ?? null,
|
||||
"ContactStartDate" => $input['ContactStartDate'] ?? null,
|
||||
"ContactEndDate" => $input['ContactEndDate'] ?? null,
|
||||
];
|
||||
|
||||
return $data;
|
||||
|
||||
169
app/Controllers/Occupation.php
Normal file
169
app/Controllers/Occupation.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\Database\RawSql;
|
||||
|
||||
class Occupation extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->rulesOccupation = [
|
||||
'AbbTex' => 'required',
|
||||
'FullText' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$rows = $this->db->table('occupation')->select("*")->get()->getRowArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "no Data.",
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message'=> "fetch success",
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function show($OccupationID = null) {
|
||||
$rows=$this->db->table('occupation')->select("*")->where('occupationID', (int) $OccupationID)->get()->getRowArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "Data not found.",
|
||||
'data' => [],
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message'=> "Data fetched successfully",
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$dataOccupation = $this->prepareOccupationData($input);
|
||||
|
||||
if (!$this->validateData($dataOccupation, $this->rulesOccupation)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
$this->db->table('contact')->insert($dataOccupation);
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError(
|
||||
'Failed to create data (transaction rolled back): ' . ( $dbError['message'] ?? 'Unknown database error')
|
||||
);
|
||||
}
|
||||
|
||||
// Complete transaction
|
||||
$this->db->transComplete();
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'data created successfully',
|
||||
'data' => $dataOccupation,
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Ensure rollback if something goes wrong
|
||||
if ($this->db->transStatus() !== false) {
|
||||
$this->db->transRollback();
|
||||
}
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$dataOccupation = $this->prepareOccupationData($input);
|
||||
|
||||
if (!$this->validateData($dataOccupation, $this->rulesOccupation)) {
|
||||
return $this->failValidationErrors( $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
$this->db->table('occupation')->where('OccupationID', $dataOccupation["OccupationID"])->update($dataOccupation);
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError(
|
||||
'Failed to update data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
|
||||
);
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Occupation updated successfully',
|
||||
'data' => $dataContact,
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Ensure rollback if something goes wrong
|
||||
if ($this->db->transStatus() !== false) {
|
||||
$this->db->transRollback();
|
||||
}
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
/*
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$OccupationID = $input["OccupationID"];
|
||||
if (!$OccupationID) {
|
||||
return $this->failValidationError('ContactID is required.');
|
||||
}
|
||||
|
||||
$occupation = $this->db->table('occupation')->where('OccupationID', $OccupationID)->get()->getRow();
|
||||
if (!$occupation) {
|
||||
return $this->failNotFound("data with {$OccupationID} not found.");
|
||||
}
|
||||
|
||||
$this->db->table('occupation')->where('OccupationID', $OccupationID)->update(['EndDate' => NOW()]);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => "{$ContactID} deleted successfully."
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Ensure rollback if something goes wrong
|
||||
if ($this->db->transStatus() !== false) {
|
||||
$this->db->transRollback();
|
||||
}
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private function prepareOccupationData(array $input): array {
|
||||
$data = [
|
||||
"AbbTex" => $input['AbbTex'] ?? null,
|
||||
"FullText" => $input['FullText'] ?? null,
|
||||
"Description" => $input['Description'] ?? null,
|
||||
];
|
||||
|
||||
if(!empty($input["OccupationID"])) { $data["OccupationID"] = $input["OccupationID"]; }
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@ -17,9 +17,13 @@ class ValueSet extends Controller {
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$rows = $this->db->table('valueset')
|
||||
->select("*")
|
||||
->get()->getResultArray();
|
||||
$builder = $this->db->table('valueset')->select("*");
|
||||
$param = $this->request->getVar('param');
|
||||
if ($param !== null) {
|
||||
$builder->like('VValue', $param, 'both');
|
||||
$builder->orlike('VDesc', $param, 'both');
|
||||
}
|
||||
$rows = $builder->get()->getResultArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
@ -38,8 +42,9 @@ class ValueSet extends Controller {
|
||||
|
||||
public function show($VID = null) {
|
||||
$rows = $this->db->table('valueset')
|
||||
->select("*")
|
||||
->where('VID', (int) $VID)
|
||||
->select("valueset.*, valuesetdef.VSName")
|
||||
->join('valuesetdef', 'valuesetdef.VSetID = valueset.VSetID', 'LEFT')
|
||||
->where('valueset.VID', (int) $VID)
|
||||
->get()->getResultArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
|
||||
@ -17,10 +17,14 @@ class ValueSetDef extends Controller {
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$rows = $this->db->table('valuesetdef')
|
||||
->select("*")
|
||||
->get()->getResultArray();
|
||||
|
||||
$builder = $this->db->table('valuesetdef')->select("*");
|
||||
$param = $this->request->getVar('param');
|
||||
if ($param !== null) {
|
||||
$builder->like('VSName', $param, 'both');
|
||||
$builder->orlike('VSDesc', $param, 'both');
|
||||
}
|
||||
$rows = $builder->get()->getResultArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
|
||||
@ -8,7 +8,7 @@ class CreateContactTable extends Migration {
|
||||
public function up() {
|
||||
// Contact
|
||||
$this->forge->addField([
|
||||
'ContactID' => [ 'type' => 'INT', 'constraint' => 11 ],
|
||||
'ContactID' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true ],
|
||||
'NameFirst' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
|
||||
'NameLast' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
|
||||
'Title' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
|
||||
@ -32,6 +32,7 @@ class CreateContactTable extends Migration {
|
||||
'ContactDetID' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true ],
|
||||
'ContactID' => [ 'type' => 'INT', 'constraint' => 11 ],
|
||||
'SiteID' => [ 'type' => 'INT', 'constraint' => 11, 'null' => true ],
|
||||
'Code' => [ 'type' => 'varchar', 'constraint' => 11, 'null' => false ],
|
||||
'ContactEmail' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ],
|
||||
'OccupationID' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
|
||||
'JobTitle' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
|
||||
|
||||
BIN
public/clqms01.sql.gz
Normal file
BIN
public/clqms01.sql.gz
Normal file
Binary file not shown.
BIN
public/upload/meow.jpg
Normal file
BIN
public/upload/meow.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
BIN
public/upload/panda.jpg
Normal file
BIN
public/upload/panda.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Loading…
x
Reference in New Issue
Block a user