319 lines
11 KiB
PHP
319 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Constants\HttpEnumCode;
|
|
use App\Model\OrderPrescription;
|
|
use App\Model\OrderPrescriptionIcd;
|
|
use App\Model\OrderPrescriptionProduct;
|
|
use App\Model\OrderProduct;
|
|
use App\Model\PatientFamily;
|
|
use App\Model\PatientPathography;
|
|
use App\Model\PatientPathographyProduct;
|
|
use App\Model\Product;
|
|
use App\Utils\PcreMatch;
|
|
use Hyperf\DbConnection\Db;
|
|
|
|
/**
|
|
* 家庭成员病情记录
|
|
*/
|
|
class PatientPathographyService extends BaseService
|
|
{
|
|
/**
|
|
* 检测家庭成员是否存在病情记录
|
|
* @return array
|
|
*/
|
|
public function existFamilyPathography(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
$family_id = $this->request->input('family_id');
|
|
|
|
// 获取家庭成员数据
|
|
$params = array();
|
|
$params['family_id'] = $family_id;
|
|
$patient_family = PatientFamily::getOne($params);
|
|
if (empty($patient_family)){
|
|
return fail();
|
|
}
|
|
|
|
if ($user_info['user_type'] == 1){
|
|
// 患者情况下 用户id需相同
|
|
if ($patient_family['patient_id'] != $user_info['client_user_id']){
|
|
return fail();
|
|
}
|
|
}
|
|
|
|
$result = array();
|
|
$result['is_exist'] = 0;
|
|
|
|
// 获取病情记录
|
|
$params = array();
|
|
$params['patient_id'] = $patient_family['patient_id'];
|
|
$params['family_id'] = $family_id;
|
|
$params['status'] = 1;
|
|
$patient_pathography = PatientPathography::getLastOne($params);
|
|
if (!empty($patient_pathography)){
|
|
$result['is_exist'] = 1;
|
|
}
|
|
|
|
return success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取家庭成员病情记录列表-分页
|
|
* @return array
|
|
*/
|
|
public function getFamilyPathographyPage(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
$family_id = $this->request->input('family_id');
|
|
$page = $this->request->input('page', 1);
|
|
$per_page = $this->request->input('per_page', 10);
|
|
|
|
// 获取家庭成员数据
|
|
$params = array();
|
|
$params['family_id'] = $family_id;
|
|
$patient_family = PatientFamily::getOne($params);
|
|
if (empty($patient_family)){
|
|
return fail();
|
|
}
|
|
|
|
if ($user_info['user_type'] == 1){
|
|
// 患者情况下 用户id需相同
|
|
if ($patient_family['patient_id'] != $user_info['client_user_id']){
|
|
return fail();
|
|
}
|
|
}
|
|
|
|
// 获取病情记录列表
|
|
$fields = [
|
|
"pathography_id",
|
|
"order_inquiry_id",
|
|
"name",
|
|
"sex",
|
|
"age",
|
|
"created_at",
|
|
"disease_class_name",
|
|
"disease_desc"
|
|
];
|
|
|
|
$params = array();
|
|
$params['patient_id'] = $patient_family['patient_id'];
|
|
$params['family_id'] = $family_id;
|
|
$params['status'] = 1;
|
|
$patient_pathographys = PatientPathography::getPatientPathographyPage($params, $fields, $page, $per_page);
|
|
|
|
foreach ($patient_pathographys['data'] as &$patient_pathography){
|
|
$patient_pathography['reception_time'] = null;
|
|
if (!empty($patient_pathography['OrderInquiry'])){
|
|
// 接诊时间
|
|
$patient_pathography['reception_time'] = $patient_pathography['OrderInquiry']['reception_time'];
|
|
}
|
|
|
|
unset($patient_pathography['OrderInquiry']);
|
|
}
|
|
|
|
return success($patient_pathographys);
|
|
}
|
|
|
|
/**
|
|
* 获取家庭成员病情记录详情
|
|
* @return array
|
|
*/
|
|
public function getFamilyPathographyInfo(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
$pathography_id = $this->request->route('pathography_id');
|
|
|
|
$params = array();
|
|
$params['pathography_id'] = $pathography_id;
|
|
$params['status'] = 1;
|
|
$patient_pathography = PatientPathography::getOne($params);
|
|
if (empty($patient_pathography)){
|
|
return success(null);
|
|
}
|
|
|
|
if ($user_info['user_type'] == 1){
|
|
// 患者情况下 用户id需相同
|
|
if ($patient_pathography['patient_id'] != $user_info['client_user_id']){
|
|
return fail();
|
|
}
|
|
|
|
if ($patient_pathography['user_id'] != $user_info['user_id']){
|
|
return fail();
|
|
}
|
|
}
|
|
|
|
$result = $patient_pathography->toArray();
|
|
$result['order_prescription'] = null; // 处方数据
|
|
$result['patient_pathography_product'] = array(); // 用药意向
|
|
$result['diagnose_images'] = array(); // 复诊凭证
|
|
|
|
// 获取处方数据
|
|
if (!empty($patient_pathography['order_prescription_id'])){
|
|
$params = array();
|
|
$params['order_prescription_id'] = $patient_pathography['order_prescription_id'];
|
|
$params['patient_id'] = $patient_pathography['patient_id'];
|
|
$params['family_id'] = $patient_pathography['family_id'];
|
|
$order_prescription = OrderPrescription::getOne($params);
|
|
if (!empty($order_prescription)){
|
|
$result['order_prescription']['doctor_created_time'] = $order_prescription['doctor_created_time']; // 医生开具处方时间
|
|
$result['order_prescription']['doctor_advice'] = $order_prescription['doctor_advice'];// 医嘱
|
|
|
|
// 获取处方疾病数据
|
|
$params = array();
|
|
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
|
$order_prescription_icds = OrderPrescriptionIcd::getList($params);
|
|
if (empty($order_prescription_icds)){
|
|
return fail();
|
|
}
|
|
|
|
$icd_name = array_column($order_prescription_icds->toArray(),"icd_name");
|
|
$result['order_prescription']['icd_name'] = implode(";",$icd_name);
|
|
|
|
// 获取处方药品名称
|
|
$params = array();
|
|
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
|
$order_prescription_products = OrderPrescriptionProduct::getList($params);
|
|
if (empty($order_prescription_products)){
|
|
return fail();
|
|
}
|
|
|
|
$result["order_prescription"]["product"] = $order_prescription_products->toArray();
|
|
}
|
|
}
|
|
|
|
// 获取用药意向
|
|
$params = array();
|
|
$params['pathography_id'] = $patient_pathography['pathography_id'];
|
|
$patient_pathography_products = PatientPathographyProduct::getList($params);
|
|
if (!empty($patient_pathography_products)){
|
|
foreach ($patient_pathography_products as $patient_pathography_product){
|
|
// 获取商品数据
|
|
$params =array();
|
|
$params['product_id'] = $patient_pathography_product['product_id'];
|
|
$product = Product::getOne($params);
|
|
if (empty($product)){
|
|
return fail();
|
|
}
|
|
|
|
$item = array();
|
|
$item['product_cover_img'] = addAliyunOssWebsite($product['product_cover_img']);
|
|
$item['product_name'] = $product['product_name']; // 名称
|
|
$item['product_spec'] = $product['product_spec']; // 商品规格
|
|
$item['packaging_unit'] = $product['packaging_unit']; // 基本包装单位(例:盒/瓶)
|
|
$item['case_product_num'] = $patient_pathography_product['case_product_num']; // 药品数量
|
|
|
|
$result['patient_pathography_product'][] = $item;
|
|
}
|
|
}
|
|
|
|
// 复诊凭证
|
|
if (!empty($patient_pathography['diagnose_images'])){
|
|
$diagnose_images = explode(',', $patient_pathography['diagnose_images']);
|
|
foreach ($diagnose_images as &$item) {
|
|
$item = addAliyunOssWebsite($item);
|
|
}
|
|
|
|
$result['diagnose_images'] = $diagnose_images;
|
|
}
|
|
|
|
return success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取家庭成员病情记录分组
|
|
* @return array
|
|
*/
|
|
public function getFamilyPathographyGroup(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
// 获取家庭成员数据
|
|
$params = array();
|
|
$params['patient_id'] = $user_info['client_user_id'];
|
|
$patient_familys = PatientFamily::getList($params);
|
|
if (empty($patient_familys)){
|
|
return success();
|
|
}
|
|
|
|
// 定义返回数据
|
|
$results = array();
|
|
|
|
foreach ($patient_familys as $patient_family){
|
|
// 定义返回数据
|
|
$result = array();
|
|
$result['user_id'] = $user_info['user_id'];
|
|
$result['patient_id'] = $patient_family['patient_id'];
|
|
$result['family_id'] = $patient_family['family_id'];
|
|
$result['status'] = $patient_family['status'];
|
|
$result['card_name'] = $patient_family['card_name'];
|
|
$result['sex'] = $patient_family['sex'];
|
|
$result['age'] = $patient_family['age'];
|
|
$result['count'] = 0;
|
|
|
|
$params = array();
|
|
$params['user_id'] = $user_info['user_id'];
|
|
$params['patient_id'] = $patient_family['patient_id'];
|
|
$params['family_id'] = $patient_family['family_id'];
|
|
$params['status'] = 1;
|
|
$patient_pathographys = PatientPathography::getList($params);
|
|
if (!empty($patient_pathographys)){
|
|
$result['count'] = count($patient_pathographys);
|
|
}
|
|
|
|
$results[] = $result;
|
|
}
|
|
|
|
return success($results);
|
|
}
|
|
|
|
/**
|
|
* 删除家庭成员病情记录
|
|
* @return array
|
|
*/
|
|
public function deleteFamilyPathography(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
$pathography_id = $this->request->route('pathography_id');
|
|
|
|
// 获取病情记录
|
|
$params = array();
|
|
$params['pathography_id'] = $pathography_id;
|
|
$patient_pathography = PatientPathography::getOne($params);
|
|
if (empty($patient_pathography)){
|
|
return fail(HttpEnumCode::HTTP_ERROR,"无该病例");
|
|
}
|
|
|
|
if ($user_info['user_type'] == 2){
|
|
return fail();
|
|
}
|
|
|
|
if ($user_info['user_type'] == 1){
|
|
// 患者情况下 用户id需相同
|
|
if ($patient_pathography['patient_id'] != $user_info['client_user_id']){
|
|
return fail();
|
|
}
|
|
|
|
if ($patient_pathography['user_id'] != $user_info['user_id']){
|
|
return fail();
|
|
}
|
|
}
|
|
|
|
if ($patient_pathography['status'] == 2){
|
|
return success();
|
|
}
|
|
|
|
$params = array();
|
|
$params['pathography_id'] = $patient_pathography['pathography_id'];
|
|
|
|
$data = array();
|
|
$data['status'] = 2;
|
|
$res = PatientPathography::edit($params,$data);
|
|
if (!$res){
|
|
return fail();
|
|
}
|
|
|
|
return success();
|
|
}
|
|
} |