1// Copyright (C) 2024 The Android Open Source Project 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// This file contains the proto libraries, python script and genrule required for FHIR structural 16// validation of PHR medical data. 17// The python script generate_fhir_spec.py reads in the FHIR spec json files published by FHIR 18// (located in the android external folder). The official spec is then used to generate a fhirspec 19// proto message that is written to "fhirspec-r4.binarypb". This file is then added to 20// java_resources of the HC service to be used for the validation of incoming FHIR resources, 21// specifically in the FhirSpecProvider class. 22 23package { 24 default_applicable_licenses: ["Android-Apache-2.0"], 25 default_team: "trendy_team_android_health", 26} 27 28filegroup { 29 name: "fhirspec-proto", 30 srcs: [ 31 "*.proto", 32 ], 33} 34 35// Generate the java fhirspec proto library, used for capturing FHIR spec details for validation 36java_library { 37 name: "fhirspec-java-proto-lite", 38 sdk_version: "core_current", 39 proto: { 40 type: "lite", 41 include_dirs: [ 42 "external/protobuf/src", 43 "external/protobuf/java", 44 ], 45 }, 46 srcs: [ 47 ":fhirspec-proto", 48 ":libprotobuf-internal-protos", 49 ], 50 static_libs: ["libprotobuf-java-lite"], 51 apex_available: ["com.android.healthfitness"], 52} 53 54// Generate the python fhirspec proto library, used for capturing FHIR spec details for validation 55python_library_host { 56 name: "fhirspec-py-proto", 57 srcs: [ 58 "fhirspec.proto", 59 ], 60 proto: { 61 canonical_path_from_root: false, 62 }, 63} 64 65python_library_host { 66 name: "fhir-spec-extractor", 67 srcs: [ 68 "fhir_spec_extractor.py", 69 ], 70 libs: [ 71 "fhirspec-py-proto", 72 ], 73} 74 75python_test_host { 76 name: "fhir-spec-extractor-test", 77 main: "fhir_spec_extractor_test.py", 78 srcs: [ 79 "fhir_spec_extractor_test.py", 80 ], 81 libs: [ 82 "fhirspec-py-proto", 83 "fhir-spec-extractor", 84 ], 85 test_options: { 86 unit_test: true, 87 }, 88 version: { 89 py3: { 90 embedded_launcher: true, 91 }, 92 }, 93} 94 95// Python script for generating a FhirResourceSpec proto message based on fhir spec json files 96python_binary_host { 97 name: "generate-fhir-spec", 98 main: "generate_fhir_spec.py", 99 srcs: [ 100 "generate_fhir_spec.py", 101 ], 102 libs: [ 103 "fhirspec-py-proto", 104 "fhir-spec-extractor", 105 ], 106} 107 108// Genrule that runs generate_fhir_spec.py to generate a FhirResourceSpec proto binary file 109genrule { 110 name: "generate-fhir-spec-r4-binarypb", 111 srcs: [ 112 "//external/fhir/spec/r4:resource-definitions", 113 ], 114 tools: ["generate-fhir-spec"], 115 cmd: "$(location generate-fhir-spec) $(out) $(in)", 116 out: ["fhirspec-r4.binarypb"], 117} 118