P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?xml version="1.0" encoding="UTF-8" ?>
    
<sqls>
    <dataSpace name="org">
    
        <sql name="getOrgByHospital">
            <![CDATA[
                 select md_org.*
                 from md_org_hospital
                 inner join md_org on md_org_hospital.parent_id = md_org.id
                 where @{filter} @{orderby} @{limit}
            ]]>    
        </sql>    
    
        <sql name="getPositionLevelHospital">
            <![CDATA[
                 select md_hospital.*
                 from (select * from (
                                      select t1.*, if(find_in_set(ifnull(CONVERT ( parent_id USING utf8mb4 ), ''), @pids) = 0  , null, @pids := concat(@pids, ',', id)) as ischild
                                      from (select * 
                                            from md_position t  
                                            order by parent_id, id) t1, (select @pids := '@{position_id}') t2
                                     ) t3 
                       where (ischild is not null or id ='@{position_id}' )) md_position
                 inner join md_position_hospital on md_position_hospital.position_id = md_position.id
                 inner join md_hospital on md_hospital.id = md_position_hospital.hospital_id
                 where @{filter} @{orderby} @{limit}
            ]]>    
        </sql>    
    
        <sql name="getSoonExpireOrg">
            <![CDATA[
                 select * from (
                                select md_org.code, md_org.name, certificate_date_to, 
                                       if(DATEDIFF(certificate_date_to, now()) <= certificate_day, CONCAT('经销商:', md_org.name,',营业执照还剩余:',DATEDIFF(certificate_date_to, now()), '天过期'), null) as certificate_remind,
                                       DATEDIFF(certificate_date_to, now()) as certificate_day,
                                       instrument_date_to, 
                                       if(DATEDIFF(instrument_date_to, now()) <= instrument_day, CONCAT('经销商:', md_org.name,',器械许可证还剩余:',DATEDIFF(instrument_date_to, now()), '天过期'), null) as instrument_remind,
                                       DATEDIFF(instrument_date_to, now()) as instrument_day
                 from (select * from md_org where state_code = 'Open') md_org
                 left join md_org_register on md_org.id = md_org_register.parent_id
                 left join (select sum(case code when 'certificate' then value end) as certificate_day,
                                    sum(case code when 'instrument' then value end) as instrument_day
                            from sys_config
                            where code in ('certificate','instrument') and type = 'licenceremind'
                            group by type ) sys_config on 1 = 1
                 where (DATEDIFF(certificate_date_to, now()) <= certificate_day or DATEDIFF(instrument_date_to, now()) <= instrument_day)
                 ) licence_remind
                 where @{filter} @{orderby} @{limit}
            ]]>    
        </sql>    
 
        <sql name="getOneOrgTempCapacity">
            <![CDATA[
             select sys_actor_capacity.* from sys_actor_capacity
             where exists (
                 select 1 from md_org
                 where md_org.id = '@{org_id}'
                    and md_org.actor = sys_actor_capacity.actor_id
             )
             and (type_code = 'Temp' or type_code is null or type_code = "")
            ]]>    
        </sql>    
        
        <sql name="getAccountOpening">
            <![CDATA[
                select ifnull(opening.id, UUID_SHORT()) as id, opening.idx as answer_idx, opening.parent_id, opening.criteria_id, 
                       opening.criteria_value, opening.remark,md_org_opening_criteria.id as ask_id, md_org_opening_criteria.idx as ask_idx, 
                       md_org_opening_criteria.content_before, md_org_opening_criteria.content_after, md_org_opening_criteria.content_type, 
                       md_org_opening_criteria.category_code, md_org_opening_criteria.category_name, md_org_opening_criteria.group_code, 
                       md_org_opening_criteria.group_name, md_org_opening_criteria.index_no, md_org_opening_criteria.is_active, 
                       md_org_opening_criteria.classify, md_org_opening_criteria.required_no,
                       md_org_opening_criteria.dictionary_id, md_org_opening_criteria.group_batch_code,
                       md_org_opening_criteria.group_batch_name
                from (
                    select md_org_opening.* 
                    from md_org_opening 
                    left join md_org_opening_criteria on md_org_opening_criteria.id = md_org_opening.criteria_id
                    where md_org_opening.parent_id = @{parent_id}
                    and md_org_opening_criteria.category_code = @{category_code}
                ) opening
                right join md_org_opening_criteria
                        on md_org_opening_criteria.id = opening.criteria_id 
                where md_org_opening_criteria.category_code = @{category_code}
                  and classify = @{classify}
                order by index_no            
            ]]>    
        </sql>
            
    </dataSpace>
    
</sqls>