1 /*
2  * Copyright (C) 2023 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 package android.health.connect.internal.datatypes;
17 
18 import android.annotation.NonNull;
19 import android.health.connect.datatypes.BloodPressureRecord;
20 import android.health.connect.datatypes.BloodPressureRecord.BloodPressureMeasurementLocation;
21 import android.health.connect.datatypes.BloodPressureRecord.BodyPosition.BodyPositionType;
22 import android.health.connect.datatypes.Identifier;
23 import android.health.connect.datatypes.RecordTypeIdentifier;
24 import android.health.connect.datatypes.units.Pressure;
25 import android.os.Parcel;
26 
27 /**
28  * @hide
29  * @see BloodPressureRecord
30  */
31 @Identifier(recordIdentifier = RecordTypeIdentifier.RECORD_TYPE_BLOOD_PRESSURE)
32 public final class BloodPressureRecordInternal extends InstantRecordInternal<BloodPressureRecord> {
33     private int mMeasurementLocation;
34     private double mSystolic;
35     private double mDiastolic;
36     private int mBodyPosition;
37 
38     @BloodPressureMeasurementLocation.BloodPressureMeasurementLocations
getMeasurementLocation()39     public int getMeasurementLocation() {
40         return mMeasurementLocation;
41     }
42 
43     /** returns this object with the specified measurementLocation */
44     @NonNull
setMeasurementLocation(int measurementLocation)45     public BloodPressureRecordInternal setMeasurementLocation(int measurementLocation) {
46         this.mMeasurementLocation = measurementLocation;
47         return this;
48     }
49 
getSystolic()50     public double getSystolic() {
51         return mSystolic;
52     }
53 
54     /** returns this object with the specified systolic */
55     @NonNull
setSystolic(double systolic)56     public BloodPressureRecordInternal setSystolic(double systolic) {
57         this.mSystolic = systolic;
58         return this;
59     }
60 
getDiastolic()61     public double getDiastolic() {
62         return mDiastolic;
63     }
64 
65     /** returns this object with the specified diastolic */
66     @NonNull
setDiastolic(double diastolic)67     public BloodPressureRecordInternal setDiastolic(double diastolic) {
68         this.mDiastolic = diastolic;
69         return this;
70     }
71 
72     @BodyPositionType
getBodyPosition()73     public int getBodyPosition() {
74         return mBodyPosition;
75     }
76 
77     /** returns this object with the specified bodyPosition */
78     @NonNull
setBodyPosition(int bodyPosition)79     public BloodPressureRecordInternal setBodyPosition(int bodyPosition) {
80         this.mBodyPosition = bodyPosition;
81         return this;
82     }
83 
84     @NonNull
85     @Override
toExternalRecord()86     public BloodPressureRecord toExternalRecord() {
87         return new BloodPressureRecord.Builder(
88                         buildMetaData(),
89                         getTime(),
90                         getMeasurementLocation(),
91                         Pressure.fromMillimetersOfMercury(getSystolic()),
92                         Pressure.fromMillimetersOfMercury(getDiastolic()),
93                         getBodyPosition())
94                 .setZoneOffset(getZoneOffset())
95                 .buildWithoutValidation();
96     }
97 
98     @Override
populateInstantRecordFrom(@onNull Parcel parcel)99     void populateInstantRecordFrom(@NonNull Parcel parcel) {
100         mMeasurementLocation = parcel.readInt();
101         mSystolic = parcel.readDouble();
102         mDiastolic = parcel.readDouble();
103         mBodyPosition = parcel.readInt();
104     }
105 
106     @Override
populateInstantRecordTo(@onNull Parcel parcel)107     void populateInstantRecordTo(@NonNull Parcel parcel) {
108         parcel.writeInt(mMeasurementLocation);
109         parcel.writeDouble(mSystolic);
110         parcel.writeDouble(mDiastolic);
111         parcel.writeInt(mBodyPosition);
112     }
113 }
114