Skip to main content

amitavroy/doctor-app

41 stars
1 code files
View amitavroy/doctor-app on GitHub

app/Services/PatientService.php

Open in GitHub
use App\Models\Patient;
use Exception;
use Illuminate\Support\Facades\DB;
 
class PatientService
{
public function createPatient($patientData): Patient
{
$settingService = app()->make(SettingService::class);
 
try {
DB::beginTransaction();
$patientNumber = $settingService->getNextPatientNumber();
 
$patient = Patient::create([
'patient_id' => now()->format('Ym') . $patientNumber,
'name' => $patientData['name'],
'phone_number' => $patientData['phone_number'],
'year_of_birth' => now()->subYears($patientData['age'])->format('Y'),
'weight' => $patientData['weight'],
]);
 
$settingService->incrementLastPatientNumber();
DB::commit();
 
return $patient;
} catch (Exception $exception) {
logger()->error($exception->getMessage());
}
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.