-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
BaseProviderR4Test.java
87 lines (77 loc) · 3.15 KB
/
BaseProviderR4Test.java
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
package ca.uhn.fhir.jpa.mdm.provider;
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test;
import ca.uhn.fhir.jpa.test.Batch2JobHelper;
import ca.uhn.fhir.mdm.api.IMdmControllerSvc;
import ca.uhn.fhir.mdm.api.IMdmSubmitSvc;
import ca.uhn.fhir.mdm.provider.MdmControllerHelper;
import ca.uhn.fhir.mdm.provider.MdmProviderDstu3Plus;
import ca.uhn.fhir.mdm.rules.config.MdmSettings;
import ca.uhn.fhir.mdm.rules.svc.MdmResourceMatcherSvc;
import ca.uhn.fhir.mdm.util.MessageHelper;
import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.r4.hapi.rest.server.helper.BatchHelperR4;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public abstract class BaseProviderR4Test extends BaseMdmR4Test {
protected MdmProviderDstu3Plus myMdmProvider;
@Autowired
private IMdmControllerSvc myMdmControllerSvc;
@Autowired
private IMdmSubmitSvc myMdmSubmitSvc;
@Autowired
protected MdmSettings myMdmSettings;
@Autowired
protected MdmResourceMatcherSvc myMdmResourceMatcherSvc;
@Autowired
private MdmControllerHelper myMdmHelper;
@Autowired
Batch2JobHelper myBatch2JobHelper;
@Autowired
MessageHelper myMessageHelper;
private String defaultScript;
protected void setMdmRuleJson(String theString) throws IOException {
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
Resource resource = resourceLoader.getResource(theString);
String json = IOUtils.toString(resource.getInputStream(), Charsets.UTF_8);
myMdmSettings.setEnabled(true);
myMdmSettings.setScriptText(json);
myMdmResourceMatcherSvc.setMdmRulesJson(myMdmSettings.getMdmRules());
}
@BeforeEach
public void before() throws Exception {
myMdmProvider = new MdmProviderDstu3Plus(myFhirContext, myMdmControllerSvc, myMdmHelper, myMdmSubmitSvc, myMdmSettings);
defaultScript = myMdmSettings.getScriptText();
}
@Override
@AfterEach
public void after() throws IOException {
super.after();
myMdmSettings.setScriptText(defaultScript);
myMdmResourceMatcherSvc.setMdmRulesJson(myMdmSettings.getMdmRules());
}
protected void clearMdmLinks() {
Parameters result = (Parameters) myMdmProvider.clearMdmLinks(null, null, myRequestDetails);
myBatch2JobHelper.awaitJobCompletion(BatchHelperR4.jobIdFromBatch2Parameters(result));
}
protected void clearMdmLinks(String theResourceName) {
Parameters result = (Parameters) myMdmProvider.clearMdmLinks(getResourceNames(theResourceName), null, myRequestDetails);
myBatch2JobHelper.awaitJobCompletion(BatchHelperR4.jobIdFromBatch2Parameters(result));
}
@Nonnull
protected List<IPrimitiveType<String>> getResourceNames(String theResourceName) {
List<IPrimitiveType<String>> resourceNames = new ArrayList<>();
resourceNames.add(new StringType(theResourceName));
return resourceNames;
}
}