From 76f9178f603337367cdae773015c8a28fb166bd6 Mon Sep 17 00:00:00 2001 From: Romain Date: Sun, 20 May 2018 21:53:26 +0200 Subject: [PATCH] Add field to patient --- app/main/patient/controller/PatientCtrl.php | 20 +++-- app/main/patient/model/Patient.php | 85 ++++++++++++++----- .../patient/repository/PatientRepository.php | 14 +-- ressources/js/savePatient.js | 34 +++++--- ressources/js/savePatient.min.js | 12 +-- ressources/views/patient_record.php | 42 ++++++--- 6 files changed, 148 insertions(+), 59 deletions(-) diff --git a/app/main/patient/controller/PatientCtrl.php b/app/main/patient/controller/PatientCtrl.php index 85407c6..dbf04ab 100755 --- a/app/main/patient/controller/PatientCtrl.php +++ b/app/main/patient/controller/PatientCtrl.php @@ -15,11 +15,15 @@ class PatientCtrl { const AUTO_LOAD = [ - Dinet::SLUG . 'Observation' => 'Observation', - Dinet::SLUG . 'Phone' => 'Phone', - Dinet::SLUG . 'Height' => 'Height', - 'first_name' => 'FirstName', - 'last_name' => 'LastName', + Dinet::SLUG . 'Observation' => 'Observation', + Dinet::SLUG . 'Phone' => 'Phone', + Dinet::SLUG . 'Height' => 'Height', + 'first_name' => 'FirstName', + 'last_name' => 'LastName', + Dinet::SLUG . 'Job' => 'Job', + Dinet::SLUG . 'DateOfBirth' => 'DateOfBirth', + Dinet::SLUG . 'FamilialHistory' => 'FamilialHistory', + Dinet::SLUG . 'MedicalHistory' => 'MedicalHistory', ]; /** @var Patient */ @@ -68,7 +72,11 @@ public function ajaxSavePatient(): void ->setHeight( $this->reformatHeight( $_POST['Height'] ) ) ->setObservation( $_POST['Observation'] ) ->setPhone( $_POST['Phone'] ) - ->setWeight( ( new Weight() )->setValue( $_POST['Weight'] )->setTimestamp( time() ) ); + ->setWeight( ( new Weight() )->setValue( $_POST['Weight'] )->setTimestamp( time() ) ) + ->setJob( $_POST['Job'] ) + ->setDateOfBirth( $_POST['DateOfBirth'] ) + ->setMedicalHistory( $_POST['MedicalHistory'] ) + ->setFamilialHistory( $_POST['FamilialHistory'] ); $this->getRepository()->save( $this->Patient ); $this->load(); diff --git a/app/main/patient/model/Patient.php b/app/main/patient/model/Patient.php index d9af82d..5ff4417 100755 --- a/app/main/patient/model/Patient.php +++ b/app/main/patient/model/Patient.php @@ -4,41 +4,50 @@ class Patient { - /** - * @var int - */ + /** @var int */ private $userId; - /** - * @var string - */ + /** @var string */ private $firstName; - /** - * @var string - */ + /** @var string */ private $lastName; - /** - * @var Weight - */ + /** @var Weight */ private $weight; - /** - * @var float - */ + /** @var float */ private $height; - /** - * @var string - */ + /** @var string */ private $phone; - /** - * @var string - */ + /** @var string */ private $observation; + /** @var string */ + private $dateOfBirth; + + /** @var string */ + private $job; + + /** @var string */ + private $medicalHistory; + + /** @var string */ + private $familialHistory; + + public function getMedicalHistory(): string + { + return $this->medicalHistory ?: ''; + } + + + public function getFamilialHistory(): string + { + return $this->familialHistory ?: ''; + } + public function __construct( $userId = null ) { $this->userId = $userId === null ? get_current_user_id() : $userId; @@ -89,6 +98,16 @@ public function getPhone(): string return isset( $this->phone ) ? $this->phone : ''; } + public function getDateOfBirth(): string + { + return $this->dateOfBirth ?: ''; + } + + public function getJob(): string + { + return $this->job ?: ''; + } + public function setFirstName( ?string $firstName ): Patient { $this->firstName = $firstName; @@ -124,4 +143,28 @@ public function setObservation( ?string $observation ): Patient $this->observation = $observation; return $this; } + + public function setDateOfBirth( string $dateOfBirth ): Patient + { + $this->dateOfBirth = $dateOfBirth; + return $this; + } + + public function setJob( string $job ): Patient + { + $this->job = $job; + return $this; + } + + public function setMedicalHistory( string $medicalHistory ): Patient + { + $this->medicalHistory = $medicalHistory; + return $this; + } + + public function setFamilialHistory( string $familialHistory ): Patient + { + $this->familialHistory = $familialHistory; + return $this; + } } diff --git a/app/main/patient/repository/PatientRepository.php b/app/main/patient/repository/PatientRepository.php index 2fbbd1a..980a9c6 100755 --- a/app/main/patient/repository/PatientRepository.php +++ b/app/main/patient/repository/PatientRepository.php @@ -7,11 +7,15 @@ class PatientRepository { const AUTO_SAVE = [ - Dinet::SLUG . 'Observation' => 'Observation', - Dinet::SLUG . 'Phone' => 'Phone', - Dinet::SLUG . 'Height' => 'Height', - 'first_name' => 'FirstName', - 'last_name' => 'LastName', + Dinet::SLUG . 'Observation' => 'Observation', + Dinet::SLUG . 'Phone' => 'Phone', + Dinet::SLUG . 'Height' => 'Height', + 'first_name' => 'FirstName', + 'last_name' => 'LastName', + Dinet::SLUG . 'Job' => 'Job', + Dinet::SLUG . 'DateOfBirth' => 'DateOfBirth', + Dinet::SLUG . 'FamilialHistory' => 'FamilialHistory', + Dinet::SLUG . 'MedicalHistory' => 'MedicalHistory', ]; public function save( Patient $patient ) diff --git a/ressources/js/savePatient.js b/ressources/js/savePatient.js index aca440d..c8906b2 100755 --- a/ressources/js/savePatient.js +++ b/ressources/js/savePatient.js @@ -11,6 +11,7 @@ jQuery(document).ready(function($){ checkValue('weight','[0-9]{1,3}[.]?[0-9]{0,}'); checkValue('height','[0-9]{1,3}[.]?[0-9]{0,}'); checkValue('phone','^[(+33)|0]{1}[1-9]{1}[ |.]?([0-9]{2}[ |.]?){4}$'); + checkValue('job','[a-zA-Z]'); if( $('.patient_record .inputError').length === 0 ) { savePatientRecord(); @@ -31,6 +32,10 @@ jQuery(document).ready(function($){ saveFormInfo(); } }); + + $('#height, #weight').change(function(){ + $('#bmi').val(calculBMI($('#height').val(),$('#weight').val())); + }); }); let savePatientRecord = function(){ @@ -38,16 +43,20 @@ let savePatientRecord = function(){ url : SavePatientRecordUtil.ajaxurl, dataType: "json", data : { - action : "ajaxSavePatient", - nonce : SavePatientRecordUtil.nonce, - nonceName : jQuery('#nonceName').val(), - patientId : jQuery('#patientId').val(), - FirstName : jQuery('#firstname').val(), - LastName : jQuery('#lastname').val(), - Weight : jQuery('#weight').val(), - Height : jQuery('#height').val(), - Phone : jQuery('#phone').val(), - Observation : jQuery('#obs').val() + action : "ajaxSavePatient", + nonce : SavePatientRecordUtil.nonce, + nonceName : jQuery('#nonceName').val(), + patientId : jQuery('#patientId').val(), + FirstName : jQuery('#firstname').val(), + LastName : jQuery('#lastname').val(), + Weight : jQuery('#weight').val(), + Height : jQuery('#height').val(), + Phone : jQuery('#phone').val(), + Observation : jQuery('#obs').val(), + Job : jQuery('#job').val(), + DateOfBirth : jQuery('#dob').val(), + FamilialHistory : jQuery('#familialHistory').val(), + MedicalHistory : jQuery('#medicalHistory').val() }, success : function (response) { @@ -130,4 +139,9 @@ let formatPhone = function( separator = '' ){ result += phone[i] + ( result.replace(new RegExp(separator,'g'),'').length % 2 ? separator : '' ); $phone.val(result); +}; + +let calculBMI = function(height, weight) +{ + return Math.round(weight / (height * height) * 10 ) / 10; }; \ No newline at end of file diff --git a/ressources/js/savePatient.min.js b/ressources/js/savePatient.min.js index f345207..61512e7 100755 --- a/ressources/js/savePatient.min.js +++ b/ressources/js/savePatient.min.js @@ -1,9 +1,9 @@ var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(a,b,c){a instanceof String&&(a=String(a));for(var e=a.length,d=0;d
-

Informations du patient

+

Informations du patient getPatient()->getLogin() ?>

-
- - -
+

Renseignements administratifs

@@ -22,16 +19,39 @@
- - + +
- - + +
- - + + +
+

Renseignements médicaux

+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ +