Merge pull request #80 from dikstub-rssa/feat/patient-search-79

Feat/patient search 79
This commit is contained in:
Dwi Atmoko Purbo Sakti
2025-10-17 13:09:50 +07:00
committed by GitHub
18 changed files with 256 additions and 47 deletions
@@ -0,0 +1,54 @@
-- Create "AmbulanceTransportReq" table
CREATE TABLE "public"."AmbulanceTransportReq" (
"Id" bigserial NOT NULL,
"CreatedAt" timestamptz NULL,
"UpdatedAt" timestamptz NULL,
"DeletedAt" timestamptz NULL,
"Patient_Id" bigint NULL,
"Diagnoses" character varying(1024) NULL,
"RequestData" timestamptz NULL,
"UsageDate" timestamptz NULL,
"Address" character varying(100) NULL,
"RtRw" character varying(10) NULL,
"Province_Code" character varying(2) NULL,
"Regency_Code" character varying(4) NULL,
"District_Code" character varying(6) NULL,
"Village_Code" character varying(10) NULL,
"Facility_Code" character varying(10) NULL,
"Needs_Code" character varying(10) NULL,
"Contact_Name" character varying(100) NULL,
"Contact_Relationship_Code" character varying(10) NULL,
"Contact_PhoneNumber" character varying(20) NULL,
PRIMARY KEY ("Id"),
CONSTRAINT "fk_AmbulanceTransportReq_District" FOREIGN KEY ("District_Code") REFERENCES "public"."District" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "fk_AmbulanceTransportReq_Patient" FOREIGN KEY ("Patient_Id") REFERENCES "public"."Patient" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "fk_AmbulanceTransportReq_Province" FOREIGN KEY ("Province_Code") REFERENCES "public"."Province" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "fk_AmbulanceTransportReq_Regency" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "fk_AmbulanceTransportReq_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "Vehicle" table
CREATE TABLE "public"."Vehicle" (
"Id" bigserial NOT NULL,
"CreatedAt" timestamptz NULL,
"UpdatedAt" timestamptz NULL,
"DeletedAt" timestamptz NULL,
"Type_Code" text NULL,
"PoliceNumber" text NULL,
"FrameNumber" text NULL,
"RegNumber" text NULL,
"AvailableStatus" boolean NULL,
PRIMARY KEY ("Id")
);
-- Create "VehicleHist" table
CREATE TABLE "public"."VehicleHist" (
"Id" bigserial NOT NULL,
"CreatedAt" timestamptz NULL,
"UpdatedAt" timestamptz NULL,
"DeletedAt" timestamptz NULL,
"Vehicle_Id" bigint NULL,
"Date" timestamptz NULL,
"Data" text NULL,
"Crud_Code" text NULL,
PRIMARY KEY ("Id"),
CONSTRAINT "fk_VehicleHist_Vehicle" FOREIGN KEY ("Vehicle_Id") REFERENCES "public"."Vehicle" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
@@ -0,0 +1,2 @@
-- Modify "MedicalActionSrc" table
ALTER TABLE "public"."MedicalActionSrc" ADD COLUMN "Type_Code" character varying(20) NULL;
+5 -3
View File
@@ -1,4 +1,4 @@
h1:qfP77w9XYWpAFDON1lo+vpqIYCSiPkVEyHXcYFC52Hk=
h1:sU0SrZhFKtCYoF46RbBCtQHOoDtvLJtLcIfBvmeawkg=
20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k=
20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0=
20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI=
@@ -44,5 +44,7 @@ h1:qfP77w9XYWpAFDON1lo+vpqIYCSiPkVEyHXcYFC52Hk=
20251014063537.sql h1:VZLXol0PTsTW21Epg6vBPsztWkDtcxup9F/z88EGgIg=
20251014063720.sql h1:2HVUyCV0ud3BJJDH2GEKZN/+IWLFPCsN1KqhP6csO14=
20251015045455.sql h1:MeLWmMhAOAz8b15Dd7IAQnt6JxjSml02XCXK22C0Lpg=
20251016010845.sql h1:MSUh26glEDyZ5BFiteYOm9mUCWw7aG9vv5TxYY+EidU=
20251016011023.sql h1:8oUBzIpzAYTo03yex+wLKacv32YjXmn4MsXtBFiQtzY=
20251016010845.sql h1:4BncQdDOasRZJkzVJrSJJA7091A9VPNVx/faUCUPhBM=
20251016011023.sql h1:9JB9eFZKURK5RoCVDKR6glSvdJ8NTXrN7K/4q51zkz4=
20251016062912.sql h1:ACNn0fe+EMqUt3hoY+Dr3uqAV/QICBa1+mIW7fUc9Fk=
20251017060617.sql h1:KzIbA9fYORIK9aGWMMf0te5/8oThYFCCCSQVktGO0K0=
@@ -0,0 +1,45 @@
package ambulance_transport_req
import (
ecore "simrs-vx/internal/domain/base-entities/core"
eds "simrs-vx/internal/domain/main-entities/district"
ept "simrs-vx/internal/domain/main-entities/patient"
epr "simrs-vx/internal/domain/main-entities/province"
erg "simrs-vx/internal/domain/main-entities/regency"
evl "simrs-vx/internal/domain/main-entities/village"
"time"
eren "simrs-vx/internal/domain/references/encounter"
erp "simrs-vx/internal/domain/references/person"
)
type AmbulanceTransportReq struct {
ecore.Main
Patient_Id *uint `json:"patient_id"`
Patient *ept.Patient `json:"patient,omitempty" gorm:"foreignKey:Patient_Id;references:Id"`
Diagnoses *string `json:"diagnoses" gorm:"size:1024"`
RequestData *time.Time `json:"requestData"`
UsageDate *time.Time `json:"usageDate"`
Address *string `json:"address" gorm:"size:100"`
RtRw *string `json:"rtRw" gorm:"size:10"`
Province_Code *string `json:"province_code" gorm:"size:2"`
Province *epr.Province `json:"province,omitempty" gorm:"foreignKey:Province_Code;references:Code"`
Regency_Code *string `json:"regency_code" gorm:"size:4"`
Regency *erg.Regency `json:"regency,omitempty" gorm:"foreignKey:Regency_Code;references:Code"`
District_Code *string `json:"district_code" gorm:"size:6"`
District *eds.District `json:"district,omitempty" gorm:"foreignKey:District_Code;references:Code"`
Village_Code *string `json:"village_code" gorm:"size:10"`
Village *evl.Village `json:"village,omitempty" gorm:"foreignKey:Village_Code;references:Code"`
Facility_Code *eren.AmbulanceFacilityCode `json:"facility_code" gorm:"size:10"`
Needs_Code *eren.AmbulanceNeedsCode `json:"needs_code" gorm:"size:10"`
Contact_Name *string `json:"contact_name" gorm:"size:100"`
Contact_Relationship_Code *erp.RelationshipCode `json:"contact_relationship_code" gorm:"size:10"`
Contact_PhoneNumber *string `json:"contact_phoneNumber" gorm:"size:20"`
}
@@ -6,9 +6,10 @@ import (
)
type CreateDto struct {
Code string `json:"code" validate:"maxLength=20"`
Name string `json:"name" validate:"maxLength=50"`
Item_Id *uint `json:"item_id"`
Code string `json:"code" validate:"maxLength=20"`
Name string `json:"name" validate:"maxLength=50"`
Type_Code string `json:"type_code" validate:"maxLength:20"`
Item_Id *uint `json:"item_id"`
}
type ReadListDto struct {
@@ -19,10 +20,11 @@ type ReadListDto struct {
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
Item_Id *uint `json:"item-id"`
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
Code string `json:"code"`
Name string `json:"name"`
Type_Code string `json:"type_code"`
Item_Id *uint `json:"item-id"`
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
}
type ReadDetailDto struct {
@@ -47,18 +49,20 @@ type MetaDto struct {
type ResponseDto struct {
ecore.Main
Code string `json:"code"`
Name string `json:"name"`
Item_Id *uint `json:"item_id"`
Item *ei.Item `json:"item,omitempty"`
Code string `json:"code"`
Name string `json:"name"`
Type_Code string `json:"type_code"`
Item_Id *uint `json:"item_id"`
Item *ei.Item `json:"item,omitempty"`
}
func (d MedicalActionSrc) ToResponse() ResponseDto {
resp := ResponseDto{
Code: d.Code,
Name: d.Name,
Item_Id: d.Item_Id,
Item: d.Item,
Code: d.Code,
Name: d.Name,
Type_Code: d.Type_Code,
Item_Id: d.Item_Id,
Item: d.Item,
}
resp.Main = d.Main
return resp
@@ -9,6 +9,7 @@ type MedicalActionSrc struct {
ecore.Main // adjust this according to the needs
Code string `json:"code" gorm:"unique;size:20"`
Name string `json:"name" gorm:"size:50"`
Type_Code string `json:"type_code" gorm:"size:20"`
Item_Id *uint `json:"item_id"`
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"`
}
+2 -1
View File
@@ -57,7 +57,8 @@ type DeleteDto struct {
}
type SearchDto struct {
Search string `json:"search"`
Search string `json:"search"`
Mode SearchMode `json:"mode"`
}
type UploadDto struct {
@@ -0,0 +1,8 @@
package patient
type SearchMode string
const (
SMNik SearchMode = "resident-identity"
SMIdent SearchMode = "identifier"
)
@@ -0,0 +1,17 @@
package vehicle_hist
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ev "simrs-vx/internal/domain/main-entities/vehicle"
erc "simrs-vx/internal/domain/references/common"
"time"
)
type VehicleHist struct {
ecore.Main // adjust this according to the needs
Vehicle_Id *uint `json:"vehicle_id"`
Vehicle *ev.Vehicle `json:"vehicle,omitempty" gorm:"foreignKey:Vehicle_Id;references:Id"`
Date *time.Time `json:"date"`
Data *string `json:"data"`
Crud_Code *erc.CrudCode `json:"crud_code"`
}
@@ -0,0 +1,15 @@
package vehicle
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ercl "simrs-vx/internal/domain/references/clinical"
)
type Vehicle struct {
ecore.Main // adjust this according to the needs
Type_Code *ercl.VehicleTypeCode `json:"type_code"`
PoliceNumber *string `json:"policeNumber"`
FrameNumber *string `json:"frameNumber"`
RegNumber *string `json:"regNumber"`
AvailableStatus bool `json:"availableStatus"`
}
@@ -10,6 +10,8 @@ type (
HeadToToeCode string
McuUrgencyLevelCode string
SoapiTypeCode string
MedicalAction string
VehicleTypeCode string
)
const (
@@ -101,6 +103,16 @@ const (
STCEarlyRehab SoapiTypeCode = "early-rehab" // Kajian Awal Rehab Medik
STCFunc SoapiTypeCode = "function" // Assessment Fungsi
STCProgress SoapiTypeCode = "progress" // CPPT
MAChemo MedicalAction = "chemo"
MAHemo MedicalAction = "hemo"
MAThalasemia MedicalAction = "thalasemia"
MAEchocardio MedicalAction = "echocardio"
MASpirometry MedicalAction = "spirometry"
VTCAmbulance VehicleTypeCode = "ambulance" // Ambulans
VTCTransport VehicleTypeCode = "transport" // Transport
VTCHearse VehicleTypeCode = "hearse" // Jenazah
)
type Soapi struct {
@@ -14,6 +14,7 @@ type (
PaymentMethodCode string
DataAvailabilityCode string
DataVerifiedCode string
CrudCode string
)
const (
@@ -91,6 +92,10 @@ const (
PMCInsurance PaymentMethodCode = "insurance" // Asuransi
PMCMembership PaymentMethodCode = "membership" // Member
CCCreate CrudCode = "c" // Create
CCRead CrudCode = "r" // Read
CCUpdate CrudCode = "u" // Update
CCDelete CrudCode = "d" // Delete
)
func GetDayCodes() map[DayCode]string {
@@ -1,18 +1,20 @@
package encounter
type (
EncounterClassCode string
QueueStatusCode string
DischargeMethodCode string
TransportationCode string
PersonConditionCode string
EmergencyClassCode string
OutpatientClassCode string
CheckupScopeCode string
AmbulatoryClassCode string
InpatientClassCode string
UploadCode string
ChemoClassCode string
EncounterClassCode string
QueueStatusCode string
DischargeMethodCode string
TransportationCode string
PersonConditionCode string
EmergencyClassCode string
OutpatientClassCode string
CheckupScopeCode string
AmbulatoryClassCode string
InpatientClassCode string
UploadCode string
ChemoClassCode string
AmbulanceFacilityCode string
AmbulanceNeedsCode string
)
const (
@@ -82,6 +84,12 @@ const (
CCCAdm ChemoClassCode = "adm" // Administrasi
CCCAct ChemoClassCode = "act" // Tindakan
AFCStd AmbulanceFacilityCode = "std" // Standar
AFCIcu AmbulanceFacilityCode = "icu" // ICU
ANCAssist AmbulanceNeedsCode = "assist" // Dengan Pendampingan
ANCNonassist AmbulanceNeedsCode = "non-assist" // Tanpa Pendampingan
)
func (ec EncounterClassCode) Code() string {
@@ -260,13 +260,14 @@ func SetRoutes() http.Handler {
"PATCH /{id}/active": user.O.Active,
})
hk.GroupRoutes("/v1/patient", r, hk.MapHandlerFunc{
"GET /": patient.O.GetList,
"GET /{id}": patient.O.GetDetail,
"POST /": patient.O.Create,
"PATCH /{id}": patient.O.Update,
"DELETE /{id}": patient.O.Delete,
"GET /by-identifier": patient.O.Search,
"POST /{id}/upload": patient.O.Upload,
"GET /": patient.O.GetList,
"GET /{id}": patient.O.GetDetail,
"POST /": patient.O.Create,
"PATCH /{id}": patient.O.Update,
"DELETE /{id}": patient.O.Delete,
"GET /search/{keyword}": patient.O.Search,
"GET /by-resident-identity": patient.O.SearchByResidentIdentity,
"POST /{id}/upload": patient.O.Upload,
})
/******************** sources ********************/
@@ -12,6 +12,8 @@ import (
u "simrs-vx/internal/use-case/main-use-case/patient"
ere "simrs-vx/internal/domain/references/encounter"
d "github.com/karincake/dodol"
)
type myBase struct{}
@@ -73,8 +75,21 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
}
func (obj myBase) Search(w http.ResponseWriter, r *http.Request) {
dto := e.SearchDto{}
keyword := rw.ValidateString(w, "keyword", r.PathValue("keyword"))
if keyword == "" {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "keyword is required"}, nil)
}
dto.Mode = e.SMIdent
dto.Search = keyword
res, err := u.Search(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) SearchByResidentIdentity(w http.ResponseWriter, r *http.Request) {
dto := e.SearchDto{}
sf.UrlQueryParam(&dto, *r.URL)
dto.Mode = e.SMNik
res, err := u.Search(dto)
rw.DataResponse(w, res, err)
}
@@ -2,6 +2,7 @@ package migration
import (
adime "simrs-vx/internal/domain/main-entities/adime"
ambulancetransportreq "simrs-vx/internal/domain/main-entities/ambulance-transport-req"
ambulatory "simrs-vx/internal/domain/main-entities/ambulatory"
appointment "simrs-vx/internal/domain/main-entities/appointment"
chemo "simrs-vx/internal/domain/main-entities/chemo"
@@ -75,6 +76,8 @@ import (
unit "simrs-vx/internal/domain/main-entities/unit"
uom "simrs-vx/internal/domain/main-entities/uom"
user "simrs-vx/internal/domain/main-entities/user"
vehicle "simrs-vx/internal/domain/main-entities/vehicle"
vehiclehist "simrs-vx/internal/domain/main-entities/vehicle-hist"
village "simrs-vx/internal/domain/main-entities/village"
///BPJS
@@ -163,5 +166,8 @@ func getMainEntities() []any {
&internalreference.InternalReference{},
&vclaimsephist.VclaimSepHist{},
&vclaimsepprint.VclaimSepPrint{},
&vehicle.Vehicle{},
&vehiclehist.VehicleHist{},
&ambulancetransportreq.AmbulanceTransportReq{},
}
}
@@ -19,5 +19,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicalActionSrc) {
data.Code = inputSrc.Code
data.Name = inputSrc.Name
data.Type_Code = inputSrc.Type_Code
data.Item_Id = inputSrc.Item_Id
}
+21 -9
View File
@@ -91,7 +91,8 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
Preload("Person.Contacts").
Preload("Person.Relatives.Village.District.Regency.Province").
Preload("Person.Addresses.Village.District.Regency.Province").
Preload("Person.Addresses.PostalRegion.Village.District.Regency.Province")
Preload("Person.Addresses.PostalRegion.Village.District.Regency.Province").
Preload("Person.Insurances.InsuranceCompany")
if err := tx.First(&data, input.Id).Error; err != nil {
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
@@ -157,6 +158,7 @@ func SearchData(input e.SearchDto, event *pl.Event, dbx ...*gorm.DB) (*e.Patient
pl.SetLogInfo(event, input, "started", "DBSearch")
var patient e.Patient
var err error
var tx *gorm.DB
if len(dbx) > 0 {
@@ -167,15 +169,25 @@ func SearchData(input e.SearchDto, event *pl.Event, dbx ...*gorm.DB) (*e.Patient
// Preload associations for complete data
tx = tx.Preload(clause.Associations)
tx = tx.Preload("Person.Addresses")
tx = tx.Preload("Person.Contacts")
tx = tx.Preload("Person.Relatives")
tx = tx.Preload("Person.Addresses").
Preload("Person.Contacts").
Preload("Person.Relatives").
Preload("Person.Insurances")
// Search by patient number OR person's resident identity number (exact match)
err := tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
Where("\"Patient\".\"Number\" = ? OR \"Person\".\"ResidentIdentityNumber\" = ?",
input.Search, input.Search).
First(&patient).Error
switch input.Mode {
case e.SMIdent:
// Search by patient number OR person's resident identity number (exact match) OR person's name (partial match)
err = tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
Where("\"Patient\".\"Number\" = ? OR \"Person\".\"ResidentIdentityNumber\" = ? OR \"Person\".\"Name\" ILIKE ?",
input.Search, input.Search, "%"+input.Search+"%").
First(&patient).Error
case e.SMNik:
// Search by patient person's resident identity number (exact match)
err = tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
Where("\"Person\".\"ResidentIdentityNumber\" = ?",
input.Search).
First(&patient).Error
}
if err != nil {
if processedErr := pu.HandleSearchError(err, event, source, input.Search, patient); processedErr != nil {