高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
@isTest
private class OpdAmountBatchTest {
 
    static testMethod void myUnitTest1() {
         ControllerUtil.EscapeNFM001Trigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        List<Account2__c> acc2List = [select id from Account2__c where Account_org__c = :section.Id];
        Account2__c acc2 = acc2List[0];
        acc2.OPD_290Miro_BF__c = 0;
        acc2.OPD_290Miro_GI__c = 0;
        acc2.OPD_3D__c = 1;
        acc2.OPD_CV_170__c = 2;
        acc2.OPD_CV_190__c = 3;
        acc2.OPD_CV_290__c = 4;
        acc2.OPD_EU_ME2__c = 5;
        acc2.OPD_OTV_S190__c = 6;
        acc2.OPD_STMS__c = 7;
        acc2.OPD_GW__c = 8;
        update acc2;
 
        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new OpdAmountBatch(), 10);
        System.Test.StopTest();
 
        List<Account_Number_of_target__c> atList = [select id,
                                                           OPD_amount_290Miro__c,
                                                           OPD_amount_3D__c,
                                                           OPD_amount_CV170__c,
                                                           OPD_amount_CV190__c,
                                                           OPD_amount_CV290__c,
                                                           OPD_amount_EUME2__c,
                                                           OPD_amount_OTVS190__c,
                                                           OPD_amount_USG400__c,
                                                           OPD_amount_GW__c
                                                      from Account_Number_of_target__c
                                                     where Account__c = :section.Id];
        //System.assertEquals(0, atList[0].OPD_amount_290Miro__c);
        //System.assertEquals(1, atList[0].OPD_amount_3D__c);
        //System.assertEquals(2, atList[0].OPD_amount_CV170__c);
        //System.assertEquals(3, atList[0].OPD_amount_CV190__c);
        //System.assertEquals(4, atList[0].OPD_amount_CV290__c);
        //System.assertEquals(5, atList[0].OPD_amount_EUME2__c);
        //System.assertEquals(6, atList[0].OPD_amount_OTVS190__c);
        //System.assertEquals(7, atList[0].OPD_amount_USG400__c);
        //System.assertEquals(8, atList[0].OPD_amount_GW__c);
 
