Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Grahame Grieve committed Aug 22, 2023
2 parents 53a9829 + 2ab5919 commit 7a7a85f
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 28 deletions.
11 changes: 10 additions & 1 deletion org.hl7.fhir.convertors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,19 @@
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.3</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
<optional>true</optional>
</dependency>
<!-- HTTP Client -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
1 change: 0 additions & 1 deletion org.hl7.fhir.dstu2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.3</version>
<optional>true</optional>
</dependency>

Expand Down
15 changes: 0 additions & 15 deletions org.hl7.fhir.dstu2016may/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,7 @@
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.3</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
</exclusion>
<exclusion>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
</exclusion>
<exclusion>
<groupId>xpp3</groupId>
<artifactId>xpp3_min</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- XML Parsers -->
Expand Down
1 change: 0 additions & 1 deletion org.hl7.fhir.dstu3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.3</version>
<optional>true</optional>
</dependency>

Expand Down
1 change: 0 additions & 1 deletion org.hl7.fhir.r4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.3</version>
<optional>true</optional>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.hl7.fhir.r4.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
import java.util.HashSet;

import org.hl7.fhir.r4.formats.IParser.OutputStyle;
import org.hl7.fhir.r4.formats.JsonParser;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.MetadataResource;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.utilities.TextFile;

/**
* Used to take an overload dump from tx.fhir.org and turn it into a parameters resource
*
* @author grahamegrieve
*
*/
public class ParametersBuilder {

public static void main(String[] args) throws FileNotFoundException, IOException {
new ParametersBuilder(args[0], args[1]).process(args[2]);
}



private String folder;
private String baseId;

protected ParametersBuilder(String folder, String baseId) {
super();
this.folder = folder;
this.baseId = baseId;
}

private void process(String output) throws FileNotFoundException, IOException {
Parameters p = new Parameters();
Set<String> ids = new HashSet<>();
for (File f : new File(folder).listFiles()) {
if (f.getName().startsWith(baseId)) {
if (f.getName().startsWith(baseId)) {
byte[] cnt = TextFile.fileToBytes(f);
cnt = shaveZeros(cnt); // bug in tx.fhir.org
MetadataResource r = (MetadataResource) new JsonParser().parse(cnt);
if (!ids.contains(r.getUrl()+"|"+r.getVersion())) {
ids.add(r.getUrl()+"|"+r.getVersion());
p.addParameter().setName("tx-resource").setResource(r);
}
}
}
}
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(output), p);
}

private byte[] shaveZeros(byte[] cnt) {
for (int i = 0; i < cnt.length; i++) {
if (cnt[i] == 0) {
return Arrays.copyOf(cnt, i-1);
}
}
return cnt;
}
}
1 change: 0 additions & 1 deletion org.hl7.fhir.r4b/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.3</version>
<optional>true</optional>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ private boolean addDependentResources(Parameters pin, ConceptSetComponent inc, R
boolean cache = false;
for (CanonicalType c : inc.getValueSet()) {
ValueSet vs = fetchResource(ValueSet.class, c.getValue(), src);
if (vs != null) {
if (vs != null && !hasCanonicalResource(pin, "tx-resource", vs.getVUrl())) {
pin.addParameter().setName("tx-resource").setResource(vs);
if (tcc.isTxCaching() && tcc.getCacheId() == null || !tcc.getCached().contains(vs.getVUrl())) {
tcc.getCached().add(vs.getVUrl());
Expand All @@ -1509,7 +1509,7 @@ private boolean addDependentResources(Parameters pin, ConceptSetComponent inc, R
}
}
CodeSystem cs = fetchResource(CodeSystem.class, inc.getSystem(), src);
if (cs != null && (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == CodeSystemContentMode.FRAGMENT)) {
if (cs != null && !hasCanonicalResource(pin, "tx-resource", cs.getVUrl()) && (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == CodeSystemContentMode.FRAGMENT)) {
pin.addParameter().setName("tx-resource").setResource(cs);
if (tcc.isTxCaching() && tcc.getCacheId() == null || !tcc.getCached().contains(cs.getVUrl())) {
tcc.getCached().add(cs.getVUrl());
Expand All @@ -1520,6 +1520,16 @@ private boolean addDependentResources(Parameters pin, ConceptSetComponent inc, R
return cache;
}

private boolean hasCanonicalResource(Parameters pin, String name, String vUrl) {
for (ParametersParameterComponent p : pin.getParameter()) {
if (name.equals(p.getName()) && p.hasResource() &&
p.getResource() instanceof CanonicalResource && vUrl.equals(((CanonicalResource) p.getResource()).getVUrl())) {
return true;
}
}
return false;
}

public ValidationResult processValidationResult(Parameters pOut, String vs) {
boolean ok = false;
String message = "No Message returned";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void checkNonRootFirstEntry(String[] args) {
return;
}
if (isPathRoot(args[0])) {
throw new RuntimeException("First entry cannot be root: " + args[0]);
throw new RuntimeException("First entry in file path cannot be root: " + args[0]+", full path = "+String.join(", ", args));
}
}

Expand All @@ -159,7 +159,7 @@ private void checkNonNullNonEmptyFirstEntry(String[] args) {
return;
}
if (args[0] == null || Utilities.noString(args[0].trim())) {
throw new RuntimeException("First path entry cannot be null or empty");
throw new RuntimeException("First entry in file path cannot be null or empty, full path = "+String.join(", ", args));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private static void testCantStartWithRoot(String[] pathStrings) {
RuntimeException thrown = Assertions.assertThrows(RuntimeException.class, () -> {
Utilities.path(pathStrings);
});
assertTrue(thrown.getMessage().endsWith(pathStrings[0]));
assertTrue(thrown.getMessage().endsWith(pathStrings[0]+", full path = "+String.join(", ", pathStrings)));
}

public static Stream<Arguments> macAndLinuxNonFirstElementStartPaths() {
Expand Down Expand Up @@ -384,7 +384,7 @@ public void testNullOrEmptyFirstPathEntryFails(String[] pathsStrings) {
RuntimeException thrown = Assertions.assertThrows(RuntimeException.class, () -> {
Utilities.path(pathsStrings);
});
assertEquals("First path entry cannot be null or empty",thrown.getMessage());
assertEquals("First entry in file path cannot be null or empty, full path = "+String.join(", ", pathsStrings),thrown.getMessage());
}

@Test
Expand Down
1 change: 0 additions & 1 deletion org.hl7.fhir.validation.cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>xpp3</groupId>
Expand Down
2 changes: 1 addition & 1 deletion org.hl7.fhir.validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.3</version>
<optional>true</optional>
</dependency>

<!-- CQL-to-ELM -->
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@
<artifactId>Saxon-HE</artifactId>
<version>${saxon_he_version}</version>
</dependency>
<dependency>
<groupId>org.fhir</groupId>
<artifactId>ucum</artifactId>
<version>1.0.8</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
Expand Down

0 comments on commit 7a7a85f

Please sign in to comment.