feat (resume): add verify and validate, base value structure
This commit is contained in:
@@ -82,3 +82,10 @@ type Encounter struct {
|
||||
func (d Encounter) IsDone() bool {
|
||||
return d.Status_Code == erc.DSCDone
|
||||
}
|
||||
|
||||
func (d Encounter) IsSameResponsibleDoctor(input *string) bool {
|
||||
if input == nil {
|
||||
return false
|
||||
}
|
||||
return d.Responsible_Doctor_Code == input
|
||||
}
|
||||
|
||||
@@ -2,11 +2,19 @@ package resume
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
"time"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Value *string `json:"value"`
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Value *string `json:"value"`
|
||||
Status_Code erc.DataVerifiedCode `json:"status_code"`
|
||||
|
||||
pa.AuthInfo
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -16,7 +24,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Encounter_Id *uint `json:"encounter-id"`
|
||||
Encounter_Id *uint `json:"encounter-id"`
|
||||
Doctor_Code *string `json:"doctor-code"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
@@ -30,6 +39,8 @@ type UpdateDto struct {
|
||||
|
||||
type DeleteDto struct {
|
||||
Id uint `json:"id"`
|
||||
|
||||
pa.AuthInfo
|
||||
}
|
||||
|
||||
type MetaDto struct {
|
||||
@@ -40,16 +51,20 @@ type MetaDto struct {
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.Main
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Value *string `json:"value"`
|
||||
FileUrl *string `json:"fileUrl"`
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Value *string `json:"value"`
|
||||
FileUrl *string `json:"fileUrl"`
|
||||
Status_Code erc.DataVerifiedCode `json:"status_code"`
|
||||
}
|
||||
|
||||
func (d Resume) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Encounter_Id: d.Encounter_Id,
|
||||
Doctor_Code: d.Doctor_Code,
|
||||
Value: d.Value,
|
||||
FileUrl: d.FileUrl,
|
||||
Status_Code: d.Status_Code,
|
||||
}
|
||||
resp.Main = d.Main
|
||||
return resp
|
||||
@@ -62,3 +77,95 @@ func ToResponseList(data []Resume) []ResponseDto {
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
// ValueDto is for resume value
|
||||
type ValueDto struct {
|
||||
Assessment Assessment `json:"assessment"`
|
||||
Diagnosis Diagnosis `json:"diagnosis"`
|
||||
Action Action `json:"action"`
|
||||
Consultation Consultation `json:"consultation"`
|
||||
Supporting SupportingExaminations `json:"supporting"`
|
||||
Pharmacy PharmacyData `json:"pharmacy"`
|
||||
Discharge DischargeCondition `json:"discharge"`
|
||||
National NationalProgram `json:"national"`
|
||||
Management Management `json:"management"`
|
||||
}
|
||||
|
||||
type Assessment struct {
|
||||
StartedAt *time.Time `json:"startedAt`
|
||||
FinishedAt *time.Time `json:"finishedAt`
|
||||
Doctor_Code string `json:"doctor_code`
|
||||
DiagnosisIn string `json:"diagnosesIn`
|
||||
AmbulatoryIndication string `json:"ambulatoryIndication"`
|
||||
MainComplaint string `json:"mainComplaint"`
|
||||
PhysicalExamination string `json:"physicalExamination"`
|
||||
MedicalHistory string `json:"medicalHistory"`
|
||||
MedicalDiagnosis string `json:"medicalDiagnosis"`
|
||||
}
|
||||
|
||||
type Diagnosis struct {
|
||||
PrimaryDiagnosis DiagnosisEntry `json:"primaryDiagnosis"`
|
||||
SecondaryDiagnoses []DiagnosisEntry `json:"secondaryDiagnoses"`
|
||||
}
|
||||
|
||||
type DiagnosisEntry struct {
|
||||
Diagnosis string `json:"diagnosis"`
|
||||
ICD10 string `json:"icd_10"`
|
||||
Basis string `json:"basis"` // Clinical basis of diagnosis / dasar diagnosa
|
||||
}
|
||||
|
||||
type Action struct {
|
||||
PrimaryAction ActionEntry `json:"primaryAction"`
|
||||
AdditionalActions []ActionEntry `json:"additionalActions"`
|
||||
MedicalActions string `json:"medicalActions"` // free-text: "Tindakan Medis"
|
||||
}
|
||||
|
||||
type ActionEntry struct {
|
||||
Action string `json:"action"` // Tindakan
|
||||
ICD9 string `json:"icd_9"` // ICD-9
|
||||
Basis string `json:"basis"` // Dasar Tindakan
|
||||
}
|
||||
|
||||
type Consultation struct {
|
||||
Consultations []ConsultationEntry `json:"consultations"`
|
||||
}
|
||||
|
||||
type ConsultationEntry struct {
|
||||
Consultation string `json:"consultation"` // Konsultasi
|
||||
ConsultationAnswer string `json:"consultationAnswer"` // Jawaban Konsultasi
|
||||
}
|
||||
|
||||
type SupportingExaminations struct {
|
||||
Notes string `json:"notes"` // Free-text list of lab/imaging results
|
||||
}
|
||||
|
||||
type PharmacyData struct {
|
||||
AllergySpecialConditions string `json:"allergySpecialConditions"` // Kelainan Khusus Alergi
|
||||
OtherConditions string `json:"otherConditions"` // Kelainan Lain
|
||||
TherapyDuringCare string `json:"therapyDuringCare"` // Terapi selama dirawat
|
||||
TherapyAtDischarge string `json:"therapyAtDischarge"` // Terapi waktu pulang
|
||||
FollowUpInstructions string `json:"followUpInstructions"` // Edukasi / Anjuran / Follow-up
|
||||
}
|
||||
|
||||
type DischargeCondition struct {
|
||||
BloodPressureSystolic float64 `json:"bloodPressureSystolic"` // Tekanan Darah Sistol (mmHg)
|
||||
BloodPressureDiastolic float64 `json:"bloodPressureDiastolic"` // Tekanan Darah Diastol (mmHg)
|
||||
RespirationRate float64 `json:"respirationRate"` // Pernafasan (kali/menit)
|
||||
HeartRate float64 `json:"heartRate"` // Denyut Jantung (kali/menit)
|
||||
BodyTemperature float64 `json:"bodyTemperature"` // Suhu Tubuh (°C)
|
||||
|
||||
ConsciousnessLevel string `json:"consciousnessLevel"` // Tingkat Kesadaran
|
||||
PainScale int `json:"painScale"` // Skala Nyeri (0–10)
|
||||
}
|
||||
|
||||
type NationalProgram struct {
|
||||
ProgramService string `json:"programService"` // e.g. "Antenatal Care"
|
||||
ProgramServiceStatus string `json:"programServiceStatus"` // e.g. "Suspected"
|
||||
}
|
||||
|
||||
type Management struct {
|
||||
NationalProgramService string `json:"nationalProgramService"` // e.g. selected program
|
||||
FollowUpManagement string `json:"followUpManagement"` // e.g. further management plan
|
||||
ConditionOnDischarge string `json:"conditionOnDischarge"` // e.g. "Stable"
|
||||
DischargeMethod string `json:"dischargeMethod"` // e.g. "Discharged with Doctor's Approval"
|
||||
}
|
||||
|
||||
@@ -16,3 +16,15 @@ type Resume struct {
|
||||
FileUrl *string `json:"fileUrl" gorm:"size:1024"`
|
||||
Status_Code erc.DataVerifiedCode `json:"status_code" gorm:"not null;size:10"`
|
||||
}
|
||||
|
||||
func (d Resume) IsNew() bool {
|
||||
return d.Status_Code == erc.DVCNew
|
||||
}
|
||||
|
||||
func (d Resume) IsVerified() bool {
|
||||
return d.Status_Code == erc.DVCVerified
|
||||
}
|
||||
|
||||
func (d Resume) IsValidated() bool {
|
||||
return d.Status_Code == erc.DVCValidated
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
prescription "simrs-vx/internal/interface/main-handler/prescription"
|
||||
prescriptionitem "simrs-vx/internal/interface/main-handler/prescription-item"
|
||||
responsibledoctorhist "simrs-vx/internal/interface/main-handler/responsible-doctor-hist"
|
||||
resume "simrs-vx/internal/interface/main-handler/resume"
|
||||
sbar "simrs-vx/internal/interface/main-handler/sbar"
|
||||
soapi "simrs-vx/internal/interface/main-handler/soapi"
|
||||
uploadfile "simrs-vx/internal/interface/main-handler/upload-file"
|
||||
@@ -288,6 +289,15 @@ func SetRoutes() http.Handler {
|
||||
hc.RegCrud(r, "/v1/encounter-document", encounterdocument.O)
|
||||
hc.RegCrud(r, "/v1/general-consent", generalconsent.O)
|
||||
r.HandleFunc("POST /v1/generate-file", generatefile.Generate)
|
||||
hk.GroupRoutes("/v1/resume", r, auth.GuardMW, hk.MapHandlerFunc{
|
||||
"POST /": resume.Create,
|
||||
"GET /": resume.GetList,
|
||||
"GET /{id}": resume.GetDetail,
|
||||
"PATCH /{id}": resume.Update,
|
||||
"DELETE /{id}": resume.Delete,
|
||||
"PATCH /{id}/verify": resume.Verify,
|
||||
"PATCH /{id}/validate": resume.Validate,
|
||||
})
|
||||
|
||||
/******************** actor ********************/
|
||||
hc.RegCrud(r, "/v1/person", person.O)
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package resume
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
rw "github.com/karincake/risoles"
|
||||
sf "github.com/karincake/semprit"
|
||||
|
||||
// ua "github.com/karincake/tumpeng/auth/svc"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/resume"
|
||||
u "simrs-vx/internal/use-case/main-use-case/resume"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
)
|
||||
|
||||
func Create(w http.ResponseWriter, r *http.Request) {
|
||||
authInfo, err := pa.GetAuthInfo(r)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
|
||||
}
|
||||
dto := e.CreateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
dto.AuthInfo = *authInfo
|
||||
res, err := u.Create(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func GetList(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ReadListDto{}
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
res, err := u.ReadList(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func GetDetail(w http.ResponseWriter, r *http.Request) {
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
dto := e.ReadDetailDto{}
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
dto.Id = uint(id)
|
||||
res, err := u.ReadDetail(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func Update(w http.ResponseWriter, r *http.Request) {
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.UpdateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
dto.Id = uint(id)
|
||||
res, err := u.Update(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func Delete(w http.ResponseWriter, r *http.Request) {
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.DeleteDto{}
|
||||
dto.Id = uint(id)
|
||||
res, err := u.Delete(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func Verify(w http.ResponseWriter, r *http.Request) {
|
||||
authInfo, err := pa.GetAuthInfo(r)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
|
||||
}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.UpdateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
dto.Id = uint(id)
|
||||
dto.Status_Code = erc.DVCVerified
|
||||
dto.AuthInfo = *authInfo
|
||||
res, err := u.UpdateStatusCode(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func Validate(w http.ResponseWriter, r *http.Request) {
|
||||
authInfo, err := pa.GetAuthInfo(r)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
|
||||
}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.UpdateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
dto.Id = uint(id)
|
||||
dto.Status_Code = erc.DVCValidated
|
||||
dto.AuthInfo = *authInfo
|
||||
res, err := u.UpdateStatusCode(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
|
||||
// main entities
|
||||
ee "simrs-vx/internal/domain/main-entities/encounter"
|
||||
e "simrs-vx/internal/domain/main-entities/resume"
|
||||
|
||||
ue "simrs-vx/internal/use-case/main-use-case/encounter"
|
||||
@@ -31,6 +34,10 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
pl.SetLogInfo(&event, input, "started", "create")
|
||||
|
||||
err := dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
if !input.AuthInfo.IsDoctor() {
|
||||
return errors.New("user is not a doctor")
|
||||
}
|
||||
|
||||
mwRunner := newMiddlewareRunner(&event, tx)
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
@@ -43,6 +50,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
return errors.New("encounter is already done")
|
||||
}
|
||||
|
||||
input.Status_Code = erc.DVCNew
|
||||
if resData, err := CreateData(input, &event, tx); err != nil {
|
||||
return err
|
||||
} else {
|
||||
@@ -188,6 +196,10 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
pl.SetLogInfo(&event, input, "started", "update")
|
||||
|
||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
if !input.AuthInfo.IsDoctor() {
|
||||
return errors.New("user is not a doctor")
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail")
|
||||
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
|
||||
return err
|
||||
@@ -254,6 +266,10 @@ func Delete(input e.DeleteDto) (*d.Data, error) {
|
||||
pl.SetLogInfo(&event, input, "started", "delete")
|
||||
|
||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
if !input.AuthInfo.IsDoctor() {
|
||||
return errors.New("user is not a doctor")
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail")
|
||||
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
|
||||
return err
|
||||
@@ -293,3 +309,84 @@ func Delete(input e.DeleteDto) (*d.Data, error) {
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func UpdateStatusCode(input e.UpdateDto) (*d.Data, error) {
|
||||
rdDto := e.ReadDetailDto{Id: input.Id}
|
||||
var data *e.Resume
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "UpdateStatusCode",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "updateStatusCode")
|
||||
|
||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
if !input.AuthInfo.IsDoctor() {
|
||||
return errors.New("user is not a doctor")
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail")
|
||||
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
enc, err := ue.ReadDetailData(ee.ReadDetailDto{Id: uint16(*data.Encounter_Id)}, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// check if encounter is done
|
||||
if enc.IsDone() {
|
||||
return errors.New("encounter is already done")
|
||||
}
|
||||
|
||||
switch input.Status_Code {
|
||||
case erc.DVCValidated:
|
||||
if !enc.IsSameResponsibleDoctor(input.AuthInfo.Doctor_Code) {
|
||||
return errors.New("validation doctor is not the same as encounter responsible doctor")
|
||||
}
|
||||
|
||||
if data.IsNew() {
|
||||
return errors.New("resume need to be verified first")
|
||||
}
|
||||
if data.IsValidated() {
|
||||
return errors.New("resume already validated")
|
||||
}
|
||||
data.Status_Code = erc.DVCValidated
|
||||
err = tx.Save(&data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case erc.DVCVerified:
|
||||
if data.IsValidated() {
|
||||
return errors.New("resume already validated")
|
||||
}
|
||||
if data.IsVerified() {
|
||||
return errors.New("resume already verified")
|
||||
}
|
||||
data.Status_Code = erc.DVCVerified
|
||||
err = tx.Save(&data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "updated",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -18,5 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Resume) {
|
||||
}
|
||||
|
||||
data.Encounter_Id = inputSrc.Encounter_Id
|
||||
data.Doctor_Code = inputSrc.AuthInfo.Doctor_Code
|
||||
data.Value = inputSrc.Value
|
||||
data.Status_Code = inputSrc.Status_Code
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user