Skip to content

Commit 1f9569a

Browse files
committed
Fixes for null pointers
1 parent 97e0aac commit 1f9569a

File tree

2 files changed

+89
-8
lines changed

2 files changed

+89
-8
lines changed

ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ public Integer call() throws Exception {
209209
var repository = createRepository(
210210
fhirContext,
211211
terminologyPath,
212-
modelPath,
213-
library.context != null ? library.context.contextValue : null);
212+
modelPath);
214213
var engine = Engines.forRepositoryAndSettings(
215214
evaluationSettings, repository, null, new NpmProcessor(igContext), true);
216215

@@ -239,24 +238,30 @@ public Integer call() throws Exception {
239238
}
240239

241240
private Repository createRepository(
242-
FhirContext fhirContext, String terminologyUrl, String modelUrl, String contextValue) {
241+
FhirContext fhirContext, String terminologyUrl, String modelUrl) {
243242
Repository data = null;
244243
Repository terminology = null;
245244

245+
if (terminologyUrl == null && modelUrl == null) {
246+
return new NoOpRepository(fhirContext);
247+
}
248+
246249
if (modelUrl != null) {
247250
Path path = Path.of(modelUrl);
248-
if (contextValue != null && !path.endsWith(contextValue)) {
249-
path = path.resolve(contextValue);
250-
}
251-
252251
data = new IgRepository(fhirContext, path);
253252
}
253+
else {
254+
data = new NoOpRepository(fhirContext);
255+
}
254256

255257
if (terminologyUrl != null) {
256258
terminology = new IgRepository(fhirContext, Paths.get(terminologyUrl));
257259
}
260+
else {
261+
terminology = new NoOpRepository(fhirContext);
262+
}
258263

259-
return new ProxyRepository(data, null, terminology);
264+
return new ProxyRepository(data, data, terminology);
260265
}
261266

262267
@SuppressWarnings("java:S106") // We are intending to output to the console here as a CLI tool
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.opencds.cqf.cql.ls.server.command;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.Set;
7+
8+
import org.hl7.fhir.instance.model.api.IBaseBundle;
9+
import org.hl7.fhir.instance.model.api.IBaseParameters;
10+
import org.hl7.fhir.instance.model.api.IBaseResource;
11+
import org.hl7.fhir.instance.model.api.IIdType;
12+
import org.opencds.cqf.fhir.api.Repository;
13+
14+
import ca.uhn.fhir.context.FhirContext;
15+
import ca.uhn.fhir.context.api.BundleInclusionRule;
16+
import ca.uhn.fhir.model.api.IQueryParameterType;
17+
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
18+
import ca.uhn.fhir.rest.api.MethodOutcome;
19+
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
20+
21+
public class NoOpRepository implements Repository {
22+
23+
private final FhirContext fhirContext;
24+
25+
public NoOpRepository(FhirContext fhirContext) {
26+
this.fhirContext = fhirContext;
27+
}
28+
29+
@Override
30+
public <T extends IBaseResource> MethodOutcome create(T arg0, Map<String, String> arg1) {
31+
throw new UnsupportedOperationException("Unimplemented method 'create'");
32+
}
33+
34+
@Override
35+
public <T extends IBaseResource, I extends IIdType> MethodOutcome delete(Class<T> arg0, I arg1,
36+
Map<String, String> arg2) {
37+
throw new UnsupportedOperationException("Unimplemented method 'delete'");
38+
}
39+
40+
@Override
41+
public FhirContext fhirContext() {
42+
return this.fhirContext;
43+
}
44+
45+
@Override
46+
public <R extends IBaseResource, P extends IBaseParameters, T extends IBaseResource> R invoke(Class<T> arg0,
47+
String arg1, P arg2, Class<R> arg3, Map<String, String> arg4) {
48+
throw new UnsupportedOperationException("Unimplemented method 'invoke'");
49+
}
50+
51+
@Override
52+
public <R extends IBaseResource, P extends IBaseParameters, I extends IIdType> R invoke(I arg0, String arg1, P arg2,
53+
Class<R> arg3, Map<String, String> arg4) {
54+
throw new UnsupportedOperationException("Unimplemented method 'invoke'");
55+
}
56+
57+
@Override
58+
public <T extends IBaseResource, I extends IIdType> T read(Class<T> arg0, I arg1, Map<String, String> arg2) {
59+
throw new ResourceNotFoundException(arg1);
60+
}
61+
62+
@SuppressWarnings("unchecked")
63+
@Override
64+
public <B extends IBaseBundle, T extends IBaseResource> B search(Class<B> arg0, Class<T> arg1,
65+
Map<String, List<IQueryParameterType>> arg2, Map<String, String> arg3) {
66+
var factory = this.fhirContext.newBundleFactory();
67+
factory.addResourcesToBundle(Collections.emptyList(), BundleTypeEnum.SEARCHSET, "", BundleInclusionRule.BASED_ON_INCLUDES, Set.of());
68+
return (B)factory.getResourceBundle();
69+
}
70+
71+
@Override
72+
public <T extends IBaseResource> MethodOutcome update(T arg0, Map<String, String> arg1) {
73+
throw new UnsupportedOperationException("Unimplemented method 'update'");
74+
}
75+
76+
}

0 commit comments

Comments
 (0)