Skip to content

Commit

Permalink
Merge pull request hapifhir#1529 from hapifhir/2024-01-gg-fhirpath-split
Browse files Browse the repository at this point in the history
2024 01 gg fhirpath split
  • Loading branch information
grahamegrieve authored Jan 2, 2024
2 parents 8ee621a + 108c6f0 commit 5e9f87d
Show file tree
Hide file tree
Showing 36 changed files with 2,318 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4391,7 +4391,7 @@ private List<Base> funcSplit(ExecutionContext context, List<Base> focus, Express
List<Base> result = new ArrayList<Base>();
if (focus.size() == 1) {
String cnt = focus.get(0).primitiveValue();
String[] sl = Pattern.compile(param, Pattern.LITERAL).split(cnt);
String[] sl = Utilities.simpleSplit(cnt, param);
for (String s : sl) {
result.add(new StringType(s));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4401,7 +4401,7 @@ private List<Base> funcSplit(ExecutionContext context, List<Base> focus, Express
List<Base> result = new ArrayList<Base>();
if (focus.size() == 1) {
String cnt = focus.get(0).primitiveValue();
String[] sl = Pattern.compile(param, Pattern.LITERAL).split(cnt);
String[] sl = Utilities.simpleSplit(cnt, param);
for (String s : sl) {
result.add(new StringType(s));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4383,7 +4383,7 @@ private List<Base> funcSplit(ExecutionContext context, List<Base> focus, Express
List<Base> result = new ArrayList<Base>();
if (focus.size() == 1) {
String cnt = focus.get(0).primitiveValue();
String[] sl = Pattern.compile(param, Pattern.LITERAL).split(cnt);
String[] sl = Utilities.simpleSplit(cnt, param);
for (String s : sl) {
result.add(new StringType(s));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2191,4 +2191,36 @@ public static String escapeSql(String s) {
return s.replace("'", "''");
}

public static String[] simpleSplit(String cnt, String div) {
if (cnt == null) {
return new String[] {};
}
List<String> parts = new ArrayList<>();
int cursor = 0;
int last = 0;
while (cursor < cnt.length()) {
if (matches(cnt, div, cursor)) {
parts.add(cnt.substring(last, cursor));
cursor = cursor + div.length();
last = cursor;
} else {
cursor++;
}
}
parts.add(cnt.substring(last, cursor));
return parts.toArray(new String[] {});
}

private static boolean matches(String cnt, String div, int cursor) {
if (div.length() + cursor > cnt.length()) {
return false;
}
for (int i = 0; i < div.length(); i++) {
if (cnt.charAt(cursor+i) != div.charAt(i)) {
return false;
}
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,24 @@ private void makeDir(String path) throws IOException {
Utilities.createDirectory(path);
Utilities.clearDirectory(path);
}

@Test
void testSimpleSplit() throws IOException {
checkEquals(new String[] {}, Utilities.simpleSplit(null, ","));
checkEquals(new String[] {""}, Utilities.simpleSplit("", ","));
checkEquals(new String[] {"", ""}, Utilities.simpleSplit(",", ","));
checkEquals(new String[] {"A"}, Utilities.simpleSplit("A", ","));
checkEquals(new String[] {"A", "B"}, Utilities.simpleSplit("A,B", ","));
checkEquals(new String[] {"", "A", "", "B", ""}, Utilities.simpleSplit(",A,,B,", ","));
checkEquals(new String[] {"", "ONE", "", "TWO", "", "", "THREE", "", ""}, Utilities.simpleSplit("[stop]ONE[stop][stop]TWO[stop][stop][stop]THREE[stop][stop]", "[stop]"));
}

private void checkEquals(String[] left, String[] right) {
for (int i =0; i < Integer.min(left.length, right.length); i++) {
Assertions.assertEquals(left[i], right[i], "String["+i+"] differs");
}
Assertions.assertEquals(left.length, right.length, "String[].length() differs");

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-------------------------------------------------------------------------------------
{"hierarchical" : false, "valueSet" :{
"resourceType" : "ValueSet",
"compose" : {
"inactive" : true,
"include" : [{
"system" : "urn:ietf:bcp:47"
}]
}
}}####
e: {
"from-server" : true,
"error" : "Cannot invoke \"org.hl7.fhir.r5.terminologies.client.ITerminologyClient.expandValueset(org.hl7.fhir.r5.model.ValueSet, org.hl7.fhir.r5.model.Parameters, java.util.Map)\" because the return value of \"org.hl7.fhir.r5.terminologies.client.TerminologyClientContext.getClient()\" is null"
}
-------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-------------------------------------------------------------------------------------
{"hierarchical" : false, "valueSet" :{
"resourceType" : "ValueSet",
"compose" : {
"inactive" : true,
"include" : [{
"system" : "http://loinc.org",
"concept" : [{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-label",
"valueString" : "A."
}],
"code" : "LA20752-4",
"display" : "Within 24 hours"
},
{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-label",
"valueString" : "B."
}],
"code" : "LA20753-2",
"display" : "After 24 hours but before 3 days"
},
{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-label",
"valueString" : "C."
}],
"code" : "LA20754-0",
"display" : "Three days or later"
},
{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-label",
"valueString" : "D."
}],
"code" : "LA4489-6",
"display" : "Unknown"
}]
}]
}
}}####
e: {
"from-server" : true,
"error" : "Cannot invoke \"org.hl7.fhir.r5.terminologies.client.ITerminologyClient.expandValueset(org.hl7.fhir.r5.model.ValueSet, org.hl7.fhir.r5.model.Parameters, java.util.Map)\" because the return value of \"org.hl7.fhir.r5.terminologies.client.TerminologyClientContext.getClient()\" is null"
}
-------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-------------------------------------------------------------------------------------
{"hierarchical" : false, "valueSet" :{
"resourceType" : "ValueSet",
"compose" : {
"inactive" : true,
"include" : [{
"system" : "urn:ietf:bcp:13"
}]
}
}}####
e: {
"from-server" : true,
"error" : "Cannot invoke \"org.hl7.fhir.r5.terminologies.client.ITerminologyClient.expandValueset(org.hl7.fhir.r5.model.ValueSet, org.hl7.fhir.r5.model.Parameters, java.util.Map)\" because the return value of \"org.hl7.fhir.r5.terminologies.client.TerminologyClientContext.getClient()\" is null"
}
-------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
-------------------------------------------------------------------------------------
{"hierarchical" : false, "valueSet" :{
"resourceType" : "ValueSet",
"compose" : {
"inactive" : true,
"include" : [{
"system" : "http://unitsofmeasure.org",
"concept" : [{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-concept-definition",
"valueString" : "second"
}],
"code" : "s",
"display" : "second",
"designation" : [{
"language" : "zh",
"value" : "秒"
}]
},
{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-concept-definition",
"valueString" : "minute"
}],
"code" : "min",
"display" : "minute",
"designation" : [{
"language" : "zh",
"value" : "分钟"
}]
},
{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-concept-definition",
"valueString" : "hour"
}],
"code" : "h",
"display" : "hour",
"designation" : [{
"language" : "zh",
"value" : "小时"
}]
},
{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-concept-definition",
"valueString" : "day"
}],
"code" : "d",
"display" : "day",
"designation" : [{
"language" : "zh",
"value" : "天"
}]
},
{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-concept-definition",
"valueString" : "week"
}],
"code" : "wk",
"display" : "week",
"designation" : [{
"language" : "zh",
"value" : "星期"
}]
},
{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-concept-definition",
"valueString" : "month - Normal practice is to use the 'mo' code as a calendar month when calculating the next occurrence."
}],
"code" : "mo",
"display" : "month",
"designation" : [{
"language" : "zh",
"value" : "月"
}]
},
{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/valueset-concept-definition",
"valueString" : "year"
}],
"code" : "a",
"display" : "year",
"designation" : [{
"language" : "zh",
"value" : "年"
}]
}]
}]
}
}}####
e: {
"from-server" : true,
"error" : "Cannot invoke \"org.hl7.fhir.r5.terminologies.client.ITerminologyClient.expandValueset(org.hl7.fhir.r5.model.ValueSet, org.hl7.fhir.r5.model.Parameters, java.util.Map)\" because the return value of \"org.hl7.fhir.r5.terminologies.client.TerminologyClientContext.getClient()\" is null"
}
-------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,42 @@ v: {

}
-------------------------------------------------------------------------------------
{"code" : {
"system" : "http://acme.org/devices/clinical-codes",
"code" : "body-weight",
"display" : "Body Weight"
}, "valueSet" :null, "langs":"", "useServer":"true", "useClient":"false", "guessSystem":"false", "activeOnly":"false", "membershipOnly":"false", "displayWarningMode":"false", "versionFlexible":"true", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"code" : "body-weight",
"severity" : "error",
"error" : "A definition for CodeSystem http://acme.org/devices/clinical-codes could not be found, so the code cannot be validated",
"class" : "CODESYSTEM_UNSUPPORTED",
"unknown-systems" : "http://acme.org/devices/clinical-codes",
"issues" : {
"resourceType" : "OperationOutcome",
"issue" : [{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/operationoutcome-issue-server",
"valueUrl" : "http://tx-dev.fhir.org/r2"
}],
"severity" : "error",
"code" : "not-found",
"details" : {
"coding" : [{
"system" : "http://hl7.org/fhir/tools/CodeSystem/tx-issue-type",
"code" : "not-found"
}],
"text" : "A definition for CodeSystem http://acme.org/devices/clinical-codes could not be found, so the code cannot be validated"
},
"location" : ["Coding.system"]
}]
}

}
-------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "Body weight Measured",
"code" : "3141-9",
"system" : "http://loinc.org",
"version" : "2.74",
"issues" : {
"resourceType" : "OperationOutcome"
}

}
-------------------------------------------------------------------------------------
{"code" : {
"system" : "http://loinc.org",
"code" : "3141-9",
"display" : "Weight Measured"
}, "valueSet" :null, "langs":"", "useServer":"true", "useClient":"false", "guessSystem":"false", "activeOnly":"false", "membershipOnly":"false", "displayWarningMode":"false", "versionFlexible":"true", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "Body weight Measured",
"code" : "3141-9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,45 @@
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "Vital Signs",
"code" : "vital-signs",
"system" : "http://hl7.org/fhir/observation-category",
"version" : "1.0.2",
"issues" : {
"resourceType" : "OperationOutcome",
"issue" : [{
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/operationoutcome-issue-server",
"valueUrl" : "http://tx-dev.fhir.org/r2"
}],
"severity" : "information",
"code" : "business-rule",
"details" : {
"coding" : [{
"system" : "http://hl7.org/fhir/tools/CodeSystem/tx-issue-type",
"code" : "status-check"
}],
"text" : "Reference to experimental CodeSystem http://hl7.org/fhir/observation-category|1.0.2"
}
}]
}

}
-------------------------------------------------------------------------------------
{"code" : {
"coding" : [{
"system" : "http://hl7.org/fhir/observation-category",
"code" : "vital-signs",
"display" : "Vital Signs"
}]
}, "langs":"", "useServer":"true", "useClient":"true", "guessSystem":"false", "activeOnly":"false", "membershipOnly":"false", "displayWarningMode":"false", "versionFlexible":"true", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "Vital Signs",
"code" : "vital-signs",
Expand Down
Loading

0 comments on commit 5e9f87d

Please sign in to comment.