Skip to content

Commit

Permalink
Merge pull request #27 from Capstone-MediScan/develop
Browse files Browse the repository at this point in the history
feat: 알약 예측 API 임시 구현 (#26)
  • Loading branch information
sejineer authored May 30, 2024
2 parents 6e7a62e + 30b3d4a commit a00770a
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 279 deletions.
201 changes: 0 additions & 201 deletions LICENCE.md

This file was deleted.

1 change: 1 addition & 0 deletions core/core-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ dependencies {
testImplementation(project(":tests:api-docs"))

implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.apache.commons:commons-csv:1.11.0")
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
package org.mediscan.core.api.controller

import org.mediscan.core.api.controller.v1.request.PillIdentificationRequestDto
import org.mediscan.core.api.controller.v1.response.PillDetailResponseDto
import org.mediscan.core.api.controller.v1.response.PillIdentificationResponseDto
import org.mediscan.core.api.controller.v1.response.PillSearchResponseDto
import org.mediscan.core.api.domain.PillIdentificationData
import org.mediscan.core.api.domain.PillService
import org.mediscan.core.api.support.response.ApiResponse
import org.mediscan.core.enums.Color
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile

@RestController
class PillIController(
private var pillService: PillService,
) {
@PostMapping("/pill")
fun identifyPill(@RequestBody request: PillIdentificationRequestDto): ApiResponse<List<PillIdentificationResponseDto>> {
fun identifyPill(
@RequestPart frontImage: MultipartFile,
@RequestPart backImage: MultipartFile,
@RequestPart pillShape: String,
@RequestPart(required = false) frontMarking: String?,
@RequestPart(required = false) backMarking: String?,
): ApiResponse<List<PillIdentificationResponseDto>> {
val results = pillService.identifyPill(
request.frontImage,
request.backImage,
request.pillShape,
request.frontMarking,
request.backMarking,
PillIdentificationData(
frontImage,
backImage,
pillShape,
frontMarking,
backMarking,
),
)

val responseDtos = results.map { result ->
PillIdentificationResponseDto(
drugCode = result.drugCode,
confidence = result.confidence,
)
}

return ApiResponse.success(responseDtos)
return ApiResponse.success(results)
}

@GetMapping("/pill/search")
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.mediscan.core.api.controller.v1.response

data class PillIdentificationResponseDto(
// val pillName: String,
// val usage: String,
// val confidence: Long,
// val imagePath: String
val pillId: String,
val pillName: String?,
val itemImage: String?,
val className: String?,
val confidence: Long,
val drugCode: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.mediscan.core.api.domain

import org.springframework.web.multipart.MultipartFile

data class PillIdentificationData(
val frontImage: MultipartFile,
val backImage: MultipartFile,
val pillShape: String,
val frontMarking: String? = "None",
val backMarking: String? = "None",
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mediscan.client.example
package org.mediscan.core.api.domain

import org.mediscan.client.example.AiServiceClient
import org.mediscan.client.example.model.PillIdentificationRequestDto
import org.mediscan.client.example.model.PillIdentificationResponseDto
import org.springframework.stereotype.Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package org.mediscan.core.api.domain

import org.mediscan.client.example.PillIdentificationService
import org.mediscan.core.api.controller.v1.request.PillDomainIdentificationRequestDto
import org.mediscan.core.api.controller.v1.response.PillDomainIdentificationResponseDto
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVPrinter
import org.apache.commons.io.output.ByteArrayOutputStream
import org.springframework.stereotype.Component
import java.io.OutputStreamWriter

@Component
class PillManager(
private val pillIdentificationService: PillIdentificationService,
) {
fun identifyPill(request: PillDomainIdentificationRequestDto): List<PillDomainIdentificationResponseDto> {
val results = pillIdentificationService.identifyPill(
request.frontImage,
request.backImage,
request.pillShape,
request.frontMarking,
request.backMarking,
class PillManager {
fun createCsvInMemory(pillShape: String, pillFrontMarking: String?, pillBackMarking: String?): ByteArray {
val outputStream = ByteArrayOutputStream()
val writer = OutputStreamWriter(outputStream)
val csvPrinter =
CSVPrinter(writer, CSVFormat.DEFAULT.builder().setHeader("shape", "f_text", "b_text", "drug_code").build())

csvPrinter.printRecord(
pillShape,
pillFrontMarking.let { it ?: "none" },
pillBackMarking.let { it ?: "none" },
"none",
)
csvPrinter.flush()
csvPrinter.close()

return results.map { responseDto ->
PillDomainIdentificationResponseDto(
drugCode = responseDto.drugCode,
confidence = responseDto.confidence,
)
}
return outputStream.toByteArray()
}
}
Loading

0 comments on commit a00770a

Please sign in to comment.