Skip to content

Commit

Permalink
Merge pull request #173 from Semoban/medicalCRUD
Browse files Browse the repository at this point in the history
feat: 진료기록 정보 화면 관련 기능 구현 완료, 진료기록 생성 화면 null 체크까지 진행중
  • Loading branch information
hxeyexn authored Apr 6, 2024
2 parents acf5d33 + 3e01f1c commit 380a2ff
Show file tree
Hide file tree
Showing 36 changed files with 1,613 additions and 214 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.project.meongcare

import android.net.Uri

interface OnPictureChangedListener {
fun onPictureChanged(uri: Uri)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.project.meongcare.login.view

import android.app.Application
import android.content.Context
import android.util.Log
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import com.kakao.sdk.common.KakaoSdk
import com.kakao.sdk.common.util.Utility
import com.navercorp.nid.NaverIdLoginSDK
import com.project.meongcare.BuildConfig
import dagger.hilt.android.HiltAndroidApp
Expand Down Expand Up @@ -33,6 +35,9 @@ class GlobalApplication : Application() {
override fun onCreate() {
super.onCreate()

// 키 해시 얻기
// getKeyHash()

// kakao sdk 초기화
KakaoSdk.init(this, "${BuildConfig.KAKAO_NATIVE_APP_KEY}")

Expand All @@ -44,4 +49,9 @@ class GlobalApplication : Application() {
"${BuildConfig.NAVER_OAUTH_CLIENT_NAME}",
)
}

private fun getKeyHash() {
var keyHash = Utility.getKeyHash(this)
Log.i("GlobalApplication", "$keyHash")
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.meongcare.medicalrecord.model.data.local
package com.project.meongcare.medicalRecord.model.data.local

interface MedicalRecordItemCheckListener {
fun onMedicalRecordItemChecked(medicalRecordIds: IntArray)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.meongcare.medicalrecord.model.data.local
package com.project.meongcare.medicalRecord.model.data.local

interface MedicalRecordItemClickListener {
fun onMedicalRecordItemClick(medicalRecordId: Long)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.project.meongcare.medicalRecord.model.data.local

import android.net.Uri

interface OnPictureChangedListener {
fun onPictureChanged(uri: Uri)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.project.meongcare.medicalrecord.model.data.remote
package com.project.meongcare.medicalRecord.model.data.remote

import com.project.meongcare.medicalrecord.model.entities.MedicalRecordGetResponse
import com.project.meongcare.medicalRecord.model.entities.MedicalRecordGet
import com.project.meongcare.medicalRecord.model.entities.MedicalRecordGetResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query

interface MedicalRecordApi {
Expand All @@ -15,9 +23,23 @@ interface MedicalRecordApi {
@Header("AccessToken") accessToken: String,
): Response<MedicalRecordGetResponse>

@GET("medical-record/{medicalRecordId}")
suspend fun getMedicalRecord(
@Path("medicalRecordId") medicalRecordId: Long,
@Header("AccessToken") accessToken: String,
): Response<MedicalRecordGet>

@DELETE("medical-record")
suspend fun deleteMedicalRecordList(
@Query("medicalRecordIds") medicalRecordIds: IntArray,
@Header("AccessToken") accessToken: String,
): Response<Int>

@Multipart
@POST("medical-record")
suspend fun addMedicalRecord(
@Header("AccessToken") accessToken: String?,
@Part filePart: MultipartBody.Part,
@Part("dto") medicalRecordDto: RequestBody,
): Response<ResponseBody>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.meongcare.medicalrecord.model.data.repository
package com.project.meongcare.medicalRecord.model.data.repository

import dagger.Module
import dagger.Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.project.meongcare.medicalrecord.model.data.repository
package com.project.meongcare.medicalRecord.model.data.repository

import com.project.meongcare.medicalrecord.model.entities.MedicalRecordGetResponse
import com.project.meongcare.medicalRecord.model.entities.MedicalRecordGet
import com.project.meongcare.medicalRecord.model.entities.MedicalRecordGetResponse
import com.project.meongcare.medicalRecord.model.entities.RequestMedicalRecord
import retrofit2.Response

interface MedicalRecordRepository {
Expand All @@ -10,8 +12,18 @@ interface MedicalRecordRepository {
accessToken: String,
): Response<MedicalRecordGetResponse>?

suspend fun getMedicalRecord(
medicalRecordId: Long,
accessToken: String,
): Response<MedicalRecordGet>?

suspend fun deleteMedicalRecordList(
medicalRecordIds: IntArray,
accessToken: String,
): Int?

suspend fun addMedicalRecord(
accessToken: String?,
requestSupplement: RequestMedicalRecord,
): Int
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.project.meongcare.medicalrecord.model.data.repository
package com.project.meongcare.medicalRecord.model.data.repository

import android.util.Log
import com.project.meongcare.medicalrecord.model.data.remote.MedicalRecordRetrofitClient
import com.project.meongcare.medicalrecord.model.entities.MedicalRecordGetResponse
import com.project.meongcare.medicalRecord.model.entities.MedicalRecordGet
import com.project.meongcare.medicalRecord.model.data.remote.MedicalRecordRetrofitClient
import com.project.meongcare.medicalRecord.model.entities.MedicalRecordGetResponse
import com.project.meongcare.medicalRecord.model.entities.RequestMedicalRecord
import org.json.JSONObject
import retrofit2.Response
import javax.inject.Inject
Expand Down Expand Up @@ -30,6 +32,25 @@ class MedicalRecordRepositoryImpl
}
}

override suspend fun getMedicalRecord(
medicalRecordId: Long,
accessToken: String,
): Response<MedicalRecordGet>? {
return try {
val response = medicalRecordRetrofitClient.medicalRecordApi.getMedicalRecord(medicalRecordId, accessToken)
if (response.isSuccessful) {
Log.d("MedicalRepo-Get", "통신 성공 : ${response.code()}")
response
} else {
Log.d("MedicalRepo-Get", "통신 실패 : ${response.code()}")
response
}
} catch (e: Exception) {
e.printStackTrace()
null
}
}

override suspend fun deleteMedicalRecordList(
medicalRecordIds: IntArray,
accessToken: String,
Expand All @@ -49,4 +70,17 @@ class MedicalRecordRepositoryImpl
null
}
}

override suspend fun addMedicalRecord(
accessToken: String?,
requestMedicalRecord: RequestMedicalRecord,
): Int {
val response =
medicalRecordRetrofitClient.medicalRecordApi.addMedicalRecord(
accessToken,
requestMedicalRecord.file,
requestMedicalRecord.dto,
)
return response.code()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.meongcare.medicalrecord.model.entities
package com.project.meongcare.medicalRecord.model.entities

data class MedicalRecord(
val medicalRecordId: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.project.meongcare.medicalRecord.model.entities

data class MedicalRecordDto(
val dogId: Long,
val dateTime: String,
val hospitalName: String,
val doctorName: String,
val note: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.project.meongcare.medicalRecord.model.entities

data class MedicalRecordGet(
val medicalRecordId: Long,
val dateTime: String,
val hospitalName: String,
val doctorName: String,
val note: String,
val imageUrl: String,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.meongcare.medicalrecord.model.entities
package com.project.meongcare.medicalRecord.model.entities

data class MedicalRecordGetResponse(
val records: MutableList<MedicalRecord>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.project.meongcare.medicalRecord.model.entities

import okhttp3.MultipartBody
import okhttp3.RequestBody

data class RequestMedicalRecord(
val dto: RequestBody,
val file: MultipartBody.Part,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.meongcare.medicalrecord.model.utils
package com.project.meongcare.medicalRecord.model.utils

object MedicalRecordDateUtils {
fun showFormattedTime(dateTime: String): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.project.meongcare.medicalRecord.model.utils

import android.content.Context
import android.net.Uri
import android.view.View
import android.view.inputmethod.InputMethodManager
import com.google.gson.Gson
import com.project.meongcare.medicalRecord.model.entities.MedicalRecordDto
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.File
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale

class MedicalRecordUtils {
companion object {
fun convertMDateToSimpleDate(localMili: String): String {
val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
val dateTime = LocalDateTime.parse(localMili, inputFormatter)

val outputFormatter = DateTimeFormatter.ofPattern("yyyy년 M월 d일", Locale.getDefault())
return dateTime.format(outputFormatter)
}

fun convertMDateToSimpleTime(localMili: String): String {
val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
val dateTime = LocalDateTime.parse(localMili, inputFormatter)

val outputFormatter = DateTimeFormatter.ofPattern("a hh:mm", Locale.getDefault())
return dateTime.format(outputFormatter)
}

fun convertMedicalRecordDto(medicalRecordDto: MedicalRecordDto): RequestBody {
val json = Gson().toJson(medicalRecordDto)
return json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
}

fun convertPictureToFile(
context: Context,
uri: Uri,
): MultipartBody.Part {
if (uri.toString().isEmpty()) {
val emptyFile = "".toRequestBody("multipart/form-data".toMediaTypeOrNull())
return MultipartBody.Part.createFormData("file", "", emptyFile)
}

val inputStream = context.contentResolver.openInputStream(uri)
val file = File(context.cacheDir, "tempFile")
inputStream.use { input ->
file.outputStream().use { output ->
input?.copyTo(output)
}
}
val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull())

return MultipartBody.Part.createFormData("file", file.name, requestFile)
}

fun hideKeyboard(view: View) {
val inputMethodManager =
view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}
}
}
Loading

0 comments on commit 380a2ff

Please sign in to comment.