高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
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
@isTest
private class PAEDecisionRecordTriggerTest {
    public PAEDecisionRecordTriggerTest() {
 
    }
 
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    static Account createHospital( String hospitalName) {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'HP'].id;
        hospital.Name = hospitalName;
        insert hospital;
        StaticParameter.EscapeAccountTrigger = true;
        return hospital;
    }
 
    static List<Account> selectStrategicDep( Account hospital) {
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        return strategicDep;
    }
 
    static Account createDep( Account hospital, Account strategicDep) {
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep.Id;
        dep.Department_Class__c = strategicDep.Id;
        dep.Hospital__c = hospital.Id;
        // dep.State_Text__c = '上海市';
        insert dep;
        return dep;
    }
 
    static Asset createAsset( Account hospital, Account strategicDep, Account dep) {
        // 製品を作る
        Product2 productA = new Product2( Name = 'テスト商品');
        insert productA;
 
        // 価格表エントリを作成する
        PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = productA.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        entry.Product2Id = productA.Id;
        insert entry;
 
        // 納入機器を作成する
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dep.Id;
        asset.Department_Class__c = strategicDep.Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        asset.Quantity = 3;
        // asset.Extend_Gurantee_DateTo_Text__c =Date.today().addDays(30);
        // asset.IS_Extend_Gurantee_Txt__c =true;
        // asset.Order_No__c = 'BJ_2020';
 
        insert asset;
 
        return asset;
    }
 
    @isTest
    static void myTest(){
 
        ControllerUtil.EscapeNFM001Trigger = true;
 
        //  病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
 
        // 納入機器を作る
        Asset asset = createAsset( hospital, strategicDep[0], dep);
 
        // 修理を作成する01
        Repair__c re = new Repair__c();
        re.SAPRepairNo__c = '000010168255';
        re.Account__c = dep.Id;
        re.Department_Class__c = strategicDep[0].Id;
        re.Hospital__c = hospital.Id;
        re.Delivered_Product__c = asset.Id;
        re.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -1000); // 维修合同判断日がサービス契約のだいぶ前
        re.Failure_Occurrence_Date__c  = Date.today();
        re.InspectionCategory_Three__c = '3';
        re.IISE_Inspection_Branch_Three__c = '1';
        insert re;
 
        PAE_DecisionRecord__c record = new PAE_DecisionRecord__c(
            PAE_DetermineResults__c = 'nonPAE',                    // PAE判定结果
            PAE_ConfirmationDate__c = Date.valueOf('2020-05-06'),  // OCSM QARA确认日
            PAE_Authenticator__c = '00510000005sEEM'              // OCSM QARA确认者
        );
        record.PAE_Repair__c = re.Id;
        record.RecordTypeId = Schema.SObjectType.PAE_DecisionRecord__c.getRecordTypeInfosByDeveloperName().get('ASACDecision').getRecordTypeId();
        record.PAE_DetermineResults_Text__c = 'nonPAE';
        insert record;
 
        record.PAE_DetermineResults_Text__c = 'PAE';
        update record;
 
        List<PAE_DecisionRecord__c> recordList = [select id,name,PAE_DetermineResults_Text__c from PAE_DecisionRecord__c];
        System.debug('recordList++'+recordList);
 
    }
 
 
    @isTest
    static void myTest_QIS(){
 
        ControllerUtil.EscapeNFM001Trigger = true;
 
        //  病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
 
        // 納入機器を作る
        Asset asset = createAsset( hospital, strategicDep[0], dep);
 
 
        QIS_Report__c qis = new QIS_Report__c();
        qis.nonyushohin__c = asset.Id;
        qis.Hospital__c = hospital.Id;
        qis.RC__c = UserInfo.getUserId();
        qis.Department_Class__c = strategicDep[0].Id;
        qis.Hospital_Department__c = dep.Id;
        qis.Damage_For_Doc_Or_Pat__c = '有';
        qis.Relation_With_The_Problem__c = '有可能';
        qis.Report_For_Goz__c = '不知道';
        insert qis;
 
 
        // 修理を作成する01
        // Repair__c re = new Repair__c();
        // re.SAPRepairNo__c = '000010168255';
        // re.Account__c = dep.Id;
        // re.Department_Class__c = strategicDep[0].Id;
        // re.Hospital__c = hospital.Id;
        // re.Delivered_Product__c = asset.Id;
        // re.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -1000); // 维修合同判断日がサービス契約のだいぶ前
        // re.Failure_Occurrence_Date__c  = Date.today();
        // re.InspectionCategory_Three__c = '3';
        // re.IISE_Inspection_Branch_Three__c = '1';
        // insert re;
 
        PAE_DecisionRecord__c record = new PAE_DecisionRecord__c(
            PAE_DetermineResults__c = 'nonPAE',                    // PAE判定结果
            PAE_ConfirmationDate__c = Date.valueOf('2020-05-06'),  // OCSM QARA确认日
            PAE_Authenticator__c = '00510000005sEEM'              // OCSM QARA确认者
        );
        record.PAE_QIS__c = qis.Id;
        record.RecordTypeId = Schema.SObjectType.PAE_DecisionRecord__c.getRecordTypeInfosByDeveloperName().get('ASACDecision').getRecordTypeId();
        record.PAE_DetermineResults_Text__c = 'nonPAE';
        insert record;
 
        record.PAE_DetermineResults_Text__c = 'PAE';
        update record;
 
        List<PAE_DecisionRecord__c> recordList = [select id,name,PAE_DetermineResults_Text__c from PAE_DecisionRecord__c];
        System.debug('recordList++'+recordList);
 
    }
 
    @isTest
    static void myTest_report(){
 
        // recode type を取得
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 病院 recodetype');
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            throw new ControllerUtil.myException('not found 戦略科室分類 呼吸科 recodetype');
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
        }
        
        // insert
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name = 'Katsu テスト';
        insert 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;
        NFM001Controller.isRunning = false;
        NFM001Controller.debug_msg = '';
        insert section;
 
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM001TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        NFM001Controller.isRunning = false;
        NFM001Controller.debug_msg = '';
        insert depart;
        
        // insert test
        Report__c rpt = new Report__c();
        rpt.Hospital_Department__c = depart.Id;
        rpt.OwnerId = UserInfo.getUserId();
        rpt.OPD_ProductCategory1__c ='3D System';
        rpt.OPD_ProductCategory2__c ='OR Imaging Products';
        insert new Report__c[] {rpt};
 
 
        // 修理を作成する01
        // Repair__c re = new Repair__c();
        // re.SAPRepairNo__c = '000010168255';
        // re.Account__c = dep.Id;
        // re.Department_Class__c = strategicDep[0].Id;
        // re.Hospital__c = hospital.Id;
        // re.Delivered_Product__c = asset.Id;
        // re.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -1000); // 维修合同判断日がサービス契約のだいぶ前
        // re.Failure_Occurrence_Date__c  = Date.today();
        // re.InspectionCategory_Three__c = '3';
        // re.IISE_Inspection_Branch_Three__c = '1';
        // insert re;
 
        PAE_DecisionRecord__c record = new PAE_DecisionRecord__c(
            PAE_DetermineResults__c = 'nonPAE',                    // PAE判定结果
            PAE_ConfirmationDate__c = Date.valueOf('2020-05-06'),  // OCSM QARA确认日
            PAE_Authenticator__c = '00510000005sEEM'              // OCSM QARA确认者
        );
        record.PAE_Report__c = rpt.Id;
        record.RecordTypeId = Schema.SObjectType.PAE_DecisionRecord__c.getRecordTypeInfosByDeveloperName().get('ASACDecision').getRecordTypeId();
        record.PAE_DetermineResults_Text__c = 'nonPAE';
        insert record;
 
        record.PAE_DetermineResults_Text__c = 'PAE';
        update record;
 
        List<PAE_DecisionRecord__c> recordList = [select id,name,PAE_DetermineResults_Text__c from PAE_DecisionRecord__c];
        System.debug('recordList++'+recordList);
 
    }
 
}