• 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 android.content.Context
19 import android.graphics.drawable.Drawable
20 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_ALLERGIES_INTOLERANCES
21 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_CONDITIONS
22 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_VACCINES
23 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_LABORATORY_RESULTS
24 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_MEDICATIONS
25 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_PERSONAL_DETAILS
26 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_PRACTITIONER_DETAILS
27 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_PREGNANCY
28 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_PROCEDURES
29 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_SOCIAL_HISTORY
30 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_VISITS
31 import android.health.connect.datatypes.MedicalResource.MEDICAL_RESOURCE_TYPE_VITAL_SIGNS
32 import com.android.healthconnect.controller.R
33 import com.android.healthconnect.controller.utils.AttributeResolver
34 
35 enum class MedicalPermissionType : HealthPermissionType {
36     ALL_MEDICAL_DATA,
37     ALLERGIES_INTOLERANCES,
38     CONDITIONS,
39     LABORATORY_RESULTS,
40     MEDICATIONS,
41     PERSONAL_DETAILS,
42     PRACTITIONER_DETAILS,
43     PREGNANCY,
44     PROCEDURES,
45     SOCIAL_HISTORY,
46     VACCINES,
47     VISITS,
48     VITAL_SIGNS;
49 
lowerCaseLabelnull50     override fun lowerCaseLabel(): Int =
51         MedicalPermissionStrings.fromPermissionType(this).lowercaseLabel
52 
53     override fun upperCaseLabel(): Int =
54         MedicalPermissionStrings.fromPermissionType(this).uppercaseLabel
55 
56     override fun icon(context: Context): Drawable? {
57         val attrRes: Int =
58             when (this) {
59                 ALL_MEDICAL_DATA -> R.attr.medicalServicesIcon
60                 ALLERGIES_INTOLERANCES -> R.attr.allergiesIcon
61                 CONDITIONS -> R.attr.conditionsIcon
62                 LABORATORY_RESULTS -> R.attr.labResultsIcon
63                 MEDICATIONS -> R.attr.medicationsIcon
64                 PERSONAL_DETAILS -> R.attr.patientInfoIcon
65                 PRACTITIONER_DETAILS -> R.attr.practitionerDetailsIcon
66                 PREGNANCY -> R.attr.pregnancyIcon
67                 PROCEDURES -> R.attr.proceduresIcon
68                 SOCIAL_HISTORY -> R.attr.socialHistoryIcon
69                 VACCINES -> R.attr.immunizationIcon
70                 VISITS -> R.attr.pastVisitsIcon
71                 VITAL_SIGNS -> R.attr.vitalsIcon
72             }
73         return AttributeResolver.getDrawable(context, attrRes)
74     }
75 }
76 
isValidMedicalPermissionTypenull77 fun isValidMedicalPermissionType(permissionTypeString: String): Boolean {
78     try {
79         MedicalPermissionType.valueOf(permissionTypeString)
80     } catch (e: IllegalArgumentException) {
81         return false
82     }
83     return true
84 }
85 
fromMedicalResourceTypenull86 fun fromMedicalResourceType(medicalResourceType: Int): MedicalPermissionType {
87     return when (medicalResourceType) {
88         MEDICAL_RESOURCE_TYPE_ALLERGIES_INTOLERANCES -> MedicalPermissionType.ALLERGIES_INTOLERANCES
89         MEDICAL_RESOURCE_TYPE_CONDITIONS -> MedicalPermissionType.CONDITIONS
90         MEDICAL_RESOURCE_TYPE_LABORATORY_RESULTS -> MedicalPermissionType.LABORATORY_RESULTS
91         MEDICAL_RESOURCE_TYPE_MEDICATIONS -> MedicalPermissionType.MEDICATIONS
92         MEDICAL_RESOURCE_TYPE_PERSONAL_DETAILS -> MedicalPermissionType.PERSONAL_DETAILS
93         MEDICAL_RESOURCE_TYPE_PRACTITIONER_DETAILS -> MedicalPermissionType.PRACTITIONER_DETAILS
94         MEDICAL_RESOURCE_TYPE_PREGNANCY -> MedicalPermissionType.PREGNANCY
95         MEDICAL_RESOURCE_TYPE_PROCEDURES -> MedicalPermissionType.PROCEDURES
96         MEDICAL_RESOURCE_TYPE_SOCIAL_HISTORY -> MedicalPermissionType.SOCIAL_HISTORY
97         MEDICAL_RESOURCE_TYPE_VACCINES -> MedicalPermissionType.VACCINES
98         MEDICAL_RESOURCE_TYPE_VISITS -> MedicalPermissionType.VISITS
99         MEDICAL_RESOURCE_TYPE_VITAL_SIGNS -> MedicalPermissionType.VITAL_SIGNS
100         else -> throw IllegalArgumentException("MedicalResourceType is not supported.")
101     }
102 }
103 
toMedicalResourceTypenull104 fun toMedicalResourceType(medicalPermissionType: MedicalPermissionType): Int {
105     return when (medicalPermissionType) {
106         MedicalPermissionType.ALLERGIES_INTOLERANCES -> MEDICAL_RESOURCE_TYPE_ALLERGIES_INTOLERANCES
107         MedicalPermissionType.CONDITIONS -> MEDICAL_RESOURCE_TYPE_CONDITIONS
108         MedicalPermissionType.LABORATORY_RESULTS -> MEDICAL_RESOURCE_TYPE_LABORATORY_RESULTS
109         MedicalPermissionType.MEDICATIONS -> MEDICAL_RESOURCE_TYPE_MEDICATIONS
110         MedicalPermissionType.PERSONAL_DETAILS -> MEDICAL_RESOURCE_TYPE_PERSONAL_DETAILS
111         MedicalPermissionType.PRACTITIONER_DETAILS -> MEDICAL_RESOURCE_TYPE_PRACTITIONER_DETAILS
112         MedicalPermissionType.PREGNANCY -> MEDICAL_RESOURCE_TYPE_PREGNANCY
113         MedicalPermissionType.PROCEDURES -> MEDICAL_RESOURCE_TYPE_PROCEDURES
114         MedicalPermissionType.SOCIAL_HISTORY -> MEDICAL_RESOURCE_TYPE_SOCIAL_HISTORY
115         MedicalPermissionType.VACCINES -> MEDICAL_RESOURCE_TYPE_VACCINES
116         MedicalPermissionType.VISITS -> MEDICAL_RESOURCE_TYPE_VISITS
117         MedicalPermissionType.VITAL_SIGNS -> MEDICAL_RESOURCE_TYPE_VITAL_SIGNS
118         else -> throw IllegalArgumentException("MedicalPermissionType does not map to a MedicalResourceType.")
119     }
120 }
121