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-utils", 67 srcs: [ 68 "fhir_spec_utils.py", 69 ], 70} 71 72python_library_host { 73 name: "fhir-spec-extractor", 74 srcs: [ 75 "fhir_spec_extractor.py", 76 ], 77 libs: [ 78 "fhirspec-py-proto", 79 "fhir-spec-utils", 80 ], 81} 82 83// Python script for generating a FhirResourceSpec proto message based on fhir spec json files 84python_binary_host { 85 name: "generate-fhir-spec", 86 main: "generate_fhir_spec.py", 87 srcs: [ 88 "generate_fhir_spec.py", 89 ], 90 libs: [ 91 "fhirspec-py-proto", 92 "fhir-spec-extractor", 93 ], 94} 95 96// Genrule that runs generate_fhir_spec.py to generate a FhirResourceSpec proto binary file 97genrule { 98 name: "generate-fhir-spec-r4-binarypb", 99 srcs: [ 100 "//external/fhir/spec/r4:resource-definitions", 101 "//external/fhir/spec/r4:type-definitions", 102 ], 103 tools: ["generate-fhir-spec"], 104 cmd: "$(location generate-fhir-spec) $(out) $(in)", 105 out: ["fhirspec-r4.binarypb"], 106} 107