HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/ghayatcom/ghayatcom-api/app/Http/Resources/HealthProfileResource.php
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

/**
 * App\Http\Resources
 *
 * @property mixed $allergieHealthProfile
 * @property mixed $medicalConditionHealthProfile
 * @property mixed $medicationHealthProfile
 * @property mixed $procedureHealthProfile
 * @property mixed $prosthesisHealthProfile
 * @property mixed $vaccinationHealthProfile
 * @property mixed $dietaryRestrictionHealthProfile
 * @property mixed $recreationalDrugHealthProfile
 * @property mixed $alcoholConsumptionHealthProfile
 * @property mixed $tobaccoUseHealthProfile
 */
class HealthProfileResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    private $code;

    private $message;

    public function __construct($resource, $code = 200, $message = null)
    {
        parent::__construct($resource);
        $this->code = $code;
        $this->message = $message;
    }

    public function toArray($request)
    {
        if (! empty($this->healthProfile)) {
            $healthProfileData = [
                'id' => $this->healthProfile->id,
                'user_id' => $this->healthProfile->user_id,
                'bmi' => $this->healthProfile->bmi,
                'height' => $this->healthProfile->height,
                'weight' => $this->healthProfile->weight,
                'pulse' => $this->healthProfile->pulse,
                'body_temperature' => $this->healthProfile->body_temperature,
                'glucose' => $this->healthProfile->glucose,
                'blood_pressure_systolic' => $this->healthProfile->blood_pressure_systolic,
                'blood_pressure_diastolic' => $this->healthProfile->blood_pressure_diastolic,
                'total_cholesterol' => $this->healthProfile->total_cholesterol,
                'ldl_cholesterol' => $this->healthProfile->ldl_cholesterol,
                'hdl_cholesterol' => $this->healthProfile->hdl_cholesterol,
                'triglycerides' => $this->healthProfile->triglycerides,
                'cholesterol_hdl_ratio' => $this->healthProfile->cholesterol_hdl_ratio,
            ];
        } else {
            $healthProfileData = [];
        }

        return [
            'code' => $this->code,
            'message' => (isset($this->message)) ? [$this->message] : [__('digimed_validation.success_response.data_fetch_success')],
            'data' => [
                'hp_metrics' => $healthProfileData,
                'hp_allergies' => $this->allergieHealthProfile,
                'hp_medical_conditions' => $this->medicalConditionHealthProfile,
                'hp_medications' => $this->medicationHealthProfile,
                'hp_procedures' => $this->procedureHealthProfile,
                'hp_prosthesis' => $this->prosthesisHealthProfile,
                'hp_vaccinations' => $this->vaccinationHealthProfile,
                'hp_life_style' => [
                    'hp_dietary_restrictions' => $this->dietaryRestrictionHealthProfile,
                    'hp_recreational_drugs' => $this->recreationalDrugHealthProfile,
                    'hp_alcohol_consumptions' => $this->alcoholConsumptionHealthProfile,
                    'hp_tobacco_uses' => $this->tobaccoUseHealthProfile,
                ],
            ],
        ];
    }
}