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

feat(fhir.core): Improve computation of "content" code system property #1069

Merged
merged 1 commit into from
Oct 25, 2022
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2021-2022 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,14 +15,17 @@
*/
package com.b2international.snowowl.fhir.core.request.codesystem;

import java.util.List;
import java.util.Set;

import com.b2international.commons.CompareUtils;
import com.b2international.snowowl.core.RepositoryManager;
import com.b2international.snowowl.core.ResourceURI;
import com.b2international.snowowl.core.domain.RepositoryContext;
import com.b2international.snowowl.fhir.core.codesystems.CodeSystemContentMode;
import com.b2international.snowowl.fhir.core.codesystems.IdentifierUse;
import com.b2international.snowowl.fhir.core.model.codesystem.CodeSystem;
import com.b2international.snowowl.fhir.core.model.codesystem.Concept;
import com.b2international.snowowl.fhir.core.model.codesystem.SupportedCodeSystemRequestProperties;
import com.b2international.snowowl.fhir.core.model.codesystem.SupportedConceptProperty;
import com.b2international.snowowl.fhir.core.model.dt.Identifier;
Expand Down Expand Up @@ -60,9 +63,6 @@ protected CodeSystem.Builder createResourceBuilder() {

@Override
protected void expandResourceSpecificFields(RepositoryContext context, CodeSystem.Builder entry, ResourceFragment resource) {
// treat all CodeSystems complete by default, later we might add this field to the document, if needed
entry.content(CodeSystemContentMode.COMPLETE);

includeIfFieldSelected(CodeSystem.Fields.COPYRIGHT, resource::getCopyright, entry::copyright);
includeIfFieldSelected(CodeSystem.Fields.IDENTIFIER, () -> {
if (!CompareUtils.isEmpty(resource.getOid())) {
Expand All @@ -81,15 +81,40 @@ protected void expandResourceSpecificFields(RepositoryContext context, CodeSyste
.optionalService(FhirCodeSystemResourceConverter.class)
.orElse(FhirCodeSystemResourceConverter.DEFAULT);

includeIfFieldSelected(CodeSystem.Fields.COUNT, () -> converter.count(context, resource.getResourceURI()), entry::count);
includeIfFieldSelected(CodeSystem.Fields.CONCEPT, () -> converter.expandConcepts(context, resource.getResourceURI(), locales()), entry::concepts);
includeIfFieldSelected(CodeSystem.Fields.FILTER, () -> converter.expandFilters(context, resource.getResourceURI(), locales()), entry::filters);
includeIfFieldSelected(CodeSystem.Fields.PROPERTY, () -> converter.expandProperties(context, resource.getResourceURI(), locales()), properties -> {
final ResourceURI resourceURI = resource.getResourceURI();

if (fields().isEmpty() || fields().contains(CodeSystem.Fields.CONCEPT)) {
// XXX: When "concept" is requested to be included, we also need a total concept count to set "content" properly
final List<Concept> concepts = converter.expandConcepts(context, resourceURI, locales());
final int count = converter.count(context, resourceURI);

if (concepts.size() == 0) {
entry.content(CodeSystemContentMode.NOT_PRESENT);
} else if (concepts.size() == count) {
entry.content(CodeSystemContentMode.COMPLETE);
} else {
/*
* If the total concept count differs from the returned list's size, content is
* to be considered partial. We have two values to represent this scenario,
* "example" and "fragment", but the latter implies a curated subset, whereas
* the former is intended for subsets without a specific intent.
*/
entry.content(CodeSystemContentMode.EXAMPLE);
}

entry.concepts(concepts);
entry.count(count);
} else {
entry.content(CodeSystemContentMode.NOT_PRESENT);
includeIfFieldSelected(CodeSystem.Fields.COUNT, () -> converter.count(context, resourceURI), entry::count);
}

includeIfFieldSelected(CodeSystem.Fields.FILTER, () -> converter.expandFilters(context, resourceURI, locales()), entry::filters);
includeIfFieldSelected(CodeSystem.Fields.PROPERTY, () -> converter.expandProperties(context, resourceURI, locales()), properties -> {
properties.stream()
.filter(p -> !(SupportedCodeSystemRequestProperties.class.isInstance(p)))
.map(prop -> SupportedConceptProperty.builder(prop).build())
.forEach(entry::addProperty);
});
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2021 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2011-2022 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -172,7 +172,7 @@ public void GET_CodeSystem_Summary_Text() throws Exception {
// only text, id, meta and mandatory
.body("entry[0].resource.id", equalTo(getTestCodeSystemId()))
.body("entry[0].resource.status", equalTo("draft"))
.body("entry[0].resource.content", equalTo("complete"))
.body("entry[0].resource.content", equalTo("not-present"))
.body("entry[0].resource.meta", notNullValue())
.body("entry[0].resource.text", notNullValue())
.body("entry[0].resource.count", nullValue())
Expand All @@ -197,7 +197,7 @@ public void GET_CodeSystem_Summary_Data() throws Exception {
// only id, meta and mandatory
.body("entry[0].resource.id", notNullValue())
.body("entry[0].resource.status", equalTo("draft"))
.body("entry[0].resource.content", equalTo("complete"))
.body("entry[0].resource.content", equalTo("not-present"))
// other fields should be null
.body("entry[0].resource.text", nullValue())
.body("entry[0].resource.url", nullValue())
Expand Down Expand Up @@ -252,7 +252,7 @@ public void GET_CodeSystem_Elements() throws Exception {
.body("type", equalTo("searchset"))
// mandatory fields
.body("entry[0].resource.status", equalTo("draft"))
.body("entry[0].resource.content", equalTo("complete"))
.body("entry[0].resource.content", equalTo("not-present"))
.body("entry[0].resource.id", equalTo(getTestCodeSystemId()))
// summary and optional fields
.body("entry[0].resource.text", nullValue())
Expand Down