|
1 | 1 | package ca.uhn.fhir.jpa.starter.cdshooks;
|
2 | 2 |
|
| 3 | +import ca.uhn.fhir.context.FhirVersionEnum; |
3 | 4 | import ca.uhn.fhir.rest.api.server.RequestDetails;
|
4 | 5 | import ca.uhn.fhir.rest.api.server.cdshooks.CdsServiceRequestJson;
|
5 | 6 | import ca.uhn.hapi.fhir.cdshooks.api.ICdsConfigService;
|
6 |
| -import org.hl7.fhir.r4.model.BooleanType; |
7 |
| -import org.hl7.fhir.r4.model.Parameters; |
| 7 | +import org.hl7.fhir.instance.model.api.IBaseParameters; |
| 8 | +import org.hl7.fhir.instance.model.api.IPrimitiveType; |
8 | 9 | import org.opencds.cqf.fhir.api.Repository;
|
9 | 10 | import org.opencds.cqf.fhir.cr.hapi.cdshooks.CdsCrService;
|
| 11 | +import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory; |
10 | 12 |
|
11 | 13 | import static org.opencds.cqf.fhir.utility.Constants.APPLY_PARAMETER_DATA;
|
12 |
| -import static org.opencds.cqf.fhir.utility.r4.Parameters.part; |
13 | 14 |
|
14 | 15 | public class UpdatedCdsCrService extends CdsCrService {
|
| 16 | + private final IAdapterFactory adapterFactory; |
| 17 | + |
15 | 18 | public UpdatedCdsCrService(
|
16 | 19 | RequestDetails theRequestDetails, Repository theRepository, ICdsConfigService theCdsConfigService) {
|
17 | 20 | super(theRequestDetails, theRepository, theCdsConfigService);
|
| 21 | + adapterFactory = IAdapterFactory.forFhirContext(theRepository.fhirContext()); |
18 | 22 | }
|
19 | 23 |
|
20 | 24 | @Override
|
21 |
| - public Parameters encodeParams(CdsServiceRequestJson theJson) { |
22 |
| - var parameters = (Parameters) super.encodeParams(theJson); |
| 25 | + public IBaseParameters encodeParams(CdsServiceRequestJson theJson) { |
| 26 | + var parameters = adapterFactory.createParameters(super.encodeParams(theJson)); |
23 | 27 | if (parameters.hasParameter(APPLY_PARAMETER_DATA)) {
|
24 |
| - parameters.addParameter(part("useServerData", new BooleanType(false))); |
| 28 | + parameters.addParameter( |
| 29 | + "useServerData", |
| 30 | + booleanTypeForVersion(parameters.fhirContext().getVersion().getVersion(), false)); |
25 | 31 | }
|
26 |
| - return parameters; |
| 32 | + return (IBaseParameters) parameters.get(); |
| 33 | + } |
| 34 | + |
| 35 | + private IPrimitiveType<Boolean> booleanTypeForVersion(FhirVersionEnum fhirVersion, boolean value) { |
| 36 | + return switch (fhirVersion) { |
| 37 | + case DSTU2 -> new org.hl7.fhir.dstu2.model.BooleanType(value); |
| 38 | + case DSTU3 -> new org.hl7.fhir.dstu3.model.BooleanType(value); |
| 39 | + case R4 -> new org.hl7.fhir.r4.model.BooleanType(value); |
| 40 | + case R5 -> new org.hl7.fhir.r5.model.BooleanType(value); |
| 41 | + default -> throw new IllegalArgumentException("unknown or unsupported FHIR version"); |
| 42 | + }; |
27 | 43 | }
|
28 | 44 | }
|
0 commit comments