• 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");
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.request;
18 
19 import static java.util.Objects.hash;
20 import static java.util.Objects.requireNonNull;
21 
22 import android.health.connect.MedicalResourceId;
23 import android.health.connect.UpsertMedicalResourceRequest;
24 import android.health.connect.datatypes.FhirResource.FhirResourceType;
25 import android.health.connect.datatypes.FhirVersion;
26 import android.health.connect.datatypes.MedicalResource.MedicalResourceType;
27 
28 /**
29  * Internal representation of {@link UpsertMedicalResourceRequest}.
30  *
31  * @hide
32  */
33 public final class UpsertMedicalResourceInternalRequest {
34     private String mDataSourceId = "";
35     private String mData = "";
36     @MedicalResourceType private int mMedicalResourceType;
37     @FhirResourceType private int mFhirResourceType;
38     private String mFhirResourceId = "";
39     private String mFhirVersion = "";
40 
41     /** Returns The data source ID where the data comes from. */
getDataSourceId()42     public String getDataSourceId() {
43         return mDataSourceId;
44     }
45 
46     /** Returns this object with the data source ID. */
setDataSourceId(String dataSourceId)47     public UpsertMedicalResourceInternalRequest setDataSourceId(String dataSourceId) {
48         requireNonNull(dataSourceId);
49         mDataSourceId = dataSourceId;
50         return this;
51     }
52 
53     /** Returns the FHIR resource data in JSON representation. */
getData()54     public String getData() {
55         return mData;
56     }
57 
58     /** Returns this object with the FHIR resource data in JSON representation. */
setData(String data)59     public UpsertMedicalResourceInternalRequest setData(String data) {
60         requireNonNull(data);
61         mData = data;
62         return this;
63     }
64 
65     /** Returns the {@code IntDef} {@link MedicalResourceType} of the {@code mData}. */
66     @MedicalResourceType
getMedicalResourceType()67     public int getMedicalResourceType() {
68         return mMedicalResourceType;
69     }
70 
71     /** Returns this object with the medical resource type. */
setMedicalResourceType( @edicalResourceType int medicalResourceType)72     public UpsertMedicalResourceInternalRequest setMedicalResourceType(
73             @MedicalResourceType int medicalResourceType) {
74         mMedicalResourceType = medicalResourceType;
75         return this;
76     }
77 
78     /**
79      * Returns the FHIR resource type. This is extracted from the "resourceType" field in {@code
80      * mData}, and mapped into an {@code IntDef} {@link FhirResourceType}.
81      */
82     @FhirResourceType
getFhirResourceType()83     public int getFhirResourceType() {
84         return mFhirResourceType;
85     }
86 
87     /** Returns this object with the FHIR resource type. */
setFhirResourceType( @hirResourceType int fhirResourceType)88     public UpsertMedicalResourceInternalRequest setFhirResourceType(
89             @FhirResourceType int fhirResourceType) {
90         mFhirResourceType = fhirResourceType;
91         return this;
92     }
93 
94     /** Returns the FHIR resource id extracted from the FHIR JSON. */
getFhirResourceId()95     public String getFhirResourceId() {
96         return mFhirResourceId;
97     }
98 
99     /** Returns this object with the FHIR resource id. */
setFhirResourceId(String fhirResourceId)100     public UpsertMedicalResourceInternalRequest setFhirResourceId(String fhirResourceId) {
101         requireNonNull(fhirResourceId);
102         mFhirResourceId = fhirResourceId;
103         return this;
104     }
105 
106     /** Returns the FHIR version as string. */
getFhirVersion()107     public String getFhirVersion() {
108         return mFhirVersion;
109     }
110 
111     /** Returns this object with the FHIR version string. */
setFhirVersion(FhirVersion fhirVersion)112     public UpsertMedicalResourceInternalRequest setFhirVersion(FhirVersion fhirVersion) {
113         requireNonNull(fhirVersion);
114         mFhirVersion = fhirVersion.toString();
115         return this;
116     }
117 
118     /**
119      * Creates a {@link MedicalResourceId} from the provided values.
120      *
121      * @throws IllegalArgumentException if any values are invalid.
122      */
getMedicalResourceId()123     public MedicalResourceId getMedicalResourceId() {
124         return new MedicalResourceId(mDataSourceId, mFhirResourceType, mFhirResourceId);
125     }
126 
127     @Override
equals(Object o)128     public boolean equals(Object o) {
129         if (this == o) return true;
130         if (!(o instanceof UpsertMedicalResourceInternalRequest that)) return false;
131         return getDataSourceId().equals(that.getDataSourceId())
132                 && getMedicalResourceType() == that.getMedicalResourceType()
133                 && getFhirResourceType() == that.getFhirResourceType()
134                 && getFhirResourceId().equals(that.getFhirResourceId())
135                 && getFhirVersion().equals(that.getFhirVersion())
136                 && getData().equals(that.getData());
137     }
138 
139     @Override
hashCode()140     public int hashCode() {
141         return hash(
142                 getDataSourceId(),
143                 getMedicalResourceType(),
144                 getFhirResourceType(),
145                 getFhirResourceId(),
146                 getFhirVersion(),
147                 getData());
148     }
149 }
150