Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dss/evsrestapi 999 fhir r4 testing #317

Merged
merged 7 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 42 additions & 38 deletions src/main/java/gov/nih/nci/evs/api/fhir/R4/CodeSystemProviderR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,22 @@ public Parameters lookupImplicit(
termUtils.getIndexedTerminology(codeSys.getTitle(), esQueryService);
final Concept conc =
esQueryService.getConcept(codeToLookup, term, new IncludeParam("children")).get();
params.addParameter("code", "code");
params.addParameter("system", codeSys.getUrl());
params.addParameter("code", codeSys.getName());
params.addParameter("version", codeSys.getVersion());
// required in the specification
params.addParameter("name", codeSys.getName());
params.addParameter("display", conc.getName());
params.addParameter("active", true);
// optional in the specification
params.addParameter("version", codeSys.getVersion());
// properties
params.addParameter(FhirUtilityR4.createProperty("active", conc.getActive(), false));
for (final Concept parent : conc.getParents()) {
params.addParameter(FhirUtilityR4.createProperty("parent", parent.getCode(), true));
}
for (final Concept child : conc.getChildren()) {
params.addParameter(FhirUtilityR4.createProperty("child", child.getCode(), true));
}
} else {
params.addParameter("result", false);
params.addParameter("message", "Unable to find matching code system");
params.addParameter("system", (system == null ? new UriType("<null>") : system));
params.addParameter("version", version);
throw FhirUtilityR4.exception(
"Unable to find matching code system", OperationOutcome.IssueType.NOTFOUND, 400);
}
return params;

