diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 83da432..2d3b873 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -66,7 +66,8 @@ $routes->get('api/dictChapters/detail/(:any)', 'API_DictChapters::detail/$1'); $routes->POST('api/orders/index', 'API_HISOrders::index'); $routes->POST('api/orders/save', 'API_HISOrders::save'); $routes->get('api/orders/detail/(:any)', 'API_HISOrders::detail/$1'); -$routes->get('api/patients/search/(:any)', 'API_HISPatients::search/$1'); +$routes->get('api/patients/patnumberSearch/(:any)', 'API_HISPatients::patnumberSearch/$1'); +$routes->POST('api/patients/search/', 'API_HISPatients::search'); $routes->get('api/patients/detail/(:any)', 'API_HISPatients::detail/$1'); $routes->POST('api/patients/save', 'API_HISPatients::save'); diff --git a/app/Controllers/API_HISPatients.php b/app/Controllers/API_HISPatients.php index c06cba7..2d3029f 100644 --- a/app/Controllers/API_HISPatients.php +++ b/app/Controllers/API_HISPatients.php @@ -24,7 +24,7 @@ class API_HISPatients extends ResourceController { return $this->respond($data,200); } - public function search($patnumber) { + public function patnumberSearch($patnumber) { $db = \Config\Database::connect(); $sql = "select * from cmod.dbo.CM_HIS_PATIENTS where PATNUMBER like '%$patnumber%'"; $query = $db->query($sql); @@ -33,9 +33,32 @@ class API_HISPatients extends ResourceController { return $this->respond($data,200); } - public function detail($patnumber) { + public function search() { $db = \Config\Database::connect(); - $sql = "select * from cmod.dbo.CM_HIS_PATIENTS where PATNUMBER='$patnumber'"; + $patnumber = $this->request->getPost('patnumber'); + $patname = strtolower( $this->request->getPost('patname') ); + $sql = "select * from cmod.dbo.CM_HIS_PATIENTS"; + // Initialize a WHERE clause + $where= ''; + if (!empty($patnumber) || !empty($patname)) { + $where= ' WHERE '; + if (!empty($patnumber)) { $where .= "PATNUMBER like '%$patnumber%'"; } + if (!empty($shorttext)) { + if (!empty($testcode)) { $where .= ' OR '; } + $where .= "LOWER(PATNAME) LIKE '%$patname%'"; + } + } + $sql .= $where; + $query = $db->query($sql); + $results = $query->getResultArray(); + $data['patients'] = $results; + + return $this->respond($data, 200); + } + + public function detail($patid) { + $db = \Config\Database::connect(); + $sql = "select * from cmod.dbo.CM_HIS_PATIENTS where PATID='$patid'"; $query = $db->query($sql); $results = $query->getResultArray(); $data['patient'] = $results[0]; diff --git a/app/Views/orders_update.php b/app/Views/orders_update.php index c38ec90..0817bd9 100644 --- a/app/Views/orders_update.php +++ b/app/Views/orders_update.php @@ -235,11 +235,11 @@ function patClear() { $('#phone').html(''); } -function patSelect(patnumber) { +function patSelect() { $('#modal_patList').modal('hide'); $('#modal_patEditor').modal('hide'); $('#patid').val(''); - let url = 'api/patients/detail/'+patnumber; + let url = 'api/patients/detail/'+patid; $.ajax({ url: url, method: "GET", @@ -251,7 +251,7 @@ function patSelect(patnumber) { $('#address').html(data.ADDRESS); $('#phone').html(data.PHONE); $("#patid").val(data.PATID); - $("#patnumber").val(patnumber); + $("#patnumber").val(data.PATNUMBER); }, error: function(response) { alert(response.responseJSON.messages.errors); @@ -259,7 +259,7 @@ function patSelect(patnumber) { }); } -function patCreate(patnumber) { +function patCreate() { $('#modal_patList').modal('hide'); $("#qpatid").val('0'); $("#qpatnumber").val(patnumber); @@ -270,17 +270,16 @@ function patCreate(patnumber) { $('#modal_patEditor').modal('show'); } -function patEdit(patnumber) { +function patEdit(patid) { $('#modal_patList').modal('hide'); - let url = 'api/patients/detail/'+patnumber; + let url = 'api/patients/detail/'+patid; $.ajax({ url: url, method: "GET", success: function(response) { let data = response['patient']; - console.log(data); - $("#qpatnumber").val(patnumber); - $("#qpatid").val(data.PATID); + $("#qpatnumber").val(data.PATNUMBER); + $("#qpatid").val(patid); $("#qpatname").val(data.PATNAME); $("#qsex").val(data.SEX); $("#qbirthdate").val(data.BIRTHDATE); @@ -296,10 +295,11 @@ function patEdit(patnumber) { function patSearch() { patnumber = $("#patnumber").val(); - let url = 'api/patients/search/'+patnumber; + let url = 'api/patients/search'; $.ajax({ url: url, - method: "GET", + method: "POST", + data: {patnumber:patnumber}, success: function(response) { $("#patList_tbody").html(""); var data = response['patients']; @@ -312,8 +312,8 @@ function patSearch() { patname = data[i].PATNAME; sex = data[i].SEX; birthdate = data[i].BIRTHDATE; - editBtn = ' '; - selectBtn = ' '; + editBtn = ' '; + selectBtn = ' '; if(data[i].LISCODE == null) { liscode = '-'; } let datarow = '' + '' + qpatnumber + '' + '' + patname+ ' ' + sex + '' + '' + birthdate+ '' + '' + selectBtn + editBtn + '' + @@ -336,25 +336,21 @@ function patSave() { birthdate = $('#qbirthdate').val(); sex = $('#qsex').val(); address = $('#qaddress').val(); - phone = $('#qphone').val(); - if(patid == '') { - - } else { - let data = { patid: patid, patnumber: patnumber, patname:patname, birthdate:birthdate, sex:sex, address:address, phone:phone }; - let url = 'api/patients/save'; - $.ajax({ - url: url, - method: "POST", - data:data, - success: function(response) { - console.log(response); - patSelect(patnumber); - }, - error: function(response) { - alert(response.responseJSON.messages.errors); - } - }); - } + phone = $('#qphone').val(); + let data = { patid: patid, patnumber: patnumber, patname:patname, birthdate:birthdate, sex:sex, address:address, phone:phone }; + let url = 'api/patients/save'; + $.ajax({ + url: url, + method: "POST", + data:data, + success: function(response) { + console.log(response); + patSelect(patnumber); + }, + error: function(response) { + alert(response.responseJSON.messages.errors); + } + }); } $(document).ready(function() { @@ -363,7 +359,14 @@ $(document).ready(function() { echo "$('.test$i').select2();"; } ?> + flatpickr("#visitdate", { allowInput: true, enableTime: true, dateFormat: "Y-m-d H:i", time_24hr: true }); + + $("#patnumber").keydown(function(event) { + if (event.keyCode === 13) { + patSearch(); + } + }); }); endSection() ?> \ No newline at end of file diff --git a/app/Views/patients_index.php b/app/Views/patients_index.php index a9b07a5..4ad2200 100644 --- a/app/Views/patients_index.php +++ b/app/Views/patients_index.php @@ -2,9 +2,7 @@ section('content') ?>
-
-
Patients List
-
+
Patients List
MR#
@@ -20,6 +18,7 @@
+
@@ -38,7 +37,7 @@ -
- - - - - - - -
MR# :
Name :
Sex :
Birthdate :
Address :
Phone :
- - -
-
+ + + + + + + + + + + + + +
MR# :
Patient Name :
BirthDate :
Sex : + +
Address :
Phone :
+ +
@@ -100,60 +106,62 @@ function search() { }); } -function edit(testcode) { - let url = 'api/dictTests/detail/'+testcode; +function create() { + $("#qpatid").val('0'); + $("#qpatnumber").val(); + $("#qpatname").val(""); + $("#qsex").val(""); + $("#qbirthdate").val(""); + $("#qaddress").val(''); + $('#modal_patEditor').modal('show'); +} + +function edit(patid) { + let url = 'api/patients/detail/'+patid; $.ajax({ url: url, method: "GET", success: function(response) { - let data = response; - $("#alert-div").html(""); - $("#error-div").html(""); - $("#testcode").val(testcode); - $("#testcodetext").html(testcode); - $("#update").val('1'); - $("#text1").val(data.TEXT1); - $("#text2").val(data.TEXT2); - $("#unit").val(data.UNIT); - $("#refftext").val(data.REFFTEXT); - $("#modal_crud").modal('show'); + let data = response['patient']; + $("#qpatid").val(patid); + $("#qpatnumber").val(data.PATNUMBER); + $("#qpatname").val(data.PATNAME); + $("#qsex").val(data.SEX); + $("#qbirthdate").val(data.BIRTHDATE); + $("#qaddress").val(data.ADDRESS); + $("#qphone").val(data.PHONE); + $("#modal_patEditor").modal('show'); }, error: function(response) { - console.log(response.responseJSON) + alert(response.responseJSON.messages.errors); } }); } - function save() { - let url = 'api/dictTests/save'; - var testcode = $("#testcode").val(); - var text1 = $("#text1").val(); - var text2 = $("#text2").val(); - var unit = $("#unit").val(); - var refftext = $("#refftext").val(); - let data = { testcode: testcode, text1:text1, text2:text2, unit:unit, refftext:refftext }; + patid = $("#qpatid").val(); + patnumber = $("#qpatnumber").val(); + patname = $("#qpatname").val(); + birthdate = $('#qbirthdate').val(); + sex = $('#qsex').val(); + address = $('#qaddress').val(); + phone = $('#qphone').val(); + let data = { patid: patid, patnumber: patnumber, patname:patname, birthdate:birthdate, sex:sex, address:address, phone:phone }; + let url = 'api/patients/save'; $.ajax({ url: url, method: "POST", - data: data, + data:data, success: function(response) { - $("#alert-div").html(""); - $("#error-div").html(""); - $("#testcode").val(''); - $("#text1").val(''); - $("#text2").val(''); - $("#refftext").val(''); - $("#unit").val(''); - $("#modal_crud").modal('hide'); + $("#modal_patEditor").modal('hide'); + $('#search_patnumber').val(patnumber); search(); }, error: function(response) { - console.log(response.responseJSON) + alert(response.responseJSON.messages.errors); } }); } - endSection() ?> \ No newline at end of file