Skip to content

Commit

Permalink
diffbase
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 624930954
  • Loading branch information
Quarz0 authored and copybara-github committed Apr 15, 2024
1 parent f20f977 commit 90c794c
Show file tree
Hide file tree
Showing 42 changed files with 9,949 additions and 3,917 deletions.
5 changes: 3 additions & 2 deletions bazel/antlr4_cc.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Build rules to create C++ code from an Antlr4 grammar."""

load("@rules_java//java:defs.bzl", "java_binary")

def antlr4_cc_lexer(name, src, namespaces = None, imports = None, deps = None, lib_import = None):
"""Generates the C++ source corresponding to an antlr4 lexer definition.
Expand All @@ -25,8 +27,7 @@ def antlr4_cc_lexer(name, src, namespaces = None, imports = None, deps = None, l
"%sLexer.h" % base_file_prefix,
"%sLexer.cpp" % base_file_prefix,
]

native.java_binary(
java_binary(
name = "antlr_tool",
jvm_flags = ["-Xmx256m"],
main_class = "org.antlr.v4.Tool",
Expand Down
6 changes: 6 additions & 0 deletions bazel/go_dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,9 @@ def fhir_go_dependencies():
sum = "h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=",
version = "v0.0.0-20191204190536-9bdfabe68543",
)
go_repository(
name = "com_github_antrl4_go_antlr",
importpath = "github.com/antlr4-go/antlr/v4",
sum = "h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=",
version = "v4.13.0",
)
8 changes: 4 additions & 4 deletions bazel/protogen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Rules for generating Protos from FHIR definitions"""

load("@rules_java//java:defs.bzl", "java_binary", "java_test")

R4_PACKAGE_DEP = "@com_google_fhir//spec:fhir_r4"
PROTO_GENERATOR = "@com_google_fhir//java/com/google/fhir/protogen:ProtoGenerator"
PROFILE_GENERATOR = "@com_google_fhir//java/com/google/fhir/protogen:ProfileGenerator"
Expand Down Expand Up @@ -151,8 +152,7 @@ def gen_fhir_protos(
"-Dgolden_dir=" + src_dir,
"-Xmx4096M",
]

native.java_test(
java_test(
name = "GeneratedProtoTest_" + name,
size = "medium",
srcs = ["//external:GeneratedProtoTest.java"],
Expand Down Expand Up @@ -294,7 +294,7 @@ def _get_tar_for_pkg(pkg):
return pkg + "_package.tgz"

def _proto_generator_with_runtime_deps_on_existing_protos(name, golden_java_protos_rules):
native.java_binary(
java_binary(
name = name,
main_class = "com.google.fhir.protogen.ProtoGeneratorMain",
runtime_deps = golden_java_protos_rules +
Expand Down
1 change: 1 addition & 0 deletions cc/google/fhir/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ cc_library(
":util",
"//cc/google/fhir/json:fhir_json",
"//cc/google/fhir/status",
"//cc/google/fhir/status:statusor",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
Expand Down
8 changes: 2 additions & 6 deletions cc/google/fhir/fhir_path/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ cc_library(
"fhir_path_types.h",
],
strip_include_prefix = "//cc/",
visibility = [
"//visibility:private", # Only private by automation, not intent. Owner may accept CLs adding visibility. See go/scheuklappen#explicit-private.
],
visibility = ["//visibility:private"],
deps = [
"//cc/google/fhir:annotations",
"//cc/google/fhir:fhir_types",
Expand All @@ -143,9 +141,7 @@ cc_library(
"utils.h",
],
strip_include_prefix = "//cc/",
visibility = [
"//visibility:private", # Only private by automation, not intent. Owner may accept CLs adding visibility. See go/scheuklappen#explicit-private.
],
visibility = ["//visibility:private"],
deps = [
"//cc/google/fhir:annotations",
"//cc/google/fhir:references",
Expand Down
42 changes: 33 additions & 9 deletions cc/google/fhir/fhir_path/fhir_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@
#include "google/fhir/fhir_path/fhir_path_types.h"
#include "google/fhir/fhir_path/utils.h"
#include "google/fhir/fhir_types.h"
#include "google/fhir/primitive_handler.h"
#include "google/fhir/proto_util.h"
#include "google/fhir/status/status.h"
#include "google/fhir/status/statusor.h"
#include "google/fhir/util.h"
#include "proto/google/fhir/proto/r4/core/datatypes.pb.h"
#include "icu4c/source/common/unicode/unistr.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/message.h"

namespace google {
namespace fhir {
Expand Down Expand Up @@ -3039,7 +3041,8 @@ class ComparisonOperator : public BinaryOperator {

} else if (IsSystemString(*left_result) && IsSystemString(*right_result)) {
return EvalStringComparison(primitive_handler, left, right);
} else if (IsDateTime(*left_result) && IsDateTime(*right_result)) {
} else if ((IsInstant(*left_result) || IsDateTime(*left_result)) &&
(IsInstant(*right_result) || IsDateTime(*right_result))) {
return EvalDateTimeComparison(primitive_handler, *left_result,
*right_result);
} else if (IsSimpleQuantity(*left_result) &&
Expand Down Expand Up @@ -3147,12 +3150,33 @@ class ComparisonOperator : public BinaryOperator {
absl::StatusOr<absl::optional<bool>> EvalDateTimeComparison(
const PrimitiveHandler* primitive_handler, const Message& left_message,
const Message& right_message) const {
FHIR_ASSIGN_OR_RETURN(
DateTimePrecision left_precision,
primitive_handler->GetDateTimePrecision(left_message));
FHIR_ASSIGN_OR_RETURN(
DateTimePrecision right_precision,
primitive_handler->GetDateTimePrecision(right_message));
const Message* left = &left_message;
const Message* right = &right_message;
std::vector<std::unique_ptr<const Message>> to_delete;
if (IsInstant(left_message)) {
FHIR_ASSIGN_OR_RETURN(
JsonPrimitive json_primitive,
primitive_handler->WrapPrimitiveProto(left_message));
json_primitive.value = absl::StripPrefix(json_primitive.value, "\"");
json_primitive.value = absl::StripSuffix(json_primitive.value, "\"");
FHIR_ASSIGN_OR_RETURN(
left, primitive_handler->NewDateTime(json_primitive.value));
to_delete.push_back(std::unique_ptr<const Message>(left));
}
if (IsInstant(right_message)) {
FHIR_ASSIGN_OR_RETURN(
JsonPrimitive json_primitive,
primitive_handler->WrapPrimitiveProto(right_message));
json_primitive.value = absl::StripPrefix(json_primitive.value, "\"");
json_primitive.value = absl::StripSuffix(json_primitive.value, "\"");
FHIR_ASSIGN_OR_RETURN(
right, primitive_handler->NewDateTime(json_primitive.value));
to_delete.push_back(std::unique_ptr<const Message>(right));
}
FHIR_ASSIGN_OR_RETURN(DateTimePrecision left_precision,
primitive_handler->GetDateTimePrecision(*left));
FHIR_ASSIGN_OR_RETURN(DateTimePrecision right_precision,
primitive_handler->GetDateTimePrecision(*right));

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

FHIR_ASSIGN_OR_RETURN(absl::Time left_time,
primitive_handler->GetDateTimeValue(left_message));
primitive_handler->GetDateTimeValue(*left));
FHIR_ASSIGN_OR_RETURN(absl::Time right_time,
primitive_handler->GetDateTimeValue(right_message));
primitive_handler->GetDateTimeValue(*right));

// negative if left < right, positive if left > right, 0 if equal
absl::civil_diff_t time_difference =
Expand Down
24 changes: 24 additions & 0 deletions cc/google/fhir/fhir_path/fhir_path_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,30 @@ TYPED_TEST(FhirPathTest, TimeComparison) {
EvalsToTrue());
}

TYPED_TEST(FhirPathTest, TimeComparison_Instant) {
auto observation = ParseFromString<typename TypeParam::Observation>(R"pb(
# 2001-10-28T01:59:00Z
meta: {
last_updated: {
value_us: 1004234340000000
timezone: "UTC"
precision: MICROSECOND
}
}
)pb");
EXPECT_THAT(
TestFixture::Evaluate(observation, "meta.lastUpdated = meta.lastUpdated"),
EvalsToTrue());
EXPECT_THAT(
TestFixture::Evaluate(observation, "meta.lastUpdated < meta.lastUpdated"),
EvalsToFalse());
EXPECT_THAT(
TestFixture::Evaluate(observation,
"meta.lastUpdated < @2001-10-28T01:59:10Z and "
"@2001-10-28T01:58:50 < meta.lastUpdated"),
EvalsToTrue());
}

TYPED_TEST(FhirPathTest, TimeCompareDifferentPrecision) {
using DateTime = typename TypeParam::DateTime;
using DateTimePrecision = typename TypeParam::DateTime::Precision;
Expand Down
3 changes: 2 additions & 1 deletion examples/bulkdata/BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
load("@fhir_bazel_pip_dependencies//:requirements.bzl", "requirement")

# Simple client to download data from FHIR server (using bulk data protocol)
load(
"@rules_python//python:python.bzl",
"py_binary",
)
load("@fhir_bazel_pip_dependencies//:requirements.bzl", "requirement")

licenses(["notice"])

Expand Down
6 changes: 3 additions & 3 deletions examples/profiles/BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
load("//bazel:proto.bzl", "fhir_proto_library")
load("//bazel:protogen.bzl", "gen_fhir_definitions_and_protos")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

load("//bazel:protogen.bzl", "gen_fhir_definitions_and_protos")
load("//bazel:proto.bzl", "fhir_proto_library")

gen_fhir_definitions_and_protos(
name = "demo",
additional_proto_imports = [
Expand Down
15 changes: 15 additions & 0 deletions go/fhirpath/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

licenses(["notice"])

package(default_visibility = ["//visibility:public"])

go_library(
name = "fhirpath",
srcs = ["visitor.go"],
importpath = "github.com/google/fhir/go/fhirpath",
deps = [
"//go/fhirpath/gen",
"@com_github_antrl4_go_antlr//:go_default_library",
],
)
23 changes: 23 additions & 0 deletions go/fhirpath/gen/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

licenses(["notice"])

package(default_visibility = ["//visibility:public"])

go_library(
name = "gen",
srcs = [
"doc.go",
"fhirpath_base_listener.go",
"fhirpath_base_visitor.go",
"fhirpath_lexer.go",
"fhirpath_listener.go",
"fhirpath_parser.go",
"fhirpath_visitor.go",
],
importpath = "github.com/google/fhir/go/fhirpath/gen",
visibility = [
"//go/fhirpath:__subpackages__",
],
deps = ["@com_github_antrl4_go_antlr//:go_default_library"],
)
16 changes: 16 additions & 0 deletions go/fhirpath/gen/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package gen is a FHIRPath parser and lexer generated by Antlr. Do not modify the code in this package
package gen
Loading

0 comments on commit 90c794c

Please sign in to comment.