package Ġcom . d imed ical . controller Ċ Ċ import Ġcom . d imed ical . constant . API Constant Ċ import Ġcom . d imed ical . controller . request . Request Ċ import Ġcom . d imed ical . controller . response . Response Ċ import Ġcom . d imed ical . dto . Patient DTO Ċ import Ġcom . d imed ical . service . Patient Service Ċ import Ġcom . d imed ical . util . extension . DTO To Entity Extension . to Entity Ċ import Ġorg . slf 4 j . LoggerFactory Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . web . bind . annotation . Delete Mapping Ċ import Ġorg . springframework . web . bind . annotation . GetMapping Ċ import Ġorg . springframework . web . bind . annotation . Patch Mapping Ċ 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 . RequestMapping Ċ import Ġorg . springframework . web . bind . annotation . RestController Ċ import Ġjava . net . URI Ċ import Ġjava . net . URL Encoder Ċ import Ġjavax . validation . Valid Ċ Ċ @ RestController Ċ @ RequestMapping ( value Ġ= Ġ[ API Constant . BASE _ API ]) Ċ class ĠPatient Controller ( private Ġval Ġpatient Service : ĠPatient Service ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġlog Ġ= ĠLoggerFactory . getLogger ( java Class ) ĊĊĠĠĠ Ġ@ PostMapping ( API Constant . POST _ PAT IENT ) ĊĠĠĠ Ġfun Ġnew Patient (@ Valid Ġ@ RequestBody Ġpatient Request : ĠRequest < Patient DTO >): ĊĠĠĠĠĠĠĠ ĠResponseEntity < Response < Patient DTO >> Ġ{ ĊĠĠĠĠĠĠĠ Ġlog . info (" POST Ġ${ API Constant . POST _ PAT IENT } Ġfor Ġnew ĠPatient Ġname : Ġ{}", Ġpatient Request . request . name ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġpatient Service . add Patient ( patient Request . request . to Entity ()) ĊĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. created ( URI . create ( URL Encoder . encode ( API Constant . BASE _ API Ġ+ ĠAPI Constant . GET _ DO CTOR , Ġ" UTF - 8 "))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Response ( data Ġ= Ġresponse )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ GetMapping ( API Constant . GET _ PAT IENT ) ĊĠĠĠ Ġfun Ġfind Patient (@ PathVariable (" id ") Ġpatient ID : ĠLong ): ĠResponseEntity < Response < Patient DTO >> Ġ{ ĊĠĠĠĠĠĠĠ Ġlog . info (" GET Ġ${ API Constant . GET _ PAT IENT } Ġfor ĠID Ġ{}", Ġpatient ID ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġpatient Service . find Patient ( patient ID ) ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity . ok ( Response ( data Ġ= Ġresponse )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Patch Mapping ( API Constant . PATCH _ PAT IENT ) ĊĠĠĠ Ġfun Ġupdate Patient (@ PathVariable (" id ") Ġpatient ID : ĠLong , Ġ@ Valid Ġ@ RequestBody Ġpatient Request : ĠRequest < Patient DTO >): ĊĠĠĠĠĠĠĠ ĠResponseEntity < Response < Patient DTO >> Ġ{ ĊĠĠĠĠĠĠĠ Ġlog . info (" PATCH Ġ${ API Constant . PATCH _ PAT IENT } Ġfor ĠID Ġ{}", Ġpatient Request . request . id ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġpatient Service . update Patient ( patient ID , Ġpatient Request . request . to Entity ()) ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity . ok ( Response ( data Ġ= Ġresponse )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Delete Mapping ( API Constant . DELETE _ PAT IENT ) ĊĠĠĠ Ġfun Ġdelete Patient (@ PathVariable (" id ") Ġpatient ID : ĠLong ): ĠResponseEntity < Response < Patient DTO >> Ġ{ ĊĠĠĠĠĠĠĠ Ġlog . info (" DELETE Ġ${ API Constant . DELETE _ PAT IENT } Ġfor ĠID Ġ{}", Ġpatient ID ) ĊĊĠĠĠĠĠĠĠ Ġpatient Service . delete Patient ( patient ID ) ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity . no Content (). build () ĊĠĠĠ Ġ} Ċ } Ċ