-
Notifications
You must be signed in to change notification settings - Fork 1
LNK-4711: Informative validation of Measure/Validation Artifacts #1374
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
Merged
+6,873
−7,080
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f3631e
New backend operation to return information about a measure's related…
seanmcilvenna e668ea4
Additional code docs and unit tests
seanmcilvenna a8282a8
Updating swagger spec for measureeval service
seanmcilvenna 9d8b311
Updating all swagger specs for all services in docs
seanmcilvenna fddc349
Merge branch 'dev' into LNK-4711
seanmcilvenna ae00b57
Add `getTerminologyDependencies` endpoint and supporting service/tests
seanmcilvenna 2a88d70
Enhance terminology dependency tracking: add TerminologyDependency mo…
seanmcilvenna 1634815
Update validation config UI to clarify artifact naming, add info note…
seanmcilvenna 0e291f9
Merge branch 'dev' into LNK-4711
seanmcilvenna 7497c5e
Merge branch 'dev' into LNK-4711
seanmcilvenna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...asureeval/src/main/java/com/lantanagroup/link/measureeval/models/RelatedArtifactInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.lantanagroup.link.measureeval.models; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| public class RelatedArtifactInfo { | ||
| private String name; | ||
| private String url; | ||
| private boolean found; | ||
| private Map<String, String> libraries = new HashMap<>(); | ||
| private String version; | ||
| } |
143 changes: 143 additions & 0 deletions
143
...al/src/main/java/com/lantanagroup/link/measureeval/services/MeasureValidationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| package com.lantanagroup.link.measureeval.services; | ||
|
|
||
| import com.lantanagroup.link.measureeval.entities.MeasureDefinition; | ||
| import com.lantanagroup.link.measureeval.models.RelatedArtifactInfo; | ||
| import com.lantanagroup.link.measureeval.repositories.MeasureDefinitionRepository; | ||
| import org.hl7.fhir.r4.model.Bundle; | ||
| import org.hl7.fhir.r4.model.Library; | ||
| import org.hl7.fhir.r4.model.RelatedArtifact; | ||
| import org.hl7.fhir.r4.model.Resource; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.web.server.ResponseStatusException; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| @Service | ||
| public class MeasureValidationService { | ||
| private static final Logger logger = LoggerFactory.getLogger(MeasureValidationService.class); | ||
| private static final List<String> IGNORED_ARTIFACT_URL_PREFIXES = List.of( | ||
| "http://fhir.org/guides/cqf/" | ||
| ); | ||
| private final MeasureDefinitionRepository repository; | ||
|
|
||
| public MeasureValidationService(MeasureDefinitionRepository repository) { | ||
| this.repository = repository; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves related artifact information for a measure, indicating if each artifact is present in the | ||
| * measure definition, and where the artifact is used by other libraries. | ||
| */ | ||
| public List<RelatedArtifactInfo> getRelatedArtifacts(String id) { | ||
| MeasureDefinition measureDefinition = repository.findById(id) | ||
| .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Measure definition not found")); | ||
|
|
||
| Bundle bundle = measureDefinition.getBundle(); | ||
| if (bundle == null) { | ||
| throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Measure definition does not contain a bundle"); | ||
| } | ||
|
|
||
| Set<String> bundleResourceUrls = new HashSet<>(); | ||
|
|
||
| // Collects URLs of resources within the bundle | ||
| for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { | ||
| Resource resource = entry.getResource(); | ||
| if (resource == null) continue; | ||
|
|
||
| // Extract canonical URL if available | ||
| String url = getResourceUrl(resource); | ||
| if (url != null) { | ||
| bundleResourceUrls.add(url); | ||
| } | ||
| } | ||
|
|
||
| logger.debug("Found {} resources in measure bundle", bundleResourceUrls.size()); | ||
|
|
||
| List<RelatedArtifactInfo> relatedArtifactInfos = new ArrayList<>(); | ||
|
|
||
| for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { | ||
| if (entry.getResource() instanceof Library library) { | ||
| for (RelatedArtifact relatedArtifact : library.getRelatedArtifact()) { | ||
| // Processes related artifacts to extract dependency information | ||
| if (relatedArtifact.getType() == RelatedArtifact.RelatedArtifactType.DEPENDSON) { | ||
| String artifactUrl = relatedArtifact.getResource(); | ||
| if (artifactUrl == null || artifactUrl.isEmpty()) { | ||
| continue; | ||
| } | ||
|
|
||
| // Skip artifacts with ignored URL prefixes | ||
| if (IGNORED_ARTIFACT_URL_PREFIXES.stream().anyMatch(artifactUrl::startsWith)) { | ||
| continue; | ||
| } | ||
|
|
||
| // Extract version from URL if present (format: url|version) | ||
| String baseUrl = artifactUrl; | ||
| String version = null; | ||
| if (artifactUrl.contains("|")) { | ||
| String[] parts = artifactUrl.split("\\|", 2); | ||
| baseUrl = parts[0]; | ||
| version = parts[1]; | ||
| } | ||
|
|
||
| // Check if the artifact exists in the bundle | ||
| boolean found = bundleResourceUrls.contains(artifactUrl); | ||
|
|
||
| String finalBaseUrl = baseUrl; | ||
| String finalVersion = version; | ||
| // Finds or creates artifact info; populates if needed | ||
| RelatedArtifactInfo info = relatedArtifactInfos.stream() | ||
| .filter(i -> finalBaseUrl.equals(i.getUrl())) | ||
| .findFirst() | ||
| .orElseGet(() -> { | ||
| RelatedArtifactInfo newInfo = new RelatedArtifactInfo(); | ||
| newInfo.setName(relatedArtifact.getDisplay()); | ||
| newInfo.setUrl(finalBaseUrl); | ||
| newInfo.setVersion(finalVersion); | ||
| newInfo.setFound(found); | ||
| relatedArtifactInfos.add(newInfo); | ||
| return newInfo; | ||
| }); | ||
|
|
||
| String libUrl = library.getUrl(); | ||
| String libName = library.getName(); | ||
| if (libUrl != null) { | ||
| info.getLibraries().put(libUrl, libName); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| logger.debug("Found {} related artifacts in measure definition {}", relatedArtifactInfos.size(), id); | ||
|
|
||
| int notFoundCount = relatedArtifactInfos.stream() | ||
| .filter(info -> !info.isFound()) | ||
| .mapToInt(info -> 1) | ||
| .sum(); | ||
|
|
||
| logger.debug("Found {} artifacts not present in measure bundle {}", notFoundCount, id); | ||
|
|
||
| return relatedArtifactInfos; | ||
| } | ||
|
|
||
| /** | ||
| * Extracts resource URL, appending version if present | ||
| */ | ||
| private String getResourceUrl(Resource resource) { | ||
| if (resource instanceof org.hl7.fhir.r4.model.MetadataResource metadataResource) { | ||
| String url = metadataResource.getUrl(); | ||
| String version = metadataResource.getVersion(); | ||
| if (url != null && version != null && !version.isEmpty()) { | ||
| return url + "|" + version; | ||
| } | ||
| return url; | ||
| } | ||
| return null; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.