Skip to content

Commit

Permalink
#91 인공지능 모델 완성
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Jun 8, 2023
1 parent 7a89aaa commit 188d57f
Show file tree
Hide file tree
Showing 37 changed files with 636 additions and 205 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/android/mediproject/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa
internetNetworkListener.activityLifeCycle = this.lifecycle
internetNetworkListener.networkStateCallback = InternetNetworkListener.NetworkStateCallback { isConnected ->
if (!isConnected) {
val modalBottomSheet = NetworkStateDialogFragment()
modalBottomSheet.show(supportFragmentManager, NetworkStateDialogFragment::class.java.name)
//val modalBottomSheet = NetworkStateDialogFragment()
//modalBottomSheet.show(supportFragmentManager, NetworkStateDialogFragment::class.java.name)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.mediproject.core.common.bindingadapter

import android.content.res.ColorStateList
import android.graphics.Bitmap
import android.text.Spanned
import android.view.View
Expand Down Expand Up @@ -29,6 +30,11 @@ object BindingAdapter {
@BindingAdapter("img")
@JvmStatic
fun loadImage(imageView: ImageView, img: String) {
if (img.isEmpty()) {
imageView.setBackgroundResource(R.drawable.baseline_hide_image_24)
imageView.imageTintList = ColorStateList.valueOf(android.graphics.Color.BLUE)
return
}
GlideApp.with(imageView.context).load(img).centerInside().skipMemoryCache(false).into(imageView)
}

Expand Down
6 changes: 6 additions & 0 deletions core/common/src/main/res/drawable/baseline_hide_image_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M21,5c0,-1.1 -0.9,-2 -2,-2H5.83L21,18.17V5z"/>
<path android:fillColor="@android:color/white" android:pathData="M2.81,2.81L1.39,4.22L3,5.83V19c0,1.1 0.9,2 2,2h13.17l1.61,1.61l1.41,-1.41L2.81,2.81zM6,17l3,-4l2.25,3l0.82,-1.1l2.1,2.1H6z"/>
</vector>
3 changes: 2 additions & 1 deletion core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ plugins {
android {
namespace = "com.android.mediproject.core.data"

buildFeatures {
@Suppress("UnstableApiUsage") buildFeatures {
buildConfig = true
}

}
hilt {
enableAggregatingTask = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ interface MedicineApprovalRepository {
): Flow<PagingData<Item>>

fun getMedicineDetailInfo(itemName: String): Flow<Result<MedicineDetailInfoResponse.Body.Item>>
fun getMedicineDetailInfoByItemSeq(itemSeqs: List<String>): Flow<Result<List<MedicineDetailInfoResponse.Body.Item>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import javax.inject.Inject
class MedicineApprovalRepositoryImpl @Inject constructor(
private val medicineApprovalDataSource: MedicineApprovalDataSource,
private val searchHistoryRepository: SearchHistoryRepository,
@Dispatcher(MediDispatchers.IO) private val ioDispatcher: CoroutineDispatcher) : MedicineApprovalRepository {
@Dispatcher(MediDispatchers.IO) private val ioDispatcher: CoroutineDispatcher
) : MedicineApprovalRepository {

/**
* PagingData를 사용하여 페이징 처리를 하기 위해 Pager를 사용
Expand Down Expand Up @@ -50,4 +51,15 @@ class MedicineApprovalRepositoryImpl @Inject constructor(
})
}

override fun getMedicineDetailInfoByItemSeq(itemSeqs: List<String>) =
medicineApprovalDataSource.getMedicineDetailInfoByItemSeq(itemSeqs).map { result ->
result.fold(onSuccess = { medicineDetailInfoResponses ->
Result.success(medicineDetailInfoResponses.map {
it.body.items.first()
})
}, onFailure = {
Result.failure(it)
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import javax.inject.Inject
class GetMedicineDetailsUseCase @Inject constructor(
private val medicineApprovalRepository: MedicineApprovalRepository,
private val medicineIdRepository: MedicineIdRepository,
private val signRepository: SignRepository) {
private val signRepository: SignRepository
) {

operator fun invoke(
medicineInfoArgs: MedicineInfoArgs): Flow<Result<MedicineDetatilInfoDto>> = channelFlow {
medicineInfoArgs: MedicineInfoArgs
): Flow<Result<MedicineDetatilInfoDto>> = channelFlow {
medicineApprovalRepository.getMedicineDetailInfo(
itemName = medicineInfoArgs.itemKorName,
).zip(medicineIdRepository.getMedicineId(GetMedicineIdParameter(entpName = medicineInfoArgs.entpKorName,
Expand Down Expand Up @@ -51,4 +53,19 @@ class GetMedicineDetailsUseCase @Inject constructor(
trySend(medicineInfo)
}
}


fun getMedicineDetailInfoByItemSeq(itemSeqs: List<String>): Flow<Result<List<MedicineDetatilInfoDto>>> = channelFlow {
medicineApprovalRepository.getMedicineDetailInfoByItemSeq(itemSeqs).collectLatest { medicineInfoResult ->
val medicineInfo = medicineInfoResult.fold(onSuccess = { item ->
Result.success(item.map {
it.toDto()
})
}, onFailure = {
Result.failure(it)
})

trySend(medicineInfo)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.android.mediproject.core.model.ai

/**
* 약 분류 결과
*
* @property medicineSeq 의약품 품목 기준 코드
* @property confidence 정확도
*/
data class ClassificationRecognition(val medicineSeq: String, val confidence: Float) {

override fun toString(): String {
return probabilityString
}

private val probabilityString = String.format("%.1f%%", confidence * 100.0f)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.android.mediproject.core.model.ai

import com.android.mediproject.core.model.medicine.medicinedetailinfo.MedicineDetatilInfoDto

data class ClassificationResult(
val detectionObject: DetectionObject, val classificationRecognition: ClassificationRecognition
) {
var medicineDetatilInfoDto: MedicineDetatilInfoDto? = null
var onClick: ((MedicineDetatilInfoDto) -> Unit)? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ data class MedicineDetatilInfoDto(
val hasMedicineIdInAws: Boolean
)

fun MedicineDetailInfoResponse.Body.Item.toDto(medicineIdInAws: Long) = MedicineDetatilInfoDto(
atcCode = atcCode,
fun MedicineDetailInfoResponse.Body.Item.toDto(medicineIdInAws: Long = 0L) = MedicineDetatilInfoDto(atcCode = atcCode,
barCode = barCode,
businessRegistrationNumber = businessRegistrationNumber,
cancelDate = cancelDate.toLocalDate(),
Expand Down Expand Up @@ -145,8 +144,7 @@ fun MedicineDetailInfoResponse.Body.Item.toDto(medicineIdInAws: Long) = Medicine
uDocUid = uDDOCID,
validTerm = validTerm,
medicineIdInAws = medicineIdInAws,
hasMedicineIdInAws = medicineIdInAws != 0L
)
hasMedicineIdInAws = medicineIdInAws != 0L)

private fun String?.toLocalDate(): LocalDate? = this?.let {
java.time.LocalDate.parse(it, dateTimeFormatter).toKotlinLocalDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ interface MedicineApprovalDataSource {
fun getMedicineDetailInfo(
itemName: String,
): Flow<Result<MedicineDetailInfoResponse>>

fun getMedicineDetailInfoByItemSeq(
itemSeqs: List<String>
): Flow<Result<List<MedicineDetailInfoResponse>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class MedicineApprovalDataSourceImpl @Inject constructor(

override suspend fun getMedicineApprovalList(
itemName: String?, entpName: String?, medicationType: String?, pageNo: Int
): Result<MedicineApprovalListResponse> = dataGoKrNetworkApi.getApprovalList(
itemName = itemName, entpName = entpName, pageNo = pageNo, medicationType = medicationType
).onResponse().fold(onSuccess = { response ->
response.isSuccess().let {
if (it == DataGoKrResult.isSuccess) Result.success(response)
else Result.failure(Throwable(it.failedMessage))
}
}, onFailure = {
Result.failure(it)
})
): Result<MedicineApprovalListResponse> =
dataGoKrNetworkApi.getApprovalList(itemName = itemName, entpName = entpName, pageNo = pageNo, medicationType = medicationType)
.onResponse().fold(onSuccess = { response ->
response.isSuccess().let {
if (it == DataGoKrResult.isSuccess) Result.success(response)
else Result.failure(Throwable(it.failedMessage))
}
}, onFailure = {
Result.failure(it)
})

override fun getMedicineDetailInfo(itemName: String): Flow<Result<MedicineDetailInfoResponse>> = channelFlow {
dataGoKrNetworkApi.getMedicineDetailInfo(itemName = itemName).onResponse().fold(onSuccess = { response ->
Expand All @@ -41,4 +41,25 @@ class MedicineApprovalDataSourceImpl @Inject constructor(
send(it)
}
}

override fun getMedicineDetailInfoByItemSeq(itemSeqs: List<String>) = channelFlow {
val responses = itemSeqs.map { itemSeq ->
dataGoKrNetworkApi.getMedicineDetailInfo(itemSeq = itemSeq).onResponse().fold(onSuccess = { response ->
response.isSuccess().let {
if (it is DataGoKrResult.isSuccess) Result.success(response)
else Result.failure(Throwable(it.failedMessage))
}
}, onFailure = {
Result.failure<MedicineDetailInfoResponse>(it)
})
}

val results = responses.let {
val failed = it.any { result -> result.isFailure }
if (failed) Result.failure(Throwable("약품 상세 정보 조회에 실패했습니다."))
else Result.success(it.map { result -> result.getOrNull()!! })
}

trySend(results)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import com.android.mediproject.core.common.BuildConfig
import com.android.mediproject.core.common.DATA_GO_KR_PAGE_SIZE
import com.android.mediproject.core.common.network.Dispatcher
import com.android.mediproject.core.common.network.MediDispatchers
import com.android.mediproject.core.model.medicine.medicineapproval.MedicineApprovalListResponse
import com.android.mediproject.core.model.medicine.medicinedetailinfo.MedicineDetailInfoResponse
import com.android.mediproject.core.model.remote.adminaction.AdminActionListResponse
import com.android.mediproject.core.model.remote.dur.DurResponse
import com.android.mediproject.core.model.remote.elderlycaution.ElderlyCautionResponse
import com.android.mediproject.core.model.remote.granule.GranuleIdentificationInfoResponse
import com.android.mediproject.core.model.medicine.medicineapproval.MedicineApprovalListResponse
import com.android.mediproject.core.model.medicine.medicinedetailinfo.MedicineDetailInfoResponse
import com.android.mediproject.core.model.remote.recall.DetailRecallSuspensionResponse
import com.android.mediproject.core.model.remote.recall.RecallSuspensionListResponse
import com.android.mediproject.core.network.datasource.dur.DurDataSource
Expand Down Expand Up @@ -48,9 +48,8 @@ object DataGoKrNetwork {
@Provides
@Singleton
fun providesDataGoKrNetworkApi(okHttpClient: OkHttpClient): DataGoKrNetworkApi =
Retrofit.Builder().client(okHttpClient).addConverterFactory(
Json.asConverterFactory("application/json".toMediaType())
).baseUrl(DATA_GO_KR_BASEURL).build().create(DataGoKrNetworkApi::class.java)
Retrofit.Builder().client(okHttpClient).addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.baseUrl(DATA_GO_KR_BASEURL).build().create(DataGoKrNetworkApi::class.java)


@Provides
Expand Down Expand Up @@ -105,7 +104,8 @@ interface DataGoKrNetworkApi {
@GET(value = "DrugPrdtPrmsnInfoService04/getDrugPrdtPrmsnDtlInq03")
suspend fun getMedicineDetailInfo(
@Query("serviceKey", encoded = true) serviceKey: String = BuildConfig.DATA_GO_KR_SERVICE_KEY,
@Query("item_name", encoded = true) itemName: String,
@Query("item_name", encoded = true) itemName: String = "",
@Query("item_seq", encoded = true) itemSeq: String = "",
@Query("pageNo") pageNo: Int = 1,
@Query("type") type: String = JSON,
@Query("numOfRows") numOfRows: Int = 100
Expand Down
6 changes: 6 additions & 0 deletions core/ui/src/main/res/drawable/baseline_hide_image_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M21,5c0,-1.1 -0.9,-2 -2,-2H5.83L21,18.17V5z"/>
<path android:fillColor="@android:color/white" android:pathData="M2.81,2.81L1.39,4.22L3,5.83V19c0,1.1 0.9,2 2,2h13.17l1.61,1.61l1.41,-1.41L2.81,2.81zM6,17l3,-4l2.25,3l0.82,-1.1l2.1,2.1H6z"/>
</vector>
2 changes: 1 addition & 1 deletion core/ui/src/main/res/values/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<string name="option_show_all_medicines">모두 보기</string>
<string name="option_show_only_generic_medicines">일반 의약품만 보기</string>
<string name="option_show_only_specialty_medicines">전문 의약품만 보기</string>
<string name="detectioned_medicine_counts">개의 의약품이\n검색되었습니다</string>
<string name="detectioned_medicine_counts">개의 의약품이 검색되었습니다</string>

</resources>
33 changes: 19 additions & 14 deletions feature/camera/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,30 @@ android {
androidResources {
noCompress += listOf("tflite")
}
/*

externalNativeBuild {
cmake {
version = "3.22.1"
path = file("src/main/jni/CMakeLists.txt")
@Suppress("UnstableApiUsage") buildFeatures {
buildConfig = true
mlModelBinding = true
}/*
externalNativeBuild {
cmake {
version = "3.22.1"
path = file("src/main/jni/CMakeLists.txt")
}
}
}
defaultConfig {
defaultConfig {
ndk {
version = "25.2.9519653"
abiFilters += listOf(
"armeabi-v7a", "arm64-v8a"
)
ndk {
version = "25.2.9519653"
abiFilters += listOf(
"armeabi-v7a", "arm64-v8a"
)
}
}
}
*/
*/

}

Expand All @@ -44,6 +48,7 @@ dependencies {
implementation(project(":core:common"))
implementation(project(":core:model"))
implementation(project(":core:domain"))
implementation(project(":feature:search"))
implementation(libs.bundles.glides)
kapt(libs.bundles.glides.kapt)
implementation(libs.bundles.kotlins)
Expand Down
Loading

0 comments on commit 188d57f

Please sign in to comment.