package thyyxxk.webserver.dao.his.covid;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.covid.CovidDetail;
import thyyxxk.webserver.entity.covid.CovidIndex;
import thyyxxk.webserver.entity.covid.Region;

import java.util.List;

@Mapper
public interface CovidDao {
    @Select("select id, name, date from " +
            "t_covid19_assessment with(nolock) where patient_id=#{patientId} order by id")
    List<CovidIndex> getList(@Param("patientId") String patientId);

    @Select("select name, phone, idcard, patient_id patientId, " +
            "addrProvince=(select name from t_region with(nolock) where code=addr_province), " +
            "addrCity=(select name from t_region with(nolock) where code=addr_city), " +
            "addrDistrict=(select name from t_region with(nolock) where code=addr_district), " +
            "addr_additional addrAdditional, temperature, fever_number feverNumber, " +
            "date, item1, item2, item3, item4, item5, " +
            "symptoms symptomsSelect from t_covid19_assessment with(nolock) where id=#{id}")
    CovidDetail getDetail(@Param("id") Integer id);

    @Select("select rtrim(social_no) idcard,rtrim(phone_no) phone,rtrim(name) name " +
            "from mz_patient_mi with(nolock) where patient_id=#{patientId}")
    CovidDetail getPatientInfo(@Param("patientId") String patientId);

    @Select("select code, name from t_region with(nolock) where level=1 and del_flag=0 order by code")
    List<Region> getRegionProvince();

    @Select("select code, name from t_region with(nolock) where parent_code=#{parentCode} and del_flag=0 order by code")
    List<Region> getChildRegion(@Param("parentCode") Integer parentCode);

    @Select("select top 1 datediff(day, date, getdate()) from t_covid19_assessment with(nolock) " +
            "where idcard=#{idcard} or patient_id=#{patientId} order by date desc")
    Integer getDateDiff(@Param("idcard") String idcard, @Param("patientId") String patientId);

    @Insert("insert into t_covid19_assessment (name, phone, idcard, temperature, fever_number, " +
            "date, item1, item2, item3, item4, item5, symptoms, addr_province, addr_city, addr_district, " +
            "addr_additional, patient_id) values " +
            "(#{name},#{phone},#{idcard},#{temperature},#{feverNumber},#{date},#{item1}," +
            "#{item2},#{item3},#{item4},#{item5},#{symptomsSubmit},#{addrProvince},#{addrCity}," +
            "#{addrDistrict},#{addrAdditional},#{patientId})")
    void insertNewCovid19Assessment(CovidDetail pojo);
}
