Advertisement
Guest User

GetMedicalRecordsProductByQueueNo

a guest
Apr 21st, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.63 KB | None | 0 0
  1. class GetMedicalRecordsProductByQueueNo implements BusinessFunction {
  2.  
  3.     public function getDescription(){
  4.         return "Get Medical Records List";
  5.     }
  6.  
  7.     public function execute($dto){                    
  8.         //\Log::debug($dto);
  9.         $recordOwnerId  = $dto["record_owner_id"];
  10.         $ouCode         = $dto["ou_code"];
  11.         $queueNo        = $dto["queue_no"];
  12.         $dateNow        = $dto["date_now"];                        
  13.        
  14.         $queue = ConsultationQueue::where('ou_code_alias', $ouCode)
  15.                 ->where('doc_date', $dateNow)
  16.                 ->where('queue_no', $queueNo)                
  17.                 ->first();
  18.        
  19.         if(is_null($queue)){
  20.             throw new CoreException(ERROR_BUSINESS_VALIDATION,[],
  21.                 ["queue_no" => ["No antrian tidak ditemukan"]]);
  22.         }        
  23.  
  24.         $recordOwner    = RecordOwner::find($recordOwnerId);
  25.         $patient        = Patient::find($queue->patient_id);        
  26.  
  27.         $customer       = Customer::where('customer_code', $patient->patient_code)->first();
  28.         $medicalRecord  = MedicalRecord::where('consultation_queue_id', $queue->consultation_queue_id)->first();
  29.  
  30.         $raw = "SELECT A.product_id, A.product_code, A.product_name, X.qty, I.how_to_use,
  31.                I.prescription_balance_item_id, X.medical_record_product_id,
  32.                H.uom_name, Z.salesman_id, Z.full_name as salesman_name,
  33.                 COALESCE(E.qty, 0) as current_qty, E.product_balance_id, E.product_balance_stock_id,    Y.record_date, Y.record_time,
  34.                COALESCE(F.gross_sell_price, G.gross_sell_price, 0) AS gross_sell_price,
  35.                COALESCE(F.curr_code, G.curr_code, '') AS curr_code,
  36.                COALESCE(F.flg_tax_amount, G.flg_tax_amount) as flg_tax_amount,
  37.                COALESCE(F.tax_id, G.tax_id) as tax_id,
  38.                COALESCE(F.sell_price, G.sell_price, 0) as sell_price,
  39.                X.create_username as username, Y.remark_cashier
  40.             FROM m_medical_record_product X
  41.            JOIN m_prescription_balance_item I ON I.medical_record_product_id = X.medical_record_product_id            
  42.            JOIN m_medical_record Y ON Y.medical_record_id = X.medical_record_id
  43.            JOIN m_salesman Z ON Z.short_name = X.create_username
  44.            JOIN m_product A ON A.product_id = X.product_id
  45.            JOIN m_ctgr_product B ON B.ctgr_product_id = A.ctgr_product_id
  46.            JOIN m_group_product C ON C.group_product_id = B.group_product_id
  47.                AND C.group_product_code = :groupProductCode
  48.            JOIN m_uom H ON H.uom_id = A.base_uom_id
  49.            LEFT JOIN in_product_balance D ON D.product_id = A.product_id
  50.            LEFT JOIN in_product_balance_stock E ON E.product_balance_id = D.product_balance_id
  51.                AND E.product_id = D.product_id
  52.                AND E.warehouse_id = :warehouseId
  53.                AND E.product_status = 'GOOD'    
  54.                AND E.record_owner_id = :recordOwnerId            
  55.            LEFT JOIN m_sell_price_product_for_so F ON F.product_id = A.product_id AND :date BETWEEN F.date_from AND F.date_to AND F.ou_id = :ouId
  56.                AND F.price_level = :priceLevel
  57.            LEFT JOIN m_sell_price_product_for_so G ON G.product_id = A.product_id AND :date BETWEEN G.date_from AND G.date_to
  58.                AND G.ou_id = (f_get_ou_bu_structure_custom(:ouId)).ou_bu_id AND G.price_level = :priceLevel
  59.            WHERE Y.consultation_queue_id = :consultationQueueId
  60.                AND Y.record_date = :date AND Y.patient_id = :patientId
  61.                AND I.qty_redeem = 0 AND I.active = 'Y'
  62.            ORDER BY Y.record_time ASC";
  63.  
  64.             $medicalRecordProduct = DB::select(DB::raw($raw), [
  65.                 "warehouseId"           => $recordOwner->warehouse_id,
  66.                 "ouId"                  => $recordOwnerId,            
  67.                 "priceLevel"            => $customer->price_level,
  68.                 "date"                  => $dateNow,            
  69.                 "patientId"             => $queue->patient_id,
  70.                 "recordOwnerId"         => $recordOwnerId,
  71.                 "groupProductCode"      => 'FG',    
  72.                 "consultationQueueId"   => $queue->consultation_queue_id
  73.             ]);
  74.  
  75.         // Ambil data pasien
  76.         $builder_patient = new QueryBuilder();
  77.         $builder_patient->add(" SELECT A.patient_id, A.salutation, A.short_name, A.fullname, A.place_of_birth,  
  78.                        A.date_of_birth, A.gender, f_get_full_current_address_patient(A.patient_id) AS full_address ")
  79.             ->add(" FROM ")->add(Patient::getTableName())->add(" A ")
  80.             ->add(" WHERE A.patient_id = :patientId ");
  81.  
  82.         $query_builder_patient = new CreateNativeQuery($builder_patient->toString());
  83.         $query_builder_patient->setParameter("patientId", $patient->patient_id);
  84.  
  85.         $result_patient = $query_builder_patient->getSingleResult();
  86.  
  87.         return [
  88.             'medical_record_product_list'   => $medicalRecordProduct,
  89.             'customer'                      => $customer,
  90.             'patient'                       => !is_null($result_patient) ? $result_patient : [],
  91.             'name_with_salutation'          => !is_null($patient) ? $patient->salutation.' - '.$patient->short_name.', '.$patient->fullname  : '',
  92.             'current_address'               => !is_null($result_patient) ? $result_patient->full_address : '',
  93.             'remark_cashier'                => !is_null($medicalRecord) ? $medicalRecord->remark_cashier : '',
  94.             'queue'                         => $queue
  95.         ];                    
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement