169 lines
6.3 KiB
PHP
169 lines
6.3 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Model;
|
||
|
||
|
||
|
||
use Hyperf\Database\Model\Collection;
|
||
use Hyperf\Database\Model\Relations\HasOne;
|
||
use Hyperf\DbConnection\Db;
|
||
use Hyperf\Snowflake\Concern\Snowflake;
|
||
|
||
/**
|
||
* @property int $pathography_id 主键id
|
||
* @property int $user_id 用户id
|
||
* @property int $patient_id 患者id
|
||
* @property int $family_id 家庭成员id
|
||
* @property int $order_inquiry_id 关联问诊id
|
||
* @property int $order_prescription_id 关联处方id
|
||
* @property int $disease_class_id 疾病分类id-系统
|
||
* @property int $nation_id 民族id
|
||
* @property int $job_id 职业id
|
||
* @property int $relation 患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 )
|
||
* @property int $status 状态(1:正常 2:删除)
|
||
* @property string $name 患者名称
|
||
* @property int $sex 患者性别(0:未知 1:男 2:女)
|
||
* @property int $age 患者年龄
|
||
* @property string $height 身高(cm)
|
||
* @property string $weight 体重(kg)
|
||
* @property int $marital_status 婚姻状况(0:未婚 1:已婚 2:离异)
|
||
* @property string $disease_class_name 疾病名称-系统
|
||
* @property string $diagnosis_date 确诊日期
|
||
* @property string $disease_desc 病情描述(主诉)
|
||
* @property string $diagnose_images 复诊凭证(多个使用逗号分隔)
|
||
* @property int $is_allergy_history 是否存在过敏史(0:否 1:是)
|
||
* @property string $allergy_history 过敏史描述
|
||
* @property int $is_family_history 是否存在家族病史(0:否 1:是)
|
||
* @property string $family_history 家族病史描述
|
||
* @property int $is_pregnant 是否备孕、妊娠、哺乳期(0:否 1:是)
|
||
* @property string $pregnant 备孕、妊娠、哺乳期描述
|
||
* @property int $is_taboo 是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在
|
||
* @property int $is_take_medicine 正在服药(0:否 1:是)
|
||
* @property string $drugs_name 正在服药名称
|
||
* @property string $nation_name 民族名称
|
||
* @property string $job_name 职业名称
|
||
* @property string $diagnosis_hospital 确诊医院
|
||
* @property int $is_operation 是否存在手术(0:否 1:是)
|
||
* @property string $operation 手术描述
|
||
* @property int $drink_wine_status 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒)
|
||
* @property int $smoke_status 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟)
|
||
* @property int $chemical_compound_status 化合物状态(1:从不 2:偶尔 3:经常 4:每天)
|
||
* @property string $chemical_compound_describe 化合物描述
|
||
* @property \Carbon\Carbon $created_at 创建时间
|
||
* @property \Carbon\Carbon $updated_at 修改时间
|
||
* @property-read OrderInquiry|null $OrderInquiry
|
||
*/
|
||
class PatientPathography extends Model
|
||
{
|
||
use Snowflake;
|
||
|
||
/**
|
||
* The table associated with the model.
|
||
*/
|
||
protected ?string $table = 'patient_pathography';
|
||
|
||
/**
|
||
* The attributes that are mass assignable.
|
||
*/
|
||
protected array $fillable = ['pathography_id', 'user_id', 'patient_id', 'family_id', 'order_inquiry_id', 'order_prescription_id', 'disease_class_id', 'nation_id', 'job_id', 'relation', 'status', 'name', 'sex', 'age', 'height', 'weight', 'marital_status', 'disease_class_name', 'diagnosis_date', 'disease_desc', 'diagnose_images', 'is_allergy_history', 'allergy_history', 'is_family_history', 'family_history', 'is_pregnant', 'pregnant', 'is_taboo', 'is_take_medicine', 'drugs_name', 'nation_name', 'job_name', 'diagnosis_hospital', 'is_operation', 'operation', 'drink_wine_status', 'smoke_status', 'chemical_compound_status', 'chemical_compound_describe', 'created_at', 'updated_at'];
|
||
|
||
protected string $primaryKey = "pathography_id";
|
||
|
||
/**
|
||
* 关联问诊订单表
|
||
*/
|
||
public function OrderInquiry(): HasOne
|
||
{
|
||
return $this->hasOne(OrderInquiry::class, 'order_inquiry_id', 'order_inquiry_id');
|
||
}
|
||
|
||
/**
|
||
* 获取信息-单条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->first($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取信息-单条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getLastOne(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->latest("created_at")->first($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取数据-多
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return Collection|array
|
||
*/
|
||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||
{
|
||
return self::where($params)->get($fields);
|
||
}
|
||
|
||
/**
|
||
* 新增
|
||
* @param array $data
|
||
* @return \Hyperf\Database\Model\Model|PatientPathography
|
||
*/
|
||
public static function addPatientPathography(array $data): \Hyperf\Database\Model\Model|PatientPathography
|
||
{
|
||
return self::create($data);
|
||
}
|
||
|
||
/**
|
||
* 修改
|
||
* @param array $params
|
||
* @param array $data
|
||
* @return int
|
||
*/
|
||
public static function edit(array $params = [], array $data = []): int
|
||
{
|
||
return self::where($params)->update($data);
|
||
}
|
||
|
||
/**
|
||
* 获取家庭成员病情记录列表-分页
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @param int|null $page
|
||
* @param int|null $per_page
|
||
* @return array
|
||
*/
|
||
public static function getPatientPathographyPage(array $params,array $fields = ["*"], int $page = null, ?int $per_page = 10): array
|
||
{
|
||
$result = self::with(['OrderInquiry'])
|
||
->where($params)
|
||
->orderBy("created_at",'desc')
|
||
->paginate($per_page, $fields, "page", $page);
|
||
|
||
$data = array();
|
||
$data['current_page'] = $result->currentPage();// 当前页码
|
||
$data['total'] = $result->total();// 数据总数
|
||
$data['data'] = $result->items();// 数据
|
||
$data['per_page'] = $result->perPage();// 每页个数
|
||
$data['last_page'] = $result->lastPage();// 最后一页
|
||
|
||
return $data;
|
||
}
|
||
|
||
// 获取信息-分组
|
||
public static function getFamilyPathographyGroup(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)
|
||
->groupBy(["family_id"])
|
||
->get($fields);
|
||
}
|
||
}
|