package thyyxxk.webserver.dao.his.inpatient.casefrontsheet;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.casefrontsheet.CaseFrontsheetDisdiag;
import thyyxxk.webserver.entity.casefrontsheet.CaseFrontsheetMain;
import thyyxxk.webserver.entity.casefrontsheet.CaseFrontsheetSurgery;

import java.util.List;

@Mapper
public interface FrontSheetExportDao {

    @Select("select bah,admiss_times,pay_method,health_card_no,name,sex,birth_date,age,country,age_days,new_born_weight, " +
            "new_born_admiss_weight,birth_place,birth_place_name,native_place,native_place_name,nation,social_no, " +
            "occupation,marriage,live_place,phone,addr_zip_code,hk_place,hk_place_name,hk_zip_code,unit_name,unit_place, " +
            "unit_phone,unit_zip_code,contact_name,contact_relation,contact_addr,contact_addr_name,contact_phone, " +
            "zy_admiss_way,has_surgery,admiss_date,admiss_dept,admiss_ward,trans_dept,dismiss_date,dismiss_dept, " +
            "dismiss_ward,admiss_days,hurt_reason_name,hurt_reason_code,pathologic_diag_str,main_disdiag_status, " +
            "pathologic_diag_code,blh,allergy,allergic_medicine,autopsy,hbs_ag,hcv_ab,hiv_ab,tp_ab,blood_type,rh, " +
            "dept_leader,leader_doctor,main_doctor,admiss_doctor,duty_nurse,study_doctor,internship_doctor,coder, " +
            "dept_leader_name,leader_doctor_name,main_doctor_name,admiss_doctor_name,duty_nurse_name,study_doctor_name, " +
            "internship_doctor_name,coder_name,quality_control_level,quality_control_doctor,quality_control_nurse, " +
            "quality_control_doctor_name,quality_control_nurse_name,quality_control_date,zy_dismiss_way, " +
            "dismiss_destination,admiss_again_in_one_month,admiss_again_purpose,coma_days_before_admiss, " +
            "coma_hours_before_admiss,coma_minutes_before_admiss,coma_days_after_admiss,coma_hours_after_admiss, " +
            "coma_minutes_after_admiss,total_cost=cast(total_cost as decimal(16,2)), " +
            "self_pay=cast(self_pay as decimal(16,2)), " +
            "general_medical_service_fee=cast(general_medical_service_fee as decimal(16,2)), " +
            "general_treatment_operating_fee=cast(general_treatment_operating_fee as decimal(16,2)), " +
            "care_fee=cast(care_fee as decimal(16,2)),else_fee=cast(else_fee as decimal(16,2)), " +
            "pathologic_diag_fee=cast(pathologic_diag_fee as decimal(16,2)), " +
            "experiment_diag_fee=cast(experiment_diag_fee as decimal(16,2)), " +
            "ct_diag_fee=cast(ct_diag_fee as decimal(16,2)), " +
            "clinical_diag_fee=cast(clinical_diag_fee as decimal(16,2)), " +
            "not_surgical_fee=cast(not_surgical_fee as decimal(16,2)), " +
            "clinical_physical_fee=cast(clinical_physical_fee as decimal(16,2)), " +
            "surgical_fee=cast(surgical_fee as decimal(16,2)), " +
            "anesthetize_fee=cast(anesthetize_fee as decimal(16,2)), " +
            "surgery_fee=cast(surgery_fee as decimal(16,2)), " +
            "recover_fee=cast(recover_fee as decimal(16,2)), " +
            "tcm_treatment_fee=cast(tcm_treatment_fee as decimal(16,2)), " +
            "west_medicine_fee=cast(west_medicine_fee as decimal(16,2)), " +
            "chinese_patent_medicine_fee=cast(chinese_patent_medicine_fee as decimal(16,2)), " +
            "chinese_herbal_medicine_fee=cast(chinese_herbal_medicine_fee as decimal(16,2)), " +
            "blood_fee=cast(blood_fee as decimal(16,2)), " +
            "albumin_products_fee=cast(albumin_products_fee as decimal(16,2)), " +
            "globulin_products_fee=cast(globulin_products_fee as decimal(16,2)), " +
            "coagulation_factor_products_fee=cast(coagulation_factor_products_fee as decimal(16,2)), " +
            "cytokine_products_fee=cast(cytokine_products_fee as decimal(16,2)), " +
            "cost_of_disposable_medical_materials_for_examination=cast(cost_of_disposable_medical_materials_for_examination as decimal(16,2)), " +
            "cost_of_disposable_medical_materials_for_treatment=cast(cost_of_disposable_medical_materials_for_treatment as decimal(16,2)), " +
            "cost_of_disposable_medical_materials_for_operation=cast(cost_of_disposable_medical_materials_for_operation as decimal(16,2)), " +
            "other_fees=cast(other_fees as decimal(16,2)),diag_conform1,diag_conform2,diag_conform3, " +
            "diag_conform4,diag_conform5,rescue_times,rescue_success_times,case_classification,has_icu,icu_days, " +
            "icu_hours,monopathy_management,clinical_pathway_management,drgs_management,use_antibiotic,bacilliculture, " +
            "statutory_epidemic,tumor_level_t,tumor_level_n,tumor_level_m,tumor_level,xxe_apgar,responce_type, " +
            "responce_type_name,yb_type,yb_type_name,treat_type,treat_type_name,has_infant,med_type, " +
            "admiss_dept_code,admiss_ward_code,trans_dept_code,dismiss_dept_code,dismiss_ward_code,live_place_combo, " +
            "clinicDiagCode=(select top 1 rtrim(code) from zd_icd_code_new where yb_code=clinic_diag_code), " +
            "clinicDiagStr=(select top 1 rtrim(name) from zd_icd_code_new where yb_code=clinic_diag_code) " +
            "from t_case_frontsheet_main where dismiss_date>=#{begin} and dismiss_date<=#{end}")
    List<CaseFrontsheetMain> fetchSheets(@Param("begin") String begin, @Param("end") String end);

    @Select("select no,code,name,admiss_status,dismiss_status from t_case_frontsheet_disdiag where bah=#{bah} and times=#{times}")
    List<CaseFrontsheetDisdiag> fetchDiags(@Param("bah") String bah, @Param("times") int times);

    @Select("select no,date,level,operator,operator_name,assistant_one,assistant_one_name, " +
            "assistant_two,assistant_two_name,cut=isnull(cut,0),heal=isnull(heal,0),anaesthesiaor,anaesthesiaor_name, " +
            "anaesthesia=(select wjw_code from zd_anaesthesia where code=anaesthesia)," +
            "code=(select top 1 rtrim(d.code) from zd_icd9_cm3 d where d.yb_code=a.code order by code), " +
            "name=(select top 1 rtrim(d.name) from zd_icd9_cm3 d where d.yb_code=a.code order by code) " +
            "from t_case_frontsheet_surgery a where bah=#{bah} and times=#{times}")
    List<CaseFrontsheetSurgery> fetchSurgeries(@Param("bah") String bah, @Param("times") int times);
}
