1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.healthconnect.storage.datatypehelpers; 18 19 import static com.android.server.healthconnect.storage.utils.StorageUtils.INTEGER_NOT_NULL; 20 21 import android.content.ContentValues; 22 import android.util.Pair; 23 24 import com.android.server.healthconnect.storage.request.CreateTableRequest; 25 import com.android.server.healthconnect.storage.request.UpsertTableRequest; 26 27 import java.util.Collections; 28 import java.util.List; 29 30 /** 31 * Helper class for medical_resource_indices table. This is a child table of medical_resource_table 32 * and will store extracted information from the FHIR JSONs (e.g. display name) and the category 33 * each MedicalResource belongs to. For more context: http://shortn/_E5yENKUACX 34 * 35 * @hide 36 */ 37 public class MedicalResourceIndicesHelper { 38 private static final String MEDICAL_RESOURCE_INDICES_TABLE_NAME = 39 "medical_resource_indices_table"; 40 private static final String MEDICAL_RESOURCE_TYPE = "medical_resource_type"; 41 private static final String MEDICAL_RESOURCE_ID = "medical_resource_id"; 42 getTableName()43 public static String getTableName() { 44 return MEDICAL_RESOURCE_INDICES_TABLE_NAME; 45 } 46 getParentColumnReference()47 public static String getParentColumnReference() { 48 return MEDICAL_RESOURCE_ID; 49 } 50 getMedicalResourceTypeColumnName()51 public static String getMedicalResourceTypeColumnName() { 52 return MEDICAL_RESOURCE_TYPE; 53 } 54 getCreateMedicalResourceIndicesTableRequest()55 public static CreateTableRequest getCreateMedicalResourceIndicesTableRequest() { 56 return new CreateTableRequest( 57 MEDICAL_RESOURCE_INDICES_TABLE_NAME, 58 getMedicalResourceIndicesTableColumnInfo()) 59 .addForeignKey( 60 MedicalResourceHelper.getMainTableName(), 61 Collections.singletonList(MEDICAL_RESOURCE_ID), 62 Collections.singletonList(MedicalResourceHelper.getPrimaryColumn())); 63 } 64 65 /** Creates {@link UpsertTableRequest} for medical_resource_indices table. */ getContentValues(long parentRowId, int medicalResourceType)66 public static ContentValues getContentValues(long parentRowId, int medicalResourceType) { 67 ContentValues contentValues = new ContentValues(); 68 contentValues.put(MEDICAL_RESOURCE_TYPE, medicalResourceType); 69 contentValues.put(MEDICAL_RESOURCE_ID, parentRowId); 70 return contentValues; 71 } 72 getMedicalResourceIndicesTableColumnInfo()73 private static List<Pair<String, String>> getMedicalResourceIndicesTableColumnInfo() { 74 return List.of( 75 Pair.create(MEDICAL_RESOURCE_ID, INTEGER_NOT_NULL), 76 Pair.create(MEDICAL_RESOURCE_TYPE, INTEGER_NOT_NULL)); 77 } 78 } 79