        execBTId = Database.executeBatch(new OpdAmountBatch(), 10);
    }
    static testMethod void myUnitTest2() {
         ControllerUtil.EscapeNFM001Trigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        List<Account2__c> acc2List = [select id from Account2__c where Account_org__c = :section.Id];
        Account2__c acc2 = acc2List[0];
        acc2.OPD_290Miro_BF__c = 0;
        acc2.OPD_290Miro_GI__c = 0;
        acc2.OPD_3D__c = 1;
        acc2.OPD_CV_170__c = 2;
        acc2.OPD_CV_190__c = 3;
        acc2.OPD_CV_290__c = 4;
        acc2.OPD_EU_ME2__c = 5;
        acc2.OPD_OTV_S190__c = 6;
        acc2.OPD_STMS__c = 7;
        acc2.OPD_GW__c = 8;
        update acc2;
 
        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new OpdAmountBatch(), 10);
        System.Test.StopTest();
 
        List<Account_Number_of_target__c> atList = [select id,
                                                           OPD_amount_290Miro__c,
                                                           OPD_amount_3D__c,
                                                           OPD_amount_CV170__c,
                                                           OPD_amount_CV190__c,
                                                           OPD_amount_CV290__c,
                                                           OPD_amount_EUME2__c,
                                                           OPD_amount_OTVS190__c,
                                                           OPD_amount_USG400__c,
                                                           OPD_amount_GW__c
                                                      from Account_Number_of_target__c
                                                     where Account__c = :section.Id];
        //System.assertEquals(0, atList[0].OPD_amount_290Miro__c);
        //System.assertEquals(1, atList[0].OPD_amount_3D__c);
        //System.assertEquals(2, atList[0].OPD_amount_CV170__c);
        //System.assertEquals(3, atList[0].OPD_amount_CV190__c);
        //System.assertEquals(4, atList[0].OPD_amount_CV290__c);
        //System.assertEquals(5, atList[0].OPD_amount_EUME2__c);
        //System.assertEquals(6, atList[0].OPD_amount_OTVS190__c);
        //System.assertEquals(7, atList[0].OPD_amount_USG400__c);
        //System.assertEquals(8, atList[0].OPD_amount_GW__c);
 
        execBTId = Database.executeBatch(new OpdAmountBatch(true), 10);
    }
    static testMethod void myUnitTest3() {
         ControllerUtil.EscapeNFM001Trigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        List<Account2__c> acc2List = [select id from Account2__c where Account_org__c = :section.Id];
        Account2__c acc2 = acc2List[0];
        acc2.OPD_290Miro_BF__c = 0;
        acc2.OPD_290Miro_GI__c = 0;
        acc2.OPD_3D__c = 1;
        acc2.OPD_CV_170__c = 2;
        acc2.OPD_CV_190__c = 3;
        acc2.OPD_CV_290__c = 4;
        acc2.OPD_EU_ME2__c = 5;
        acc2.OPD_OTV_S190__c = 6;
        acc2.OPD_STMS__c = 7;
        acc2.OPD_GW__c = 8;
        update acc2;
 
        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new OpdAmountBatch(), 10);
        System.Test.StopTest();
 
        List<Account_Number_of_target__c> atList = [select id,
                                                           OPD_amount_290Miro__c,
                                                           OPD_amount_3D__c,
                                                           OPD_amount_CV170__c,
                                                           OPD_amount_CV190__c,
                                                           OPD_amount_CV290__c,
                                                           OPD_amount_EUME2__c,
                                                           OPD_amount_OTVS190__c,
                                                           OPD_amount_USG400__c,
                                                           OPD_amount_GW__c
                                                      from Account_Number_of_target__c
                                                     where Account__c = :section.Id];
        //System.assertEquals(0, atList[0].OPD_amount_290Miro__c);
        //System.assertEquals(1, atList[0].OPD_amount_3D__c);
        //System.assertEquals(2, atList[0].OPD_amount_CV170__c);
        //System.assertEquals(3, atList[0].OPD_amount_CV190__c);
        //System.assertEquals(4, atList[0].OPD_amount_CV290__c);
        //System.assertEquals(5, atList[0].OPD_amount_EUME2__c);
        //System.assertEquals(6, atList[0].OPD_amount_OTVS190__c);
        //System.assertEquals(7, atList[0].OPD_amount_USG400__c);
        //System.assertEquals(8, atList[0].OPD_amount_GW__c);
 
        execBTId = Database.executeBatch(new OpdAmountBatch(company.Id), 10);
    }
    static testMethod void caseTest() {
        ControllerUtil.EscapeNFM001Trigger = true;
        /*Boolean ManuallyUpdateFlag = true;
        Date today = date.today();
        Integer year = today.year();
        Date startDate = date.newInstance(year, 1, 4);
        Date endDate  = date.newInstance(year, 2, 1);
        String todayStr = NFMUtil.formatDate2Str(today);
        String startDateStr = NFMUtil.formatDate2Str(startDate);
        String endDateStr = NFMUtil.formatDate2Str(endDate);*/
        String PerformDate = '2020年度';
        List<RecordType> caseCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (caseCo.size() == 0) {
            return;
        }
        List<RecordType> caseSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (caseSct.size() == 0) {
            return;
        }
        
        Account company = new Account();
        company.RecordTypeId    = caseCo[0].Id;
        company.Name            = '医院';
        company.OCM_Category__c = 'H0';
        company.Is_Active__c    = '有效';
        upsert company;
 
        Account section = new Account();
        section.RecordTypeId = caseSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c    = '呼吸科';
        section.ParentId                     = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
 
        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new OpdAmountBatch(company.Id,PerformDate), 20);
        System.Test.StopTest();
 
        List<Account_Number_of_case__c> atList = [select id,
                                                         OCM_Year__c,
                                                         OCM_Period__c,
                                                         Account_HP__c,
                                                         RecordTypeid,
                                                         Case_name__c
                                                      from Account_Number_of_case__c
                                                     where Account__c = :section.Id];
        System.debug('atList:'+atList);
        //execBTId = Database.executeBatch(new OpdAmountBatch(company.Id), 20);
    }
 
    static testMethod void caseTest2() {
        ControllerUtil.EscapeNFM001Trigger = true;
        /*Boolean ManuallyUpdateFlag = true;
        Date today = date.today();
        Integer year = today.year();
        Date startDate = date.newInstance(year, 1, 4);
        Date endDate  = date.newInstance(year, 2, 1);
        String todayStr = NFMUtil.formatDate2Str(today);
        String startDateStr = NFMUtil.formatDate2Str(startDate);
        String endDateStr = NFMUtil.formatDate2Str(endDate);*/
        String PerformDate = '2020年度';
        List<RecordType> caseCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (caseCo.size() == 0) {
            return;
        }
        List<RecordType> caseSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (caseSct.size() == 0) {
            return;
        }
        
        Account company = new Account();
        company.RecordTypeId    = caseCo[0].Id;
        company.Name            = '医院';
        company.OCM_Category__c = 'H0';
        company.Is_Active__c    = '有效';
        upsert company;
 
        Account section = new Account();
        section.RecordTypeId = caseSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c    = '呼吸科';
        section.ParentId                     = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
 
        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new OpdAmountBatch(company.Id,PerformDate), 20);
        System.Test.StopTest();
 
        List<Account_Number_of_case__c> atList = [select id,
                                                         OCM_Year__c,
                                                         OCM_Period__c,
                                                         Account_HP__c,
                                                         RecordTypeid,
                                                         Case_name__c
                                                      from Account_Number_of_case__c
                                                     where Account__c = :section.Id];
        System.debug('atList:'+atList);
        execBTId = Database.executeBatch(new OpdAmountBatch(true,true), 20);
    }
 
}