Skip to content
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.

Commit

Permalink
Add field to patient
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain committed May 20, 2018
1 parent eab26e0 commit 76f9178
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 59 deletions.
20 changes: 14 additions & 6 deletions app/main/patient/controller/PatientCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
Expand Down
85 changes: 64 additions & 21 deletions app/main/patient/model/Patient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
14 changes: 9 additions & 5 deletions app/main/patient/repository/PatientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
34 changes: 24 additions & 10 deletions ressources/js/savePatient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -31,23 +32,31 @@ jQuery(document).ready(function($){
saveFormInfo();
}
});

$('#height, #weight').change(function(){
$('#bmi').val(calculBMI($('#height').val(),$('#weight').val()));
});
});

let savePatientRecord = function(){
jQuery.post({
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)
{
Expand Down Expand Up @@ -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;
};
12 changes: 6 additions & 6 deletions ressources/js/savePatient.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 31 additions & 11 deletions ressources/views/patient_record.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
?>
<section class="patient_record">
<header>
<h2>Informations du patient</h2>
<h2>Informations du patient <?= $PatientCtrl->getPatient()->getLogin() ?></h2>
</header>
<form class="patient_record_form" id="patient_form" action="<?= admin_url('admin-post.php?action=post_save_patient') ?>" method="post">
<div class="patient_record_form_group">
<label for="login">Identifiant :</label>
<input id="login" type="text" value="<?= $PatientCtrl->getPatient()->getLogin() ?>" disabled>
</div>
<h3>Renseignements administratifs</h3>
<div class="patient_record_form_group">
<label for="firstname">Prénom :</label>
<input id="firstname" type="text" name="FirstName" value="<?= $PatientCtrl->getPatient()->getFirstName() ?>">
Expand All @@ -22,16 +19,39 @@
<input id="lastname" type="text" name="LastName" value="<?= $PatientCtrl->getPatient()->getLastName() ?>">
</div>
<div class="patient_record_form_group">
<label for="weight">Poids :</label>
<input id="weight" type="text" name="Weight" value="<?= $PatientCtrl->getPatient()->getWeight()->getValue() ?>">
<label for="phone">Téléphone :</label>
<input id="phone" type="text" name="Phone" value="<?= $PatientCtrl->getPatient()->getPhone() ?>">
</div>
<div class="patient_record_form_group">
<label for="height">Taille :</label>
<input id="height" type="text" name="Height" value="<?= $PatientCtrl->getPatient()->getHeight() ?>">
<label for="dob">Date de naissance :</label>
<input id="dob" type="date" name="DateOfBirth" value="<?= $PatientCtrl->getPatient()->getDateOfBirth() ?>">
</div>
<div class="patient_record_form_group">
<label for="phone">Téléphone :</label>
<input id="phone" type="text" name="Phone" value="<?= $PatientCtrl->getPatient()->getPhone() ?>">
<label for="job">Profession :</label>
<input id="job" type="text" name="Job" value="<?= $PatientCtrl->getPatient()->getJob() ?>">
</div>
<h3>Renseignements médicaux</h3>
<div style="display: flex;justify-content: space-between">
<div class="patient_record_form_group">
<label for="weight">Poids :</label>
<input style="width: 70px;" id="weight" type="text" name="Weight" value="<?= $PatientCtrl->getPatient()->getWeight()->getValue() ?>">
</div>
<div class="patient_record_form_group" style="margin-right: 0.5rem">
<label style="width: 70px;" for="height">Taille :</label>
<input style="width: 70px;" id="height" type="text" name="Height" value="<?= $PatientCtrl->getPatient()->getHeight() ?>">
</div>
<div class="patient_record_form_group" style="margin-right: 0.5rem">
<label style="width: 70px;" for="bmi">IMC :</label>
<input style="width: 70px;" id="bmi" type="text" value="<?= ! is_string( $PatientCtrl->getBMI()->getBmi() ) ? $PatientCtrl->getBMI()->getBmi() : 0 ?>" disabled>
</div>
</div>
<div class="patient_record_form_group">
<label for="familialHistory">Antécédent familiaux :</label>
<input id="familialHistory" type="text" name="FamilialHistory" value="<?= $PatientCtrl->getPatient()->getFamilialHistory() ?>">
</div>
<div class="patient_record_form_group">
<label for="medicalHistory">Antécédent médicaux :</label>
<input id="medicalHistory" type="text" name="MedicalHistory" value="<?= $PatientCtrl->getPatient()->getFamilialHistory() ?>">
</div>
<div class="patient_record_form_group" style="display: flex;">
<label for="obs">Observations :</label>&nbsp;
Expand Down

0 comments on commit 76f9178

Please sign in to comment.