diff --git a/app/Controller/UserDoctorController.php b/app/Controller/UserDoctorController.php index 34df461..6d4a19e 100644 --- a/app/Controller/UserDoctorController.php +++ b/app/Controller/UserDoctorController.php @@ -227,9 +227,14 @@ class UserDoctorController extends AbstractController /** * 获取处方详情 * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function getPrescriptionInfo(): ResponseInterface { + $request = $this->container->get(UserDoctorRequest::class); + $request->scene('getPrescriptionInfo')->validateResolved(); + $UserDoctorService = new UserDoctorService(); $data = $UserDoctorService->getPrescriptionInfo(); return $this->response->json($data); diff --git a/app/Model/OrderPrescription.php b/app/Model/OrderPrescription.php index ba52d43..d466f8b 100644 --- a/app/Model/OrderPrescription.php +++ b/app/Model/OrderPrescription.php @@ -7,6 +7,7 @@ namespace App\Model; use Hyperf\Contract\LengthAwarePaginatorInterface; +use Hyperf\Database\Model\Collection; use Hyperf\Database\Model\Relations\HasMany; use Hyperf\Database\Model\Relations\HasOne; use Hyperf\Snowflake\Concern\Snowflake; @@ -28,8 +29,10 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $patient_sex 患者性别-就诊人(1:男 2:女) * @property int $patient_age 患者年龄-就诊人 * @property string $prescription_img 处方图片 + * @property string $doctor_advice 医嘱 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 + * @property-read \Hyperf\Database\Model\Collection|OrderPrescriptionIcd[] $OrderPrescriptionIcd */ class OrderPrescription extends Model { @@ -43,7 +46,7 @@ class OrderPrescription extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['order_prescription_id', 'order_inquiry_id', 'doctor_id', 'pharmacist_id', 'prescription_status', 'pharmacist_audit_status', 'pharmacist_fail_reason', 'platform_audit_status', 'platform_fail_reason', 'is_delete', 'prescription_code', 'doctor_name', 'patient_name', 'patient_sex', 'patient_age', 'prescription_img', 'created_at', 'updated_at']; + protected array $fillable = ['order_prescription_id', 'order_inquiry_id', 'doctor_id', 'pharmacist_id', 'prescription_status', 'pharmacist_audit_status', 'pharmacist_fail_reason', 'platform_audit_status', 'platform_fail_reason', 'is_delete', 'prescription_code', 'doctor_name', 'patient_name', 'patient_sex', 'patient_age', 'prescription_img', 'doctor_advice', 'created_at', 'updated_at']; protected string $primaryKey = "order_prescription_id"; @@ -55,6 +58,28 @@ class OrderPrescription extends Model return $this->HasMany(OrderPrescriptionIcd::class, 'order_prescription_id','order_prescription_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 Collection|array + */ + public static function getList(array $params = [], array $fields = ['*']): Collection|array + { + return self::where($params)->get($fields); + } + /** * 获取是否存在 * @param array $params diff --git a/app/Model/OrderProduct.php b/app/Model/OrderProduct.php new file mode 100644 index 0000000..8b2b5a4 --- /dev/null +++ b/app/Model/OrderProduct.php @@ -0,0 +1,93 @@ +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 $params + * @return bool + */ + public static function getExists(array $params): bool + { + return self::where($params)->exists(); + } +} diff --git a/app/Model/OrderProductItem.php b/app/Model/OrderProductItem.php new file mode 100644 index 0000000..d409c19 --- /dev/null +++ b/app/Model/OrderProductItem.php @@ -0,0 +1,99 @@ +hasOne(Product::class, 'product_id', 'product_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 Collection|array + */ + public static function getList(array $params = [], array $fields = ['*']): Collection|array + { + return self::where($params)->get($fields); + } + + /** + * 获取是否存在 + * @param array $params + * @return bool + */ + public static function getExists(array $params): bool + { + return self::where($params)->exists(); + } + + /** + * 获取数据-关联商品表 + * @param array $params + * @param array $fields + * @return Collection|array + */ + public static function getWithProductList(array $params = [], array $fields = ['*']): Collection|array + { + return self::with([ + "Product" + ]) + ->where($params) + ->get($fields); + } +} diff --git a/app/Request/UserDoctorRequest.php b/app/Request/UserDoctorRequest.php index af2f6ab..3c88fdd 100644 --- a/app/Request/UserDoctorRequest.php +++ b/app/Request/UserDoctorRequest.php @@ -54,6 +54,10 @@ class UserDoctorRequest extends FormRequest 'doctor_id', 'evaluation_type', ], + 'getPrescriptionInfo' => [ // 获取处方详情 + 'order_inquiry_id', + 'order_prescription_id', // 处方id(非必须) + ], ]; /** @@ -85,6 +89,7 @@ class UserDoctorRequest extends FormRequest 'words' => 'required', 'doctor_id' => 'required', 'evaluation_type' => 'required|integer|min:1|max:3', + 'order_inquiry_id' => 'required', ]; } @@ -134,6 +139,7 @@ class UserDoctorRequest extends FormRequest 'evaluation_type.integer' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'evaluation_type.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'evaluation_type.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'order_inquiry_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), ]; } } diff --git a/app/Services/CaseService.php b/app/Services/CaseService.php new file mode 100644 index 0000000..b67bea3 --- /dev/null +++ b/app/Services/CaseService.php @@ -0,0 +1,51 @@ +getCaseProductlist($order_inquiry_case['inquiry_case_id']); } unset($order_inquiry_case['order_inquiry']); } diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index 71ed4ce..aca7916 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -13,10 +13,12 @@ use App\Model\DoctorBankCard; use App\Model\DoctorExpertise; use App\Model\DoctorInquiryConfig; use App\Model\DoctorWord; +use App\Model\InquiryCaseProduct; use App\Model\OrderEvaluation; use App\Model\OrderInquiry; use App\Model\OrderInquiryCase; use App\Model\OrderPrescription; +use App\Model\OrderProductItem; use App\Model\User; use App\Model\UserDoctor; use App\Model\UserDoctorInfo; @@ -791,17 +793,82 @@ class UserDoctorService extends BaseService { $user_info = $this->request->getAttribute("userInfo") ?? []; - $order_prescription_id = $this->request->route('order_prescription_id'); + $order_inquiry_id = $this->request->input('order_inquiry_id'); + $order_prescription_id = $this->request->input('order_prescription_id'); + // 获取医生信息 + $params = array(); + $params['doctor_id'] = $user_info['client_user_id']; + $fields = [ + 'doctor_id', + 'iden_auth_status', + 'idcard_status', + 'multi_point_status', + ]; + $user_doctor = UserDoctor::getOne($params, $fields); + if (empty($user_doctor)) { + return fail(HttpEnumCode::HTTP_ERROR, "非法医生"); + } + + $res = $this->checkDoctorAuth($user_doctor); + if ($res !== true) { + return fail(HttpEnumCode::HTTP_ERROR, $res); + } + + // 获取患者病例表 + $fields = [ + 'inquiry_case_id', + 'name', + 'sex', + 'age', + 'disease_desc', + ]; + + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $params['status'] = 1; + $order_inquiry_case = OrderInquiryCase::getOne($params,$fields); + if (empty($order_inquiry_case)){ + return fail(HttpEnumCode::HTTP_ERROR,"患者病例信息错误"); + } + + // 获取用药意向 + $CaseService = new CaseService(); + $inquiry_case_product = $CaseService->getCaseProductlist($order_inquiry_case['inquiry_case_id']); + + if (!empty($order_prescription_id)){ + // 获取处方数据 + $params = array(); + $params['order_prescription_id'] = $order_prescription_id; + $order_prescription = OrderPrescription::getOne($params); + if (empty($order_prescription)){ + return fail(); + } + + // 订单-商品订单列表 + $OrderPrescriptionService = new OrderPrescriptionService(); + $order_product_items = $OrderPrescriptionService->getproductList($order_inquiry_id,$order_prescription_id); + } + + $result = array(); + $result['inquiry_case_product'] = $inquiry_case_product;// 用药意向 + $result['order_product_items'] = $order_product_items ?? [];// 开方药品 + $result['case'] = $order_inquiry_case;// 病例数据 + $result['prescription']['doctor_advice'] = $order_prescription['doctor_advice'] ?? "";// 医嘱 + + return success($result); } /** * 检测医生身份认证 * @param object|array $user_doctor 医生表数据 + * @param bool $is_iden_auth 是否检测身份认证 + * @param bool $is_idcard 是否检测实名认证 + * @param bool $is_multi_point 是否检测多点执业认证 * @return bool|string string:错误信息 bool:通过 */ - public function checkDoctorAuth(object|array $user_doctor): bool|string + public function checkDoctorAuth(object|array $user_doctor,bool $is_iden_auth = true,bool $is_idcard = true,bool $is_multi_point = true): bool|string { if (empty($user_doctor)){ throw new BusinessException(); diff --git a/config/routes.php b/config/routes.php index 921a532..14991fc 100644 --- a/config/routes.php +++ b/config/routes.php @@ -134,7 +134,7 @@ Router::addGroup('/doctor', function () { Router::get('', [UserDoctorController::class, 'getPrescriptionList']); // 获取处方详情 - Router::get('/{order_prescription_id:\d+}', [UserDoctorController::class, 'getPrescriptionInfo']); + Router::get('/info', [UserDoctorController::class, 'getPrescriptionInfo']); }); // 常用语