-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #3447 - move 4.3.0 spec artifacts too for consistency
Signed-off-by: Lee Surprenant <[email protected]>
- Loading branch information
Showing
4,628 changed files
with
751,233 additions
and
578,822 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...rmance/fhir-core-r4/src/test/java/com/ibm/fhir/core/r4/test/CoreResourceProviderTest.java
This file contains 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,21 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2019, 2020 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.core.r4.test; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import com.ibm.fhir.core.r4.Core401ResourceProvider; | ||
import com.ibm.fhir.registry.spi.FHIRRegistryResourceProvider; | ||
|
||
public class CoreResourceProviderTest { | ||
@Test | ||
public void testR4SpecResourceProvider() { | ||
FHIRRegistryResourceProvider provider = new Core401ResourceProvider(); | ||
Assert.assertEquals(provider.getRegistryResources().size(), 11251); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
conformance/fhir-core-r4/src/test/java/com/ibm/fhir/core/r4/test/FHIRRegistryTest.java
This file contains 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,71 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2019, 2020 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.core.r4.test; | ||
|
||
import java.util.Collection; | ||
|
||
import com.ibm.fhir.model.resource.CodeSystem; | ||
import com.ibm.fhir.model.resource.Resource; | ||
import com.ibm.fhir.model.resource.SearchParameter; | ||
import com.ibm.fhir.model.resource.StructureDefinition; | ||
import com.ibm.fhir.model.type.Canonical; | ||
import com.ibm.fhir.model.util.ModelSupport; | ||
import com.ibm.fhir.registry.FHIRRegistry; | ||
import com.ibm.fhir.registry.util.FHIRRegistryUtil; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class FHIRRegistryTest { | ||
@Test | ||
public void testRegistry() { | ||
StructureDefinition structureDefinition = FHIRRegistry.getInstance().getResource("http://hl7.org/fhir/StructureDefinition/Account", StructureDefinition.class); | ||
Assert.assertNotNull(structureDefinition); | ||
} | ||
|
||
@Test | ||
public void testVersionedResource() { | ||
CodeSystem codeSystem = FHIRRegistry.getInstance().getResource("http://terminology.hl7.org/CodeSystem/v2-0391|2.4", CodeSystem.class); | ||
Assert.assertNotNull(codeSystem); | ||
|
||
codeSystem = FHIRRegistry.getInstance().getResource("http://terminology.hl7.org/CodeSystem/v2-0391|2.6", CodeSystem.class); | ||
Assert.assertNotNull(codeSystem); | ||
|
||
codeSystem = FHIRRegistry.getInstance().getResource("http://terminology.hl7.org/CodeSystem/v2-0391", CodeSystem.class); | ||
Assert.assertNotNull(codeSystem); | ||
Assert.assertTrue(codeSystem.getUrl().getValue().endsWith("2.6")); | ||
} | ||
|
||
@Test | ||
public void testGetResourcesByResourceType() { | ||
Collection<SearchParameter> searchParameters = FHIRRegistry.getInstance().getResources(SearchParameter.class); | ||
Assert.assertEquals(searchParameters.size(), 2785); | ||
} | ||
|
||
@Test | ||
public void testGetProfilesByType() { | ||
Collection<Canonical> observationProfiles = FHIRRegistry.getInstance().getProfiles("Observation"); | ||
Assert.assertEquals(observationProfiles.size(), 34); | ||
} | ||
|
||
@Test | ||
public void testGetSearchParametersByType() { | ||
Collection<SearchParameter> tokenSearchParameters = FHIRRegistry.getInstance().getSearchParameters("token"); | ||
Assert.assertEquals(tokenSearchParameters.size(), 1100); | ||
} | ||
|
||
@Test | ||
public void testLoadAllResources() { | ||
// FHIRRegistryUtil has a private set of all definitional resources, | ||
// so an alternative would be to mark that public and iterate through that instead | ||
for (Class<? extends Resource> resourceType : ModelSupport.getResourceTypes()) { | ||
if (FHIRRegistryUtil.isDefinitionalResourceType(resourceType)) { | ||
FHIRRegistry.getInstance().getResources(resourceType); | ||
} | ||
} | ||
} | ||
} |
256 changes: 256 additions & 0 deletions
256
conformance/fhir-core-r4/src/test/java/com/ibm/fhir/core/r4/test/VitalSignsProfileTest.java
This file contains 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,256 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2019, 2021 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.core.r4.test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.StringJoiner; | ||
|
||
import com.ibm.fhir.model.annotation.Constraint; | ||
import com.ibm.fhir.model.config.FHIRModelConfig; | ||
import com.ibm.fhir.model.resource.StructureDefinition; | ||
import com.ibm.fhir.model.type.Code; | ||
import com.ibm.fhir.model.type.Element; | ||
import com.ibm.fhir.model.type.ElementDefinition; | ||
import com.ibm.fhir.model.type.Uri; | ||
import com.ibm.fhir.model.type.code.TypeDerivationRule; | ||
import com.ibm.fhir.registry.FHIRRegistry; | ||
|
||
public class VitalSignsProfileTest { | ||
private static final String VITAL_SIGNS_PROFILE_URL = "http://hl7.org/fhir/StructureDefinition/vitalsigns"; | ||
private static final Comparator<Constraint> CONSTRAINT_COMPARATOR = new Comparator<Constraint>() { | ||
@Override | ||
public int compare(Constraint first, Constraint second) { | ||
return first.id().compareTo(second.id()); | ||
} | ||
}; | ||
|
||
static class Tree { | ||
Node root; | ||
Map<String, Node> nodeMap; | ||
|
||
Node getNode(String path) { | ||
return nodeMap.get(path); | ||
} | ||
} | ||
|
||
static class Node { | ||
String label; | ||
String path; | ||
Node parent; | ||
List<Node> children = new ArrayList<>(); | ||
List<ElementDefinition> elementDefinitions = new ArrayList<>(); | ||
|
||
int getLevel() { | ||
int level = 0; | ||
Node parent = this.parent; | ||
while (parent != null) { | ||
level++; | ||
parent = parent.parent; | ||
} | ||
return level; | ||
} | ||
} | ||
|
||
public static Tree buildTree(StructureDefinition profile) { | ||
Node root = null; | ||
|
||
Map<String, Node> nodeMap = new LinkedHashMap<>(); | ||
for (ElementDefinition elementDefinition : profile.getDifferential().getElement()) { | ||
String path = elementDefinition.getPath().getValue(); | ||
|
||
Node node = nodeMap.get(path); | ||
if (node == null) { | ||
node = new Node(); | ||
node.path = path; | ||
|
||
int index = path.lastIndexOf("."); | ||
node.label = path.substring(index + 1); | ||
node.parent = (index != -1) ? nodeMap.get(path.substring(0, index)) : null; | ||
|
||
if (node.parent == null) { | ||
root = node; | ||
} else { | ||
node.parent.children.add(node); | ||
} | ||
|
||
nodeMap.put(path, node); | ||
} | ||
|
||
node.elementDefinitions.add(elementDefinition); | ||
} | ||
|
||
Tree tree = new Tree(); | ||
tree.root = root; | ||
tree.nodeMap = nodeMap; | ||
|
||
return tree; | ||
} | ||
|
||
private static String transform(Node node) { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
Integer min = getMin(node); | ||
String max = getMax(node); | ||
|
||
sb.append(node.label); | ||
|
||
Element fixed = getFixed(node); | ||
if (fixed != null) { | ||
sb.append(" = "); | ||
if (fixed.is(Code.class)) { | ||
sb.append("'").append(fixed.as(Code.class).getValue()).append("'"); | ||
} else if (fixed.is(Uri.class)) { | ||
sb.append("'").append(fixed.as(Uri.class).getValue()).append("'"); | ||
} | ||
} | ||
|
||
// TODO: pattern | ||
|
||
// TODO: value set binding | ||
|
||
// TODO: reference types | ||
|
||
if (!node.children.isEmpty()) { | ||
sb.append(".where("); | ||
|
||
StringJoiner joiner = new StringJoiner(" and "); | ||
for (Node child : node.children) { | ||
joiner.add(transform(child)); | ||
} | ||
sb.append(joiner.toString()); | ||
|
||
sb.append(")"); | ||
} | ||
|
||
if (min != null && max != null && fixed == null) { | ||
if (min == 1 && "*".equals(max)) { | ||
sb.append(".exists()"); | ||
} else if (min == 1 && "1".equals(max)) { | ||
sb.append(".count() = 1"); | ||
} | ||
} | ||
|
||
return sb.toString(); | ||
} | ||
|
||
private static Integer getMin(Node node) { | ||
for (ElementDefinition elementDefinition : node.elementDefinitions) { | ||
if (elementDefinition.getMin() != null) { | ||
return elementDefinition.getMin().getValue(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private static String getMax(Node node) { | ||
for (ElementDefinition elementDefinition : node.elementDefinitions) { | ||
if (elementDefinition.getMax() != null) { | ||
return elementDefinition.getMax().getValue(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static Element getFixed(Node node) { | ||
for (ElementDefinition elementDefinition : node.elementDefinitions) { | ||
if (elementDefinition.getFixed() != null) { | ||
return elementDefinition.getFixed(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static Element getPattern(Node node) { | ||
for (ElementDefinition elementDefinition : node.elementDefinitions) { | ||
if (elementDefinition.getPattern() != null) { | ||
return elementDefinition.getPattern(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static List<ElementDefinition.Constraint> getConstraints(Node node) { | ||
List<ElementDefinition.Constraint> constraints = new ArrayList<>(); | ||
for (ElementDefinition elementDefinition : node.elementDefinitions) { | ||
constraints.addAll(elementDefinition.getConstraint()); | ||
} | ||
return constraints; | ||
} | ||
|
||
public static List<StructureDefinition> getProfiles(StructureDefinition profile) { | ||
List<StructureDefinition> profiles = new ArrayList<>(); | ||
while (TypeDerivationRule.CONSTRAINT.equals(profile.getDerivation())) { | ||
profiles.add(profile); | ||
profile = FHIRRegistry.getInstance().getResource(profile.getBaseDefinition().getValue(), StructureDefinition.class); | ||
} | ||
Collections.reverse(profiles); | ||
return profiles; | ||
} | ||
|
||
public static void main(String[] args) { | ||
FHIRModelConfig.setToStringPrettyPrinting(false); | ||
|
||
StructureDefinition vitalSignsProfile = FHIRRegistry.getInstance().getResource(VITAL_SIGNS_PROFILE_URL, StructureDefinition.class); | ||
|
||
Tree tree = buildTree(vitalSignsProfile); | ||
Node root = tree.root; | ||
|
||
String result = transform(root); | ||
System.out.println("result: " + result); | ||
|
||
for (Node child : root.children) { | ||
String expr = transform(child); | ||
System.out.println("expr: " + expr); | ||
} | ||
|
||
System.out.println("Constraints: "); | ||
for (Constraint constraint : getConstraints(vitalSignsProfile)) { | ||
System.out.println(" " + constraint); | ||
} | ||
} | ||
|
||
public static List<Constraint> getConstraints(List<StructureDefinition> profiles) { | ||
List<Constraint> constraints = new ArrayList<>(); | ||
for (StructureDefinition profile : profiles) { | ||
constraints.addAll(getConstraints(profile)); | ||
} | ||
return constraints; | ||
} | ||
|
||
public static List<Constraint> getConstraints(StructureDefinition profile) { | ||
List<Constraint> constraints = new ArrayList<>(); | ||
for (ElementDefinition elementDefinition : profile.getDifferential().getElement()) { | ||
constraints.addAll(getConstraints(elementDefinition)); | ||
} | ||
Collections.sort(constraints, CONSTRAINT_COMPARATOR); | ||
return constraints; | ||
} | ||
|
||
private static List<Constraint> getConstraints(ElementDefinition elementDefinition) { | ||
List<Constraint> constraints = new ArrayList<>(); | ||
String path = elementDefinition.getPath().getValue(); | ||
for (ElementDefinition.Constraint constraint : elementDefinition.getConstraint()) { | ||
constraints.add(createConstraint(path, constraint)); | ||
} | ||
return constraints; | ||
} | ||
|
||
private static Constraint createConstraint(String path, ElementDefinition.Constraint constraint) { | ||
String id = constraint.getKey().getValue(); | ||
String level = "error".equals(constraint.getSeverity().getValue()) ? "Rule" : "Warning"; | ||
String location = path.contains(".") ? path.replace("[x]", "") : "(base)"; | ||
String description = constraint.getHuman().getValue(); | ||
String expression = constraint.getExpression().getValue(); | ||
String source = (constraint.getSource() != null) ? constraint.getSource().getValue() : ""; | ||
return Constraint.Factory.createConstraint(id, level, location, description, expression, source, false, false); | ||
} | ||
} |
Oops, something went wrong.