Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

amitavroy/doctor-app

40 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.