Expand Down Expand Up @@ -221,29 +220,28 @@ public Parameters lookupInstance(
termUtils.getIndexedTerminology(codeSys.getTitle(), esQueryService);
final Concept conc =
esQueryService.getConcept(codeToLookup, term, new IncludeParam("children")).get();
params.addParameter("code", "code");
params.addParameter("system", codeSys.getUrl());
params.addParameter("code", codeSys.getName());
params.addParameter("version", codeSys.getVersion());
// required in the specification
params.addParameter("name", codeSys.getName());
params.addParameter("display", conc.getName());
params.addParameter("active", true);
// optional in the specification
params.addParameter("version", codeSys.getVersion());
params.addParameter(FhirUtilityR4.createProperty("active", conc.getActive(), false));
for (final Concept parent : conc.getParents()) {
params.addParameter(FhirUtilityR4.createProperty("parent", parent.getCode(), true));
}
for (final Concept child : conc.getChildren()) {
params.addParameter(FhirUtilityR4.createProperty("child", child.getCode(), true));
}
} else {
params.addParameter("result", false);
params.addParameter("message", "Unable to find matching code system");
params.addParameter("system", (system == null ? new UriType("<null>") : system));
params.addParameter("version", version);
throw FhirUtilityR4.exception(
"Unable to find matching code system", OperationOutcome.IssueType.NOTFOUND, 400);
}
return params;

} catch (final FHIRServerResponseException e) {
throw e;
} catch (final Exception e) {
e.printStackTrace();
throw FhirUtilityR4.exception(
"Failed to lookup code", OperationOutcome.IssueType.EXCEPTION, 500);
}
Expand Down Expand Up @@ -318,10 +316,11 @@ public Parameters validateCodeImplicit(
if (check.isPresent()) {
final Concept conc =
esQueryService.getConcept(codeToValidate, term, new IncludeParam("children")).get();
params.addParameter("result", true);
if (display == null || conc.getName().equals(display.getValue())) {
params.addParameter("result", true);
params.addParameter("code", conc.getCode());
} else {
params.addParameter("result", false);
params.addParameter(
"message",
"The code "
Expand All @@ -340,10 +339,8 @@ public Parameters validateCodeImplicit(
params.addParameter("version", codeSys.getVersion());
}
} else {
params.addParameter("result", false);
params.addParameter("message", "Unable to find matching code system");
params.addParameter("url", (url == null ? new UriType("<null>") : url));
params.addParameter("version", version);
throw FhirUtilityR4.exception(
"Unable to find matching code system", OperationOutcome.IssueType.NOTFOUND, 400);
}
return params;

Expand Down Expand Up @@ -421,10 +418,11 @@ public Parameters validateCodeInstance(
if (check.isPresent()) {
final Concept conc =
esQueryService.getConcept(codeToValidate, term, new IncludeParam("children")).get();
params.addParameter("result", true);
if (display == null || conc.getName().equals(display.getValue())) {
params.addParameter("code", conc.getCode());
params.addParameter("result", true);
} else {
params.addParameter("result", false);
params.addParameter(
"message",
"The code "
Expand All @@ -443,10 +441,8 @@ public Parameters validateCodeInstance(
params.addParameter("version", codeSys.getVersion());
}
} else {
params.addParameter("result", false);
params.addParameter("message", "Unable to find matching code system");
params.addParameter("url", (url == null ? new UriType("<null>") : url));
params.addParameter("version", version);
throw FhirUtilityR4.exception(
"Unable to find matching code system", OperationOutcome.IssueType.NOTFOUND, 400);
}
return params;

Expand Down Expand Up @@ -513,6 +509,12 @@ public Parameters subsumesImplicit(
} else if (codingA != null && codingB != null) {
code1 = codingA.getCode();
code2 = codingB.getCode();
} else if (codeA == null) {
throw FhirUtilityR4.exception(
"No codeA parameter provided in request", OperationOutcome.IssueType.EXCEPTION, 400);
} else if (codeB == null) {
throw FhirUtilityR4.exception(
"No codeB parameter provided in request", OperationOutcome.IssueType.EXCEPTION, 400);
}
final CodeSystem codeSys = cs.get(0);
final Terminology term =
Expand All @@ -533,10 +535,8 @@ public Parameters subsumesImplicit(
}
}
} else {
params.addParameter("result", false);
params.addParameter("message", "Unable to find matching code system");
params.addParameter("system", (system == null ? new UriType("<null>") : system));
params.addParameter("version", version);
throw FhirUtilityR4.exception(
"Unable to find matching code system", OperationOutcome.IssueType.NOTFOUND, 400);
}
return params;

Expand Down Expand Up @@ -605,6 +605,12 @@ public Parameters subsumesInstance(
} else if (codingA != null && codingB != null) {
code1 = codingA.getCode();
code2 = codingB.getCode();
} else if (codeA == null) {
throw FhirUtilityR4.exception(
"No codeA parameter provided in request", OperationOutcome.IssueType.EXCEPTION, 400);
} else if (codeB == null) {
throw FhirUtilityR4.exception(
"No codeB parameter provided in request", OperationOutcome.IssueType.EXCEPTION, 400);
}
final CodeSystem codeSys = cs.get(0);
final Terminology term =
Expand All @@ -616,19 +622,17 @@ public Parameters subsumesInstance(
if (checkA.get() != null && checkB.get() != null) {
params.addParameter("system", codeSys.getUrl());
params.addParameter("version", codeSys.getVersion());
if (esQueryService.getPathsToParent(code1, code2, term).getCt() > 0) {
if (esQueryService.getPathsToParent(code1, code2, term).getPathCount() > 0) {
params.addParameter("outcome", "subsumes");
} else if (esQueryService.getPathsToParent(code2, code1, term).getCt() > 0) {
} else if (esQueryService.getPathsToParent(code2, code1, term).getPathCount() > 0) {
params.addParameter("outcome", "subsumed-by");
} else {
params.addParameter("outcome", "no-subsumption-relationship");
}
}
} else {
params.addParameter("result", false);
params.addParameter("message", "Unable to find matching code system");
params.addParameter("system", (system == null ? new UriType("<null>") : system));
params.addParameter("version", version);
throw FhirUtilityR4.exception(
"Unable to find matching code system", OperationOutcome.IssueType.NOTFOUND, 400);
}
return params;

Expand Down
47 changes: 37 additions & 10 deletions src/main/java/gov/nih/nci/evs/api/fhir/R4/ValueSetProviderR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.hl7.fhir.r4.model.ValueSet;
import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -173,7 +174,9 @@ public ValueSet expandImplicit(
final List<ValueSet> vsList = findPossibleValueSets(null, null, url, version);
if (vsList.size() == 0) {
throw FhirUtilityR4.exception(
"Value set " + url + " not found", OperationOutcome.IssueType.EXCEPTION, 500);
"Value set " + url.getValueAsString() + " not found",
OperationOutcome.IssueType.EXCEPTION,
500);
}
final ValueSet vs = vsList.get(0);
List<Concept> subsetMembers = new ArrayList<Concept>();
Expand Down Expand Up @@ -225,6 +228,15 @@ public ValueSet expandImplicit(
vsContains.setCode(subset.getCode());
vsContains.setDisplay(subset.getName());
vsExpansion.addContains(vsContains);
ValueSetExpansionParameterComponent vsParameter =
new ValueSetExpansionParameterComponent();
vsParameter.setName("url");
vsParameter.setValue(url);
vsExpansion.addParameter(vsParameter);
vsParameter = new ValueSetExpansionParameterComponent();
vsParameter.setName("version");
vsParameter.setValue(version);
vsExpansion.addParameter(vsParameter);
}
}
vs.setExpansion(vsExpansion);
Expand Down Expand Up @@ -294,8 +306,8 @@ public ValueSet expandInstance(
@OperationParam(name = "contextDirection") final CodeType contextDirection,
@OperationParam(name = "filter") final StringType filter,
@OperationParam(name = "date") final DateTimeType date,
@OperationParam(name = "offset") final IntegerType offset,
@OperationParam(name = "count") final IntegerType count,
@ca.uhn.fhir.rest.annotation.Offset final Integer offset,
@ca.uhn.fhir.rest.annotation.Count final Integer count,
@OperationParam(name = "includeDesignations") final BooleanType includeDesignations,
@OperationParam(name = "designation") final StringType designation,
@OperationParam(name = "includeDefinition") final BooleanType includeDefinition,
Expand All @@ -319,7 +331,7 @@ public ValueSet expandInstance(
try {
// URL is not required because "id" is provided
// FhirUtilityR4.required("url", url);
FhirUtilityR4.notSupported("valueSet", valueSet);
FhirUtilityR4.notSupported("valueSet", null);
FhirUtilityR4.notSupported("context", context);
FhirUtilityR4.notSupported("contextDirection", contextDirection);
FhirUtilityR4.notSupported("date", date);
Expand All @@ -337,7 +349,9 @@ public ValueSet expandInstance(
final List<ValueSet> vsList = findPossibleValueSets(id, null, url, version);
if (vsList.size() == 0) {
throw FhirUtilityR4.exception(
"Value set " + url + " not found", OperationOutcome.IssueType.EXCEPTION, 500);
"Value set " + url.getValueAsString() + " not found",
OperationOutcome.IssueType.EXCEPTION,
500);
}
final ValueSet vs = vsList.get(0);
List<Concept> subsetMembers = new ArrayList<Concept>();
Expand Down Expand Up @@ -366,8 +380,8 @@ public ValueSet expandInstance(
final List<Terminology> terminologies = new ArrayList<>();
terminologies.add(termUtils.getIndexedTerminology(vs.getTitle(), esQueryService));
final SearchCriteria sc = new SearchCriteria();
sc.setPageSize(count != null ? count.getValue() : 10);
sc.setFromRecord(offset != null ? offset.getValue() : 0);
sc.setPageSize(count != null ? count : 10);
sc.setFromRecord(offset != null ? offset : 0);
sc.setTerm(filter != null ? filter.getValue() : null);
sc.setType("contains");
sc.setTerminology(
Expand All @@ -376,7 +390,7 @@ public ValueSet expandInstance(
}
final ValueSetExpansionComponent vsExpansion = new ValueSetExpansionComponent();
vsExpansion.setTimestamp(new Date());
vsExpansion.setOffset(offset != null ? offset.getValue() : 0);
vsExpansion.setOffset(offset != null ? offset : 0);
vsExpansion.setTotal(subsetMembers.size());
if (subsetMembers.size() > 0) {
for (final Concept subset : subsetMembers) {
Expand All @@ -389,6 +403,15 @@ public ValueSet expandInstance(
vsContains.setCode(subset.getCode());
vsContains.setDisplay(subset.getName());
vsExpansion.addContains(vsContains);
ValueSetExpansionParameterComponent vsParameter =
new ValueSetExpansionParameterComponent();
vsParameter.setName("url");
vsParameter.setValue(url);
vsExpansion.addParameter(vsParameter);
vsParameter = new ValueSetExpansionParameterComponent();
vsParameter.setName("version");
vsParameter.setValue(version);
vsExpansion.addParameter(vsParameter);
}
}
vs.setExpansion(vsExpansion);
Expand Down Expand Up @@ -492,16 +515,18 @@ public Parameters validateCodeImplicit(
final List<Terminology> terms = Arrays.asList(term);
final List<Concept> conc = searchService.findConcepts(terms, sc).getConcepts();
if (conc.size() > 0) {
params.addParameter("result", true);
params.addParameter("display", conc.get(0).getName());
if (display != null && !display.getValue().equals(conc.get(0).getName())) {
params.addParameter("result", false);
params.addParameter(
"message",
"The code '"
+ code
+ "' was found in this value set, however the display '"
+ display
+ "' did not match any designations.");
} else {
params.addParameter("result", true);
}
} else {
params.addParameter("result", false);
Expand Down Expand Up @@ -612,16 +637,18 @@ public Parameters validateCodeInstance(
final List<Terminology> terms = Arrays.asList(term);
final List<Concept> conc = searchService.findConcepts(terms, sc).getConcepts();
if (conc.size() > 0) {
params.addParameter("result", true);
params.addParameter("display", conc.get(0).getName());
if (display != null && !display.getValue().equals(conc.get(0).getName())) {
params.addParameter("result", false);
params.addParameter(
"message",
"The code '"
+ code
+ "' was found in this value set, however the display '"
+ display
+ "' did not match any designations.");
} else {
params.addParameter("result", true);
}
} else {
params.addParameter("result", false);
Expand Down
Loading
Loading