Skip to content

Commit 90c794c

Browse files
Quarz0copybara-github
authored andcommitted
diffbase
PiperOrigin-RevId: 624930954
1 parent f20f977 commit 90c794c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+9949
-3917
lines changed

bazel/antlr4_cc.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Build rules to create C++ code from an Antlr4 grammar."""
22

3+
load("@rules_java//java:defs.bzl", "java_binary")
4+
35
def antlr4_cc_lexer(name, src, namespaces = None, imports = None, deps = None, lib_import = None):
46
"""Generates the C++ source corresponding to an antlr4 lexer definition.
57
@@ -25,8 +27,7 @@ def antlr4_cc_lexer(name, src, namespaces = None, imports = None, deps = None, l
2527
"%sLexer.h" % base_file_prefix,
2628
"%sLexer.cpp" % base_file_prefix,
2729
]
28-
29-
native.java_binary(
30+
java_binary(
3031
name = "antlr_tool",
3132
jvm_flags = ["-Xmx256m"],
3233
main_class = "org.antlr.v4.Tool",

bazel/go_dependencies.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,9 @@ def fhir_go_dependencies():
208208
sum = "h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=",
209209
version = "v0.0.0-20191204190536-9bdfabe68543",
210210
)
211+
go_repository(
212+
name = "com_github_antrl4_go_antlr",
213+
importpath = "github.com/antlr4-go/antlr/v4",
214+
sum = "h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=",
215+
version = "v4.13.0",
216+
)

bazel/protogen.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
1514
"""Rules for generating Protos from FHIR definitions"""
1615

16+
load("@rules_java//java:defs.bzl", "java_binary", "java_test")
17+
1718
R4_PACKAGE_DEP = "@com_google_fhir//spec:fhir_r4"
1819
PROTO_GENERATOR = "@com_google_fhir//java/com/google/fhir/protogen:ProtoGenerator"
1920
PROFILE_GENERATOR = "@com_google_fhir//java/com/google/fhir/protogen:ProfileGenerator"
@@ -151,8 +152,7 @@ def gen_fhir_protos(
151152
"-Dgolden_dir=" + src_dir,
152153
"-Xmx4096M",
153154
]
154-
155-
native.java_test(
155+
java_test(
156156
name = "GeneratedProtoTest_" + name,
157157
size = "medium",
158158
srcs = ["//external:GeneratedProtoTest.java"],
@@ -294,7 +294,7 @@ def _get_tar_for_pkg(pkg):
294294
return pkg + "_package.tgz"
295295

296296
def _proto_generator_with_runtime_deps_on_existing_protos(name, golden_java_protos_rules):
297-
native.java_binary(
297+
java_binary(
298298
name = name,
299299
main_class = "com.google.fhir.protogen.ProtoGeneratorMain",
300300
runtime_deps = golden_java_protos_rules +

cc/google/fhir/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ cc_library(
462462
":util",
463463
"//cc/google/fhir/json:fhir_json",
464464
"//cc/google/fhir/status",
465+
"//cc/google/fhir/status:statusor",
465466
"@com_google_absl//absl/status",
466467
"@com_google_absl//absl/status:statusor",
467468
"@com_google_absl//absl/strings",

cc/google/fhir/fhir_path/BUILD

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ cc_library(
120120
"fhir_path_types.h",
121121
],
122122
strip_include_prefix = "//cc/",
123-
visibility = [
124-
"//visibility:private", # Only private by automation, not intent. Owner may accept CLs adding visibility. See go/scheuklappen#explicit-private.
125-
],
123+
visibility = ["//visibility:private"],
126124
deps = [
127125
"//cc/google/fhir:annotations",
128126
"//cc/google/fhir:fhir_types",
@@ -143,9 +141,7 @@ cc_library(
143141
"utils.h",
144142
],
145143
strip_include_prefix = "//cc/",
146-
visibility = [
147-
"//visibility:private", # Only private by automation, not intent. Owner may accept CLs adding visibility. See go/scheuklappen#explicit-private.
148-
],
144+
visibility = ["//visibility:private"],
149145
deps = [
150146
"//cc/google/fhir:annotations",
151147
"//cc/google/fhir:references",

cc/google/fhir/fhir_path/fhir_path.cc

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@
4949
#include "google/fhir/fhir_path/fhir_path_types.h"
5050
#include "google/fhir/fhir_path/utils.h"
5151
#include "google/fhir/fhir_types.h"
52+
#include "google/fhir/primitive_handler.h"
5253
#include "google/fhir/proto_util.h"
5354
#include "google/fhir/status/status.h"
5455
#include "google/fhir/status/statusor.h"
5556
#include "google/fhir/util.h"
5657
#include "proto/google/fhir/proto/r4/core/datatypes.pb.h"
5758
#include "icu4c/source/common/unicode/unistr.h"
5859
#include "google/protobuf/descriptor.h"
60+
#include "google/protobuf/message.h"
5961

6062
namespace google {
6163
namespace fhir {
@@ -3039,7 +3041,8 @@ class ComparisonOperator : public BinaryOperator {
30393041

30403042
} else if (IsSystemString(*left_result) && IsSystemString(*right_result)) {
30413043
return EvalStringComparison(primitive_handler, left, right);
3042-
} else if (IsDateTime(*left_result) && IsDateTime(*right_result)) {
3044+
} else if ((IsInstant(*left_result) || IsDateTime(*left_result)) &&
3045+
(IsInstant(*right_result) || IsDateTime(*right_result))) {
30433046
return EvalDateTimeComparison(primitive_handler, *left_result,
30443047
*right_result);
30453048
} else if (IsSimpleQuantity(*left_result) &&
@@ -3147,12 +3150,33 @@ class ComparisonOperator : public BinaryOperator {
31473150
absl::StatusOr<absl::optional<bool>> EvalDateTimeComparison(
31483151
const PrimitiveHandler* primitive_handler, const Message& left_message,
31493152
const Message& right_message) const {
3150-
FHIR_ASSIGN_OR_RETURN(
3151-
DateTimePrecision left_precision,
3152-
primitive_handler->GetDateTimePrecision(left_message));
3153-
FHIR_ASSIGN_OR_RETURN(
3154-
DateTimePrecision right_precision,
3155-
primitive_handler->GetDateTimePrecision(right_message));
3153+
const Message* left = &left_message;
3154+
const Message* right = &right_message;
3155+
std::vector<std::unique_ptr<const Message>> to_delete;
3156+
if (IsInstant(left_message)) {
3157+
FHIR_ASSIGN_OR_RETURN(
3158+
JsonPrimitive json_primitive,
3159+
primitive_handler->WrapPrimitiveProto(left_message));
3160+
json_primitive.value = absl::StripPrefix(json_primitive.value, "\"");
3161+
json_primitive.value = absl::StripSuffix(json_primitive.value, "\"");
3162+
FHIR_ASSIGN_OR_RETURN(
3163+
left, primitive_handler->NewDateTime(json_primitive.value));
3164+
to_delete.push_back(std::unique_ptr<const Message>(left));
3165+
}
3166+
if (IsInstant(right_message)) {
3167+
FHIR_ASSIGN_OR_RETURN(
3168+
JsonPrimitive json_primitive,
3169+
primitive_handler->WrapPrimitiveProto(right_message));
3170+
json_primitive.value = absl::StripPrefix(json_primitive.value, "\"");
3171+
json_primitive.value = absl::StripSuffix(json_primitive.value, "\"");
3172+
FHIR_ASSIGN_OR_RETURN(
3173+
right, primitive_handler->NewDateTime(json_primitive.value));
3174+
to_delete.push_back(std::unique_ptr<const Message>(right));
3175+
}
3176+
FHIR_ASSIGN_OR_RETURN(DateTimePrecision left_precision,
3177+
primitive_handler->GetDateTimePrecision(*left));
3178+
FHIR_ASSIGN_OR_RETURN(DateTimePrecision right_precision,
3179+
primitive_handler->GetDateTimePrecision(*right));
31563180

31573181
// The FHIRPath spec (http://hl7.org/fhirpath/#comparison) states that "If
31583182
// one value is specified to a different level of precision than the other,
@@ -3164,9 +3188,9 @@ class ComparisonOperator : public BinaryOperator {
31643188
}
31653189

31663190
FHIR_ASSIGN_OR_RETURN(absl::Time left_time,
3167-
primitive_handler->GetDateTimeValue(left_message));
3191+
primitive_handler->GetDateTimeValue(*left));
31683192
FHIR_ASSIGN_OR_RETURN(absl::Time right_time,
3169-
primitive_handler->GetDateTimeValue(right_message));
3193+
primitive_handler->GetDateTimeValue(*right));
31703194

31713195
// negative if left < right, positive if left > right, 0 if equal
31723196
absl::civil_diff_t time_difference =

cc/google/fhir/fhir_path/fhir_path_test.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,30 @@ TYPED_TEST(FhirPathTest, TimeComparison) {
24072407
EvalsToTrue());
24082408
}
24092409

2410+
TYPED_TEST(FhirPathTest, TimeComparison_Instant) {
2411+
auto observation = ParseFromString<typename TypeParam::Observation>(R"pb(
2412+
# 2001-10-28T01:59:00Z
2413+
meta: {
2414+
last_updated: {
2415+
value_us: 1004234340000000
2416+
timezone: "UTC"
2417+
precision: MICROSECOND
2418+
}
2419+
}
2420+
)pb");
2421+
EXPECT_THAT(
2422+
TestFixture::Evaluate(observation, "meta.lastUpdated = meta.lastUpdated"),
2423+
EvalsToTrue());
2424+
EXPECT_THAT(
2425+
TestFixture::Evaluate(observation, "meta.lastUpdated < meta.lastUpdated"),
2426+
EvalsToFalse());
2427+
EXPECT_THAT(
2428+
TestFixture::Evaluate(observation,
2429+
"meta.lastUpdated < @2001-10-28T01:59:10Z and "
2430+
"@2001-10-28T01:58:50 < meta.lastUpdated"),
2431+
EvalsToTrue());
2432+
}
2433+
24102434
TYPED_TEST(FhirPathTest, TimeCompareDifferentPrecision) {
24112435
using DateTime = typename TypeParam::DateTime;
24122436
using DateTimePrecision = typename TypeParam::DateTime::Precision;

examples/bulkdata/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
load("@fhir_bazel_pip_dependencies//:requirements.bzl", "requirement")
2+
13
# Simple client to download data from FHIR server (using bulk data protocol)
24
load(
35
"@rules_python//python:python.bzl",
46
"py_binary",
57
)
6-
load("@fhir_bazel_pip_dependencies//:requirements.bzl", "requirement")
78

89
licenses(["notice"])
910

examples/profiles/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
load("//bazel:proto.bzl", "fhir_proto_library")
2+
load("//bazel:protogen.bzl", "gen_fhir_definitions_and_protos")
3+
14
package(default_visibility = ["//visibility:public"])
25

36
licenses(["notice"])
47

5-
load("//bazel:protogen.bzl", "gen_fhir_definitions_and_protos")
6-
load("//bazel:proto.bzl", "fhir_proto_library")
7-
88
gen_fhir_definitions_and_protos(
99
name = "demo",
1010
additional_proto_imports = [

go/fhirpath/BUILD

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
licenses(["notice"])
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
go_library(
8+
name = "fhirpath",
9+
srcs = ["visitor.go"],
10+
importpath = "github.com/google/fhir/go/fhirpath",
11+
deps = [
12+
"//go/fhirpath/gen",
13+
"@com_github_antrl4_go_antlr//:go_default_library",
14+
],
15+
)

go/fhirpath/gen/BUILD

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
licenses(["notice"])
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
go_library(
8+
name = "gen",
9+
srcs = [
10+
"doc.go",
11+
"fhirpath_base_listener.go",
12+
"fhirpath_base_visitor.go",
13+
"fhirpath_lexer.go",
14+
"fhirpath_listener.go",
15+
"fhirpath_parser.go",
16+
"fhirpath_visitor.go",
17+
],
18+
importpath = "github.com/google/fhir/go/fhirpath/gen",
19+
visibility = [
20+
"//go/fhirpath:__subpackages__",
21+
],
22+
deps = ["@com_github_antrl4_go_antlr//:go_default_library"],
23+
)

go/fhirpath/gen/doc.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package gen is a FHIRPath parser and lexer generated by Antlr. Do not modify the code in this package
16+
package gen

0 commit comments

Comments
 (0)