• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * ```
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * ```
10  *
11  * Unless required by applicable law or agreed to in writing, software distributed under the License
12  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.android.healthconnect.controller.permissions.data
17 
18 import androidx.annotation.StringRes
19 import com.android.healthconnect.controller.R
20 import com.google.common.collect.ImmutableMap
21 
22 data class MedicalPermissionStrings(
23     @StringRes val uppercaseLabel: Int,
24     @StringRes val lowercaseLabel: Int,
25     @StringRes val contentDescription: Int,
26 ) {
27     companion object {
fromPermissionTypenull28         fun fromPermissionType(
29             medicalPermissionType: MedicalPermissionType
30         ): MedicalPermissionStrings {
31             return PERMISSION_TYPE_STRINGS[medicalPermissionType]
32                 ?: throw IllegalArgumentException(
33                     "No strings for permission group " + medicalPermissionType.name
34                 )
35         }
36     }
37 }
38 
39 private val PERMISSION_TYPE_STRINGS: ImmutableMap<MedicalPermissionType, MedicalPermissionStrings> =
40     ImmutableMap.Builder<MedicalPermissionType, MedicalPermissionStrings>()
41         .put(
42             MedicalPermissionType.ALL_MEDICAL_DATA,
43             MedicalPermissionStrings(
44                 R.string.all_medical_data_uppercase_label,
45                 R.string.all_medical_data_lowercase_label,
46                 R.string.all_medical_data_content_description,
47             ),
48         )
49         .put(
50             MedicalPermissionType.ALLERGIES_INTOLERANCES,
51             MedicalPermissionStrings(
52                 R.string.allergies_intolerances_uppercase_label,
53                 R.string.allergies_intolerances_lowercase_label,
54                 R.string.allergies_intolerances_content_description,
55             )
56         )
57         .put(
58             MedicalPermissionType.CONDITIONS,
59             MedicalPermissionStrings(
60                 R.string.conditions_uppercase_label,
61                 R.string.conditions_lowercase_label,
62                 R.string.conditions_content_description,
63             ),
64         )
65         .put(
66             MedicalPermissionType.LABORATORY_RESULTS,
67             MedicalPermissionStrings(
68                 R.string.laboratory_results_uppercase_label,
69                 R.string.laboratory_results_lowercase_label,
70                 R.string.laboratory_results_content_description,
71             ),
72         )
73         .put(
74             MedicalPermissionType.MEDICATIONS,
75             MedicalPermissionStrings(
76                 R.string.medications_uppercase_label,
77                 R.string.medications_lowercase_label,
78                 R.string.medications_content_description,
79             ),
80         )
81         .put(
82             MedicalPermissionType.PERSONAL_DETAILS,
83             MedicalPermissionStrings(
84                 R.string.personal_details_uppercase_label,
85                 R.string.personal_details_lowercase_label,
86                 R.string.personal_details_content_description,
87             ),
88         )
89         .put(
90             MedicalPermissionType.PRACTITIONER_DETAILS,
91             MedicalPermissionStrings(
92                 R.string.practitioner_details_uppercase_label,
93                 R.string.practitioner_details_lowercase_label,
94                 R.string.practitioner_details_content_description,
95             ),
96         )
97         .put(
98             MedicalPermissionType.PREGNANCY,
99             MedicalPermissionStrings(
100                 R.string.pregnancy_uppercase_label,
101                 R.string.pregnancy_lowercase_label,
102                 R.string.pregnancy_content_description,
103             ),
104         )
105         .put(
106             MedicalPermissionType.PROCEDURES,
107             MedicalPermissionStrings(
108                 R.string.procedures_uppercase_label,
109                 R.string.procedures_lowercase_label,
110                 R.string.procedures_content_description,
111             ),
112         )
113         .put(
114             MedicalPermissionType.SOCIAL_HISTORY,
115             MedicalPermissionStrings(
116                 R.string.social_history_uppercase_label,
117                 R.string.social_history_lowercase_label,
118                 R.string.social_history_content_description,
119             ),
120         )
121         .put(
122             MedicalPermissionType.VACCINES,
123             MedicalPermissionStrings(
124                 R.string.vaccines_uppercase_label,
125                 R.string.vaccines_lowercase_label,
126                 R.string.vaccines_content_description,
127             ),
128         )
129         .put(
130             MedicalPermissionType.VISITS,
131             MedicalPermissionStrings(
132                 R.string.visits_uppercase_label,
133                 R.string.visits_lowercase_label,
134                 R.string.visits_content_description,
135             ),
136         )
137         .put(
138             MedicalPermissionType.VITAL_SIGNS,
139             MedicalPermissionStrings(
140                 R.string.vital_signs_uppercase_label,
141                 R.string.vital_signs_lowercase_label,
142                 R.string.vital_signs_content_description,
143             ),
144         )
145         .buildOrThrow()
146