-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project import generated by Copybara.
PiperOrigin-RevId: 581320593
- Loading branch information
1 parent
8fccb51
commit 3fff997
Showing
1,241 changed files
with
345,523 additions
and
5 deletions.
There are no files selected for viewing
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,109 @@ | ||
licenses(["notice"]) | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "primitive_handler", | ||
srcs = ["primitive_handler.cc"], | ||
hdrs = ["primitive_handler.h"], | ||
strip_include_prefix = "//cc/", | ||
deps = [ | ||
"//cc/google/fhir:annotations", | ||
"//cc/google/fhir:json_format_results", | ||
"//cc/google/fhir:primitive_handler", | ||
"//cc/google/fhir:primitive_wrapper", | ||
"//cc/google/fhir:proto_util", | ||
"//cc/google/fhir/status", | ||
"//cc/google/fhir/status:statusor", | ||
"//proto/google/fhir/proto/dstu2:codes_cc_proto", | ||
"//proto/google/fhir/proto/dstu2:datatypes_cc_proto", | ||
"//proto/google/fhir/proto/dstu2:fhirproto_extensions_cc_proto", | ||
"//proto/google/fhir/proto/dstu2:resources_cc_proto", | ||
"@com_google_absl//absl/status", | ||
"@com_google_absl//absl/status:statusor", | ||
"@com_google_absl//absl/strings", | ||
"@com_google_protobuf//:protobuf", | ||
], | ||
) | ||
|
||
cc_test( | ||
name = "primitive_handler_test", | ||
size = "large", | ||
srcs = ["primitive_handler_test.cc"], | ||
data = [ | ||
"//testdata/dstu2:validation", | ||
], | ||
deps = [ | ||
":json_format", | ||
":primitive_handler", | ||
"//cc/google/fhir:annotations", | ||
"//cc/google/fhir:error_reporter", | ||
"//cc/google/fhir:test_helper", | ||
"//cc/google/fhir/status", | ||
"//proto/google/fhir/proto/dstu2:datatypes_cc_proto", | ||
"//proto/google/fhir/proto/dstu2:fhirproto_extensions_cc_proto", | ||
"//proto/google/fhir/proto/dstu2:resources_cc_proto", | ||
"@com_google_absl//absl/status:statusor", | ||
"@com_google_absl//absl/strings", | ||
"@com_google_googletest//:gtest_main", | ||
"@com_google_protobuf//:protobuf", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "json_format", | ||
srcs = ["json_format.cc"], | ||
hdrs = ["json_format.h"], | ||
strip_include_prefix = "//cc/", | ||
deps = [ | ||
":primitive_handler", | ||
"//cc/google/fhir:error_reporter", | ||
"//cc/google/fhir:json_format", | ||
"//cc/google/fhir:json_format_results", | ||
"@com_google_absl//absl/status:statusor", | ||
"@com_google_absl//absl/strings", | ||
], | ||
) | ||
|
||
cc_test( | ||
name = "json_format_test", | ||
size = "large", | ||
srcs = ["json_format_test.cc"], | ||
data = [ | ||
"//spec:dstu2", | ||
"//testdata/dstu2:examples", | ||
"//testdata/jsonformat", | ||
], | ||
shard_count = 10, | ||
deps = [ | ||
":json_format", | ||
":primitive_handler", | ||
"//cc/google/fhir:test_helper", | ||
"//cc/google/fhir/json:fhir_json", | ||
"//cc/google/fhir/json:json_sax_handler", | ||
"//cc/google/fhir/json:test_matchers", | ||
"//cc/google/fhir/testutil:proto_matchers", | ||
"//proto/google/fhir/proto:annotations_cc_proto", | ||
"//proto/google/fhir/proto/dstu2:codes_cc_proto", | ||
"//proto/google/fhir/proto/dstu2:datatypes_cc_proto", | ||
"//proto/google/fhir/proto/dstu2:resources_cc_proto", | ||
"@com_google_absl//absl/status:statusor", | ||
"@com_google_absl//absl/strings", | ||
"@com_google_googletest//:gtest_main", | ||
"@com_google_protobuf//:protobuf", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "fhir_test_env", | ||
testonly = 1, | ||
hdrs = ["fhir_test_env.h"], | ||
strip_include_prefix = "//cc/", | ||
deps = [ | ||
":primitive_handler", | ||
"//cc/google/fhir:primitive_handler", | ||
"//cc/google/fhir:type_macros", | ||
"//cc/google/fhir:util", | ||
"//proto/google/fhir/proto/dstu2:resources_cc_proto", | ||
], | ||
) |
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,76 @@ | ||
// Copyright 2020 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. | ||
|
||
#ifndef GOOGLE_FHIR_DSTU2_FHIR_TEST_ENV_H_ | ||
#define GOOGLE_FHIR_DSTU2_FHIR_TEST_ENV_H_ | ||
|
||
#include "google/fhir/dstu2/primitive_handler.h" | ||
#include "google/fhir/primitive_handler.h" | ||
#include "google/fhir/type_macros.h" | ||
#include "google/fhir/util.h" | ||
#include "proto/google/fhir/proto/dstu2/resources.pb.h" | ||
|
||
namespace google { | ||
namespace fhir { | ||
namespace dstu2 { | ||
|
||
template <typename BundleType, typename PrimitiveHandlerType> | ||
struct Dstu2FhirTestEnv { | ||
using PrimitiveHandler = PrimitiveHandlerType; | ||
|
||
// Primitives + Datatypes | ||
using Boolean = FHIR_DATATYPE(BundleType, boolean); | ||
using Code = FHIR_DATATYPE(BundleType, code); | ||
using CodeableConcept = FHIR_DATATYPE(BundleType, codeable_concept); | ||
using Coding = FHIR_DATATYPE(BundleType, coding); | ||
using DateTime = FHIR_DATATYPE(BundleType, date_time); | ||
using Decimal = FHIR_DATATYPE(BundleType, decimal); | ||
using Integer = FHIR_DATATYPE(BundleType, integer); | ||
using Period = FHIR_DATATYPE(BundleType, period); | ||
using PositiveInt = FHIR_DATATYPE(BundleType, positive_int); | ||
using Quantity = FHIR_DATATYPE(BundleType, quantity); | ||
using Range = FHIR_DATATYPE(BundleType, range); | ||
using Reference = FHIR_DATATYPE(BundleType, reference); | ||
using String = FHIR_DATATYPE(BundleType, string_value); | ||
using UnsignedInt = FHIR_DATATYPE(BundleType, unsigned_int); | ||
|
||
// Resources | ||
using Bundle = BundleType; | ||
using ContainedResource = BUNDLE_CONTAINED_RESOURCE(BundleType); | ||
|
||
using Binary = BUNDLE_TYPE(BundleType, binary); | ||
using Encounter = BUNDLE_TYPE(BundleType, encounter); | ||
using Claim = BUNDLE_TYPE(BundleType, claim); | ||
using Condition = BUNDLE_TYPE(BundleType, condition); | ||
using Composition = BUNDLE_TYPE(BundleType, composition); | ||
using Medication = BUNDLE_TYPE(BundleType, medication); | ||
using MedicationAdministration = BUNDLE_TYPE(BundleType, | ||
medication_administration); | ||
using Observation = BUNDLE_TYPE(BundleType, observation); | ||
using Organization = BUNDLE_TYPE(BundleType, organization); | ||
using Parameters = BUNDLE_TYPE(BundleType, parameters); | ||
using Patient = BUNDLE_TYPE(BundleType, patient); | ||
using Procedure = BUNDLE_TYPE(BundleType, procedure); | ||
using StructureDefinition = BUNDLE_TYPE(BundleType, structure_definition); | ||
using ValueSet = BUNDLE_TYPE(BundleType, value_set); | ||
}; | ||
|
||
using Dstu2CoreTestEnv = | ||
Dstu2FhirTestEnv<dstu2::proto::Bundle, dstu2::DSTU2PrimitiveHandler>; | ||
|
||
} // namespace dstu2 | ||
} // namespace fhir | ||
} // namespace google | ||
|
||
#endif // GOOGLE_FHIR_DSTU2_FHIR_TEST_ENV_H_ |
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,88 @@ | ||
/* | ||
* Copyright 2020 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. | ||
*/ | ||
|
||
#include "google/fhir/dstu2/json_format.h" | ||
|
||
#include <string> | ||
|
||
#include "absl/status/statusor.h" | ||
#include "google/fhir/dstu2/primitive_handler.h" | ||
#include "google/fhir/error_reporter.h" | ||
#include "google/fhir/json_format.h" | ||
#include "google/fhir/json_format_results.h" | ||
|
||
namespace google { | ||
namespace fhir { | ||
namespace dstu2 { | ||
|
||
namespace { | ||
|
||
const Parser* GetParser() { | ||
static Parser* parser = new Parser(DSTU2PrimitiveHandler::GetInstance()); | ||
return parser; | ||
} | ||
|
||
const Printer* GetPrinter() { | ||
static Printer* printer = new Printer(DSTU2PrimitiveHandler::GetInstance()); | ||
return printer; | ||
} | ||
|
||
} // namespace | ||
|
||
absl::Status MergeJsonFhirStringIntoProto(const absl::string_view raw_json, | ||
google::protobuf::Message* target, | ||
absl::TimeZone default_timezone, | ||
const bool validate, | ||
ErrorHandler& error_handler) { | ||
FHIR_ASSIGN_OR_RETURN( | ||
ParseResult result, | ||
GetParser()->MergeJsonFhirStringIntoProto( | ||
raw_json, target, default_timezone, validate, error_handler)); | ||
if (result == ParseResult::kFailed) { | ||
return absl::InvalidArgumentError( | ||
"Merge failure when parsing JSON. See ErrorHandler for more info."); | ||
} | ||
return absl::OkStatus(); | ||
} | ||
|
||
absl::StatusOr<std::string> PrintFhirPrimitive( | ||
const ::google::protobuf::Message& message) { | ||
return GetPrinter()->PrintFhirPrimitive(message); | ||
} | ||
|
||
absl::StatusOr<std::string> PrintFhirToJsonString( | ||
const google::protobuf::Message& fhir_proto) { | ||
return GetPrinter()->PrintFhirToJsonString(fhir_proto); | ||
} | ||
|
||
absl::StatusOr<std::string> PrettyPrintFhirToJsonString( | ||
const google::protobuf::Message& fhir_proto) { | ||
return GetPrinter()->PrettyPrintFhirToJsonString(fhir_proto); | ||
} | ||
|
||
absl::StatusOr<std::string> PrintFhirToJsonStringForAnalytics( | ||
const google::protobuf::Message& fhir_proto) { | ||
return GetPrinter()->PrintFhirToJsonStringForAnalytics(fhir_proto); | ||
} | ||
|
||
absl::StatusOr<std::string> PrettyPrintFhirToJsonStringForAnalytics( | ||
const google::protobuf::Message& fhir_proto) { | ||
return GetPrinter()->PrettyPrintFhirToJsonStringForAnalytics(fhir_proto); | ||
} | ||
|
||
} // namespace dstu2 | ||
} // namespace fhir | ||
} // namespace google |
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,78 @@ | ||
/* | ||
* Copyright 2020 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. | ||
*/ | ||
|
||
#ifndef GOOGLE_FHIR_DSTU2_JSON_FORMAT_H_ | ||
#define GOOGLE_FHIR_DSTU2_JSON_FORMAT_H_ | ||
|
||
#include <string> | ||
|
||
#include "absl/status/statusor.h" | ||
#include "absl/strings/string_view.h" | ||
#include "google/fhir/error_reporter.h" | ||
#include "google/fhir/json_format.h" | ||
|
||
namespace google { | ||
namespace fhir { | ||
namespace dstu2 { | ||
|
||
// DSTU2-only API for cc/json_format.h | ||
// See cc/json_format.h for documentation on these methods | ||
|
||
absl::Status MergeJsonFhirStringIntoProto( | ||
absl::string_view raw_json, google::protobuf::Message* target, | ||
absl::TimeZone default_timezone, const bool validate, | ||
ErrorHandler& error_handler = FailFastErrorHandler::FailOnErrorOrFatal()); | ||
|
||
template <typename R> | ||
absl::StatusOr<R> JsonFhirStringToProto( | ||
absl::string_view raw_json, const absl::TimeZone default_timezone, | ||
ErrorHandler& error_handler = FailFastErrorHandler::FailOnErrorOrFatal()) { | ||
R resource; | ||
FHIR_RETURN_IF_ERROR(MergeJsonFhirStringIntoProto( | ||
raw_json, &resource, default_timezone, true, error_handler)); | ||
return resource; | ||
} | ||
|
||
template <typename R> | ||
absl::StatusOr<R> JsonFhirStringToProtoWithoutValidating( | ||
absl::string_view raw_json, const absl::TimeZone default_timezone, | ||
ErrorHandler& error_handler = FailFastErrorHandler::FailOnErrorOrFatal()) { | ||
R resource; | ||
FHIR_RETURN_IF_ERROR(MergeJsonFhirStringIntoProto( | ||
raw_json, &resource, default_timezone, false, error_handler)); | ||
return resource; | ||
} | ||
|
||
absl::StatusOr<std::string> PrintFhirPrimitive( | ||
const ::google::protobuf::Message& message); | ||
|
||
absl::StatusOr<std::string> PrintFhirToJsonString( | ||
const google::protobuf::Message& fhir_proto); | ||
|
||
absl::StatusOr<std::string> PrettyPrintFhirToJsonString( | ||
const google::protobuf::Message& fhir_proto); | ||
|
||
absl::StatusOr<std::string> PrintFhirToJsonStringForAnalytics( | ||
const google::protobuf::Message& fhir_proto); | ||
|
||
absl::StatusOr<std::string> PrettyPrintFhirToJsonStringForAnalytics( | ||
const google::protobuf::Message& fhir_proto); | ||
|
||
} // namespace dstu2 | ||
} // namespace fhir | ||
} // namespace google | ||
|
||
#endif // GOOGLE_FHIR_DSTU2_JSON_FORMAT_H_ |
Oops, something went wrong.