From 1fb1caaf194e6227097026b6d504eb56dcf1fcd0 Mon Sep 17 00:00:00 2001 From: ahdan15 Date: Wed, 14 May 2025 09:44:08 +0700 Subject: [PATCH] pembaruhan baru --- internal/server/routes.go | 47 +- pkg/database/mongo/appointment.go | 25 + pkg/database/mongo/extension.go | 198 ++++ pkg/database/mongo/location.go | 36 + pkg/database/satu_data/Practitioner.go | 58 +- pkg/database/satu_data/location.go | 30 + pkg/handlers/Master/extension.go | 148 +++ pkg/handlers/Practitioner/Practitioner.go | 78 +- pkg/handlers/appointment/appointment.go | 29 + pkg/handlers/location/location.go | 29 + pkg/handlers/migrasi/extension/extension.go | 620 +++++++++++- pkg/handlers/migrasi/location/location.go | 898 ++++++++++-------- pkg/handlers/migrasi/migrasi.go | 145 --- pkg/models/mongo/appointment/appointment.go | 51 + pkg/models/mongo/location/location.go | 46 +- .../master/masteraddress/masteraddress.go | 84 ++ pkg/models/simrs/icd.go | 8 + pkg/models/simrs/location.go | 15 + pkg/models/simrs/practitioner.go | 32 + pkg/models/struct/fhir.go | 58 +- 20 files changed, 1964 insertions(+), 671 deletions(-) create mode 100644 pkg/database/mongo/appointment.go create mode 100644 pkg/database/mongo/extension.go create mode 100644 pkg/database/mongo/location.go create mode 100644 pkg/database/satu_data/location.go create mode 100644 pkg/handlers/appointment/appointment.go create mode 100644 pkg/handlers/location/location.go create mode 100644 pkg/models/mongo/appointment/appointment.go create mode 100644 pkg/models/simrs/icd.go create mode 100644 pkg/models/simrs/location.go create mode 100644 pkg/models/simrs/practitioner.go diff --git a/internal/server/routes.go b/internal/server/routes.go index c2f639b..976c84c 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -2,17 +2,19 @@ package server import ( MasterHandler "api-poliklinik/pkg/handlers/Master" - //MigrasiExtension "api-poliklinik/pkg/handlers/Migrasi/extension" patientHandler "api-poliklinik/pkg/handlers/MongoHandler/Patient" patientRelatedHandler "api-poliklinik/pkg/handlers/MongoHandler/PatientRelated" personHandler "api-poliklinik/pkg/handlers/MongoHandler/person" practitionerHandler "api-poliklinik/pkg/handlers/MongoHandler/practitioner" datarelatedpersonHandler "api-poliklinik/pkg/handlers/MongoHandler/relatedperson" datapoliklinikHandler "api-poliklinik/pkg/handlers/Poliklinik" - datapractitionerHandler "api-poliklinik/pkg/handlers/Practitioner" dataAlamatHandler "api-poliklinik/pkg/handlers/address" + AppointmentHandler "api-poliklinik/pkg/handlers/appointment" + LocationHandler "api-poliklinik/pkg/handlers/location" MigrasiHandler "api-poliklinik/pkg/handlers/migrasi" MigrasiAddress "api-poliklinik/pkg/handlers/migrasi/address" + MigrasiExtension "api-poliklinik/pkg/handlers/migrasi/extension" + MigrasiLocation "api-poliklinik/pkg/handlers/migrasi/location" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" "net/http" @@ -35,14 +37,20 @@ func (s *Server) RegisterRoutes() http.Handler { migrasi := v1.Group("/migrasi") { - migrasi.POST("/migrate/practitioners", MigrasiHandler.MigratePractitionerToFHIR) + //migrasi.POST("/migrate/practitioners", MigrasiPractitioner.MigratePractitionerToFHIR) migrasi.POST("/migrate/pasien", MigrasiHandler.MigratePasienToFHIR) migrasi.POST("/migrate/provinsi", MigrasiAddress.Migrasiprovinsi) migrasi.POST("/migrate/kota", MigrasiAddress.Migrasikota) migrasi.POST("/migrate/kecamatan", MigrasiAddress.Migrasikecamatan) migrasi.POST("/migrate/kelurahan", MigrasiAddress.Migrasikelurahan) - //migrasi.POST("/migrate/bahasa", MigrasiExtension.Migrasibahasa) - + migrasi.POST("/migrate/bahasa", MigrasiExtension.Migrasibahasa) + migrasi.POST("/migrate/disabilitas", MigrasiExtension.Migrasidisbilitas) + migrasi.POST("/migrate/pendidikan", MigrasiExtension.Migrasipendidikan) + migrasi.POST("/migrate/pekerjaan", MigrasiExtension.Migrasipekerjaan) + migrasi.POST("/migrate/pernikahan", MigrasiExtension.Migrasipernikahan) + migrasi.POST("/migrate/agama", MigrasiExtension.Migrasiagama) + migrasi.POST("/migrate/suku", MigrasiExtension.Migrasisuku) + migrasi.POST("/migrate/location", MigrasiLocation.Migrasilokasi) } Poliklinik := v1.Group("/poliklinik") @@ -50,12 +58,6 @@ func (s *Server) RegisterRoutes() http.Handler { Poliklinik.GET("/getdata/statuspelayanan/:statuspelayanan", datapoliklinikHandler.GetDataPoliklinik) } - Practitioner := v1.Group("/practitionersatu") - { - Practitioner.GET("/getdata", datapractitionerHandler.GetDataPractitioner) - Practitioner.GET("/getdatapasien", datapractitionerHandler.GetDataMPasien) - - } Alamat := v1.Group("/Alamat") { Alamat.GET("/getdata", dataAlamatHandler.GetDataAlamat) @@ -110,7 +112,14 @@ func (s *Server) RegisterRoutes() http.Handler { Location := v1.Group("/location") { - Location.GET("/getdatalocation", personHandler.GetDataPerson) + Location.GET("/getdatalocation", LocationHandler.Getlocation) + //Location.POST("/insertlocation", personHandler.Inse rtPerson) + //Location.POST("/deletelocation", personHandler.DeletePersonHand) + } + + Appointment := v1.Group("/appointment") + { + Appointment.GET("/getdataappointment", AppointmentHandler.Getappointment) //Location.POST("/insertlocation", personHandler.Inse rtPerson) //Location.POST("/deletelocation", personHandler.DeletePersonHand) } @@ -126,10 +135,16 @@ func (s *Server) RegisterRoutes() http.Handler { Master.GET("/address/kelurahan/id/:id", MasterHandler.GetHierarchyByKelurahan) Master.GET("/hierarchy/provinsi/:id", MasterHandler.GetHierarchyFromProvinsi) } - // Extension := v1.Group("/extension") - //{ - // //Extension.GET("/getcommunication", MasterHandler.Getsuku ) - //} + Extension := v1.Group("/extension") + { + Extension.GET("/getcommunication", MasterHandler.GetCommunication) + Extension.GET("/getdisability", MasterHandler.Getdisability) + Extension.GET("/geteducation", MasterHandler.Geteducation) + Extension.GET("/getjob", MasterHandler.Getjob) + Extension.GET("/getmartial", MasterHandler.Getmartial) + Extension.GET("/getreligion", MasterHandler.Getreligion) + Extension.GET("/gettribe", MasterHandler.Gettribe) + } return r diff --git a/pkg/database/mongo/appointment.go b/pkg/database/mongo/appointment.go new file mode 100644 index 0000000..4ed86a2 --- /dev/null +++ b/pkg/database/mongo/appointment.go @@ -0,0 +1,25 @@ +package mongo + +import ( + "api-poliklinik/pkg/models/mongo/appointment" + "context" + "go.mongodb.org/mongo-driver/bson" + "log" + "time" +) + +func (s *DatabaseService) Getappointment() ([]*appointment.Appointment, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + dataappointment, err := s.DBMongo.Collection("location").Find(ctx, bson.D{}) + if err != nil { + log.Println(err) + } + var appointment []*appointment.Appointment + err = dataappointment.All(ctx, &appointment) + if err != nil { + log.Println(err) + return nil, err + } + return appointment, nil +} diff --git a/pkg/database/mongo/extension.go b/pkg/database/mongo/extension.go new file mode 100644 index 0000000..a7815f6 --- /dev/null +++ b/pkg/database/mongo/extension.go @@ -0,0 +1,198 @@ +package mongo + +import ( + Mongomaster "api-poliklinik/pkg/models/mongo/master/masteraddress" + "context" + "go.mongodb.org/mongo-driver/bson" + "log" + "time" +) + +func (s *DatabaseService) Insertcommunication(req Mongomaster.Communication) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, err := s.DBMongo.Collection("communication").InsertOne(ctx, req) + if err != nil { + log.Println(err) + return err + } + return nil +} + +func (s *DatabaseService) Insertdisability(req Mongomaster.Disability) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, err := s.DBMongo.Collection("disability").InsertOne(ctx, req) + if err != nil { + log.Println(err) + return err + } + return nil +} + +func (s *DatabaseService) Inserteducation(req Mongomaster.Education) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, err := s.DBMongo.Collection("education").InsertOne(ctx, req) + if err != nil { + log.Println(err) + return err + } + return nil +} + +func (s *DatabaseService) Insertjob(req Mongomaster.Job) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, err := s.DBMongo.Collection("job").InsertOne(ctx, req) + if err != nil { + log.Println(err) + return err + } + return nil +} + +func (s *DatabaseService) Insertmartial(req Mongomaster.MartialStatus) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, err := s.DBMongo.Collection("martialstatus").InsertOne(ctx, req) + if err != nil { + log.Println(err) + return err + } + return nil +} + +func (s *DatabaseService) Insertreligion(req Mongomaster.Religion) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, err := s.DBMongo.Collection("religion").InsertOne(ctx, req) + if err != nil { + log.Println(err) + return err + } + return nil +} + +func (s *DatabaseService) Inserttribe(req Mongomaster.Tribe) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, err := s.DBMongo.Collection("tribe").InsertOne(ctx, req) + if err != nil { + log.Println(err) + return err + } + return nil +} + +func (s *DatabaseService) Getcommunication() ([]*Mongomaster.Communication, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + datacommunication, err := s.DBMongo.Collection("communication").Find(ctx, bson.D{}) + if err != nil { + log.Println(err) + } + var komunikasi []*Mongomaster.Communication + err = datacommunication.All(ctx, &komunikasi) + if err != nil { + log.Println(err) + return nil, err + } + return komunikasi, nil +} + +func (s *DatabaseService) Getdisability() ([]*Mongomaster.Disability, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + datadisabilitas, err := s.DBMongo.Collection("disability").Find(ctx, bson.D{}) + if err != nil { + log.Println(err) + } + var disabilitas []*Mongomaster.Disability + err = datadisabilitas.All(ctx, &disabilitas) + if err != nil { + log.Println(err) + return nil, err + } + return disabilitas, nil +} + +func (s *DatabaseService) Geteducation() ([]*Mongomaster.Education, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + datapendidikan, err := s.DBMongo.Collection("education").Find(ctx, bson.D{}) + if err != nil { + log.Println(err) + } + var pendidikan []*Mongomaster.Education + err = datapendidikan.All(ctx, &pendidikan) + if err != nil { + log.Println(err) + return nil, err + } + return pendidikan, nil +} + +func (s *DatabaseService) Getjob() ([]*Mongomaster.Job, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + datapekerjaan, err := s.DBMongo.Collection("job").Find(ctx, bson.D{}) + if err != nil { + log.Println(err) + } + var pekerjaan []*Mongomaster.Job + err = datapekerjaan.All(ctx, &pekerjaan) + if err != nil { + log.Println(err) + return nil, err + } + return pekerjaan, nil +} + +func (s *DatabaseService) Getmartial() ([]*Mongomaster.MartialStatus, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + datapernikahan, err := s.DBMongo.Collection("martialstatus").Find(ctx, bson.D{}) + if err != nil { + log.Println(err) + } + var pernikahan []*Mongomaster.MartialStatus + err = datapernikahan.All(ctx, &pernikahan) + if err != nil { + log.Println(err) + return nil, err + } + return pernikahan, nil +} + +func (s *DatabaseService) Getreligion() ([]*Mongomaster.Religion, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + dataagama, err := s.DBMongo.Collection("religion").Find(ctx, bson.D{}) + if err != nil { + log.Println(err) + } + var agama []*Mongomaster.Religion + err = dataagama.All(ctx, &agama) + if err != nil { + log.Println(err) + return nil, err + } + return agama, nil +} + +func (s *DatabaseService) Getsuku() ([]*Mongomaster.Tribe, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + datasuku, err := s.DBMongo.Collection("tribe").Find(ctx, bson.D{}) + if err != nil { + log.Println(err) + } + var suku []*Mongomaster.Tribe + err = datasuku.All(ctx, &suku) + if err != nil { + log.Println(err) + return nil, err + } + return suku, nil +} diff --git a/pkg/database/mongo/location.go b/pkg/database/mongo/location.go new file mode 100644 index 0000000..cb5c046 --- /dev/null +++ b/pkg/database/mongo/location.go @@ -0,0 +1,36 @@ +package mongo + +import ( + "api-poliklinik/pkg/models/mongo/location" + "context" + "go.mongodb.org/mongo-driver/bson" + "log" + "time" +) + +func (s *DatabaseService) Insertlokasi(req location.Location) error { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, err := s.DBMongo.Collection("location").InsertOne(ctx, req) + if err != nil { + log.Println(err) + return err + } + return nil +} + +func (s *DatabaseService) Getlocation() ([]*location.Location, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + datalocation, err := s.DBMongo.Collection("location").Find(ctx, bson.D{}) + if err != nil { + log.Println(err) + } + var location []*location.Location + err = datalocation.All(ctx, &location) + if err != nil { + log.Println(err) + return nil, err + } + return location, nil +} diff --git a/pkg/database/satu_data/Practitioner.go b/pkg/database/satu_data/Practitioner.go index 9823e50..725d914 100644 --- a/pkg/database/satu_data/Practitioner.go +++ b/pkg/database/satu_data/Practitioner.go @@ -1,30 +1,23 @@ package satu_data import ( - "api-poliklinik/pkg/models/satu_data" + "api-poliklinik/pkg/models/simrs" "errors" "gorm.io/gorm" "log" ) -func (s *DatabaseService) PractitionerGetData() []*satu_data.PractitionerGetData { - var datapractitioner []*satu_data.PractitionerGetData - query := `select dp.id,dp."NIP", dk."Jenis_kelamin", - array( - select dgd. "Gelar_depan" - from data_pegawai_daftar_gelar_depan dpdgd - left join daftar_gelar_depan dgd on dpdgd.daftar_gelar_depan_id = dgd.id where dpdgd.data_pegawai_id = dp.id - ) AS gelardepan , - dk."Nama_lengkap" , - array( - select dgb. "Gelar_belakang" - from data_pegawai_daftar_gelar_belakang dpdgb - left join daftar_gelar_belakang dgb on dpdgb.daftar_gelar_belakang_id = dgb.id where dpdgb.data_pegawai_id = dp.id - ) AS gelarbelakang - from "data_pegawai" dp - left join data_ktp dk on dp."KTP" = dk.id - left join daftar_practitioner dp2 on dp2.id = dp."Practitioner" where dp2."Code" = 'doctor'` - errQuery := s.DB.Debug().Raw(query).Scan(&datapractitioner).Error +func (s *DatabaseService) Getdokter() []*simrs.Practitionerdoktersimrs { + var datadokter []*simrs.Practitionerdoktersimrs + query := `select + md.kddokter as id_kddokter, md.kdpoly as id_kdpoly, md.kode_dpjp as id_kodedpjp, md.nip as id_nip, + md.aktif as st_aktif, + md.namadokter as nm_namadokter, + md.no_hp as te_nomorhp, md.email as te_email, + md.tgl_akhir_sip as qu_sip, md.tgl_akhir_spk as qu_spk, + md.kdsmf as ex_smf, md.kategori as ex_kategori +from m_dokter md` + errQuery := s.DB.Debug().Raw(query).Scan(&datadokter).Error if errQuery != nil { if errors.Is(errQuery, gorm.ErrRecordNotFound) { errMsg := errors.New("Data Tidak Ditemukan") @@ -34,5 +27,30 @@ func (s *DatabaseService) PractitionerGetData() []*satu_data.PractitionerGetData log.Println(errQuery) return nil } - return datapractitioner + return datadokter +} + +func (s *DatabaseService) Getperawat() []*simrs.Practitionerperawatsimrs { + var dataperawat []*simrs.Practitionerperawatsimrs + query := `select + mp.idperawat as id_perawat, mp.nip as id_nip, mp.noktp as id_noktp, + mp.aktif as st_status, + mp.nama as nm_nama, + mp.notelp as te_telpon, + mp.jeniskelamin as ge_jeniskelamin, + mp.tgllahir as bir_tgllahir, + mp.alamat as ad_alamat, mp.kelurahan as ad_kelurahan, mp.kdkecamatan as ad_kecamatan, mp.kota as ad_kota, mp.kdprovinsi as ad_provinsi, + mp.tempat as ex_tempatlahir +from m_perawat mp` + errQuery := s.DB.Debug().Raw(query).Scan(&dataperawat).Error + if errQuery != nil { + if errors.Is(errQuery, gorm.ErrRecordNotFound) { + errMsg := errors.New("Data Tidak Ditemukan") + log.Println(errMsg) + return nil + } + log.Println(errQuery) + return nil + } + return dataperawat } diff --git a/pkg/database/satu_data/location.go b/pkg/database/satu_data/location.go new file mode 100644 index 0000000..14928c2 --- /dev/null +++ b/pkg/database/satu_data/location.go @@ -0,0 +1,30 @@ +package satu_data + +import ( + "api-poliklinik/pkg/models/simrs" + "errors" + "gorm.io/gorm" + "log" +) + +func (s *DatabaseService) Getruang() []*simrs.Location { + var dataruang []*simrs.Location + query := `select + mr."no" as id_idruang, mr.kode_ruang as id_kdruang, mr.kdunit as id_kdunit, + mr.st_aktif as st_status, + mr.nama as nm_namaruang, + mr.keterangan as des_keterangan, + mr.kelas as tp_kelas, mr.kelompok as tp_kelompokruang, mr.ruang as tp_typeruang, mr.subsistem as tp_subsistem, mr.is_partial as tp_partial +from m_ruang mr` + errQuery := s.DB.Debug().Raw(query).Scan(&dataruang).Error + if errQuery != nil { + if errors.Is(errQuery, gorm.ErrRecordNotFound) { + errMsg := errors.New("Data Tidak Ditemukan") + log.Println(errMsg) + return nil + } + log.Println(errQuery) + return nil + } + return dataruang +} diff --git a/pkg/handlers/Master/extension.go b/pkg/handlers/Master/extension.go index 88f304a..a4fb7ab 100644 --- a/pkg/handlers/Master/extension.go +++ b/pkg/handlers/Master/extension.go @@ -1 +1,149 @@ package Master + +import ( + "api-poliklinik/internal/database" + "api-poliklinik/pkg/database/mongo" + "github.com/gin-gonic/gin" + "net/http" + "os" +) + +func GetCommunication(c *gin.Context) { + local := os.Getenv("MONGODB_DEV_MASTER") + db := database.New(local).GetMongoDB() + if db == nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) + return + } + + mongoDB := mongo.NewDatabaseServiceMongo(db) + dataCommunication, errSelect := mongoDB.Getcommunication() + if errSelect != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "data": dataCommunication, + "message": "komunikasi Sukses Ter-ambil ", + }) +} + +func Getdisability(c *gin.Context) { + local := os.Getenv("MONGODB_DEV_MASTER") + db := database.New(local).GetMongoDB() + if db == nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) + return + } + + mongoDB := mongo.NewDatabaseServiceMongo(db) + dataDisability, errSelect := mongoDB.Getdisability() + if errSelect != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "data": dataDisability, + "message": "disabilitas Sukses Ter-ambil ", + }) +} + +func Geteducation(c *gin.Context) { + local := os.Getenv("MONGODB_DEV_MASTER") + db := database.New(local).GetMongoDB() + if db == nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) + return + } + + mongoDB := mongo.NewDatabaseServiceMongo(db) + dataEducation, errSelect := mongoDB.Geteducation() + if errSelect != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "data": dataEducation, + "message": "disabilitas Sukses Ter-ambil ", + }) +} + +func Getjob(c *gin.Context) { + local := os.Getenv("MONGODB_DEV_MASTER") + db := database.New(local).GetMongoDB() + if db == nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) + return + } + + mongoDB := mongo.NewDatabaseServiceMongo(db) + dataJob, errSelect := mongoDB.Getjob() + if errSelect != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "data": dataJob, + "message": "pekerjaan Sukses Ter-ambil ", + }) +} + +func Getmartial(c *gin.Context) { + local := os.Getenv("MONGODB_DEV_MASTER") + db := database.New(local).GetMongoDB() + if db == nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) + return + } + + mongoDB := mongo.NewDatabaseServiceMongo(db) + dataMartial, errSelect := mongoDB.Getmartial() + if errSelect != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "data": dataMartial, + "message": "pernikahan Sukses Ter-ambil ", + }) +} + +func Getreligion(c *gin.Context) { + local := os.Getenv("MONGODB_DEV_MASTER") + db := database.New(local).GetMongoDB() + if db == nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) + return + } + + mongoDB := mongo.NewDatabaseServiceMongo(db) + dataReligion, errSelect := mongoDB.Getreligion() + if errSelect != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "data": dataReligion, + "message": "agama Sukses Ter-ambil ", + }) +} + +func Gettribe(c *gin.Context) { + local := os.Getenv("MONGODB_DEV_MASTER") + db := database.New(local).GetMongoDB() + if db == nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) + return + } + + mongoDB := mongo.NewDatabaseServiceMongo(db) + dataTribe, errSelect := mongoDB.Getsuku() + if errSelect != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "data": dataTribe, + "message": "suku Sukses Ter-ambil ", + }) +} diff --git a/pkg/handlers/Practitioner/Practitioner.go b/pkg/handlers/Practitioner/Practitioner.go index b2457f4..03d40df 100644 --- a/pkg/handlers/Practitioner/Practitioner.go +++ b/pkg/handlers/Practitioner/Practitioner.go @@ -1,47 +1,35 @@ package Practitioner -import ( - "api-poliklinik/internal/database" - connDatabase "api-poliklinik/pkg/database/satu_data" - "api-poliklinik/pkg/models/satu_data" - - "api-poliklinik/utils" - "github.com/gin-gonic/gin" - "log" - "net/http" - "strings" -) - -func GetDataPractitioner(c *gin.Context) { - db := database.New().GetDB("satudata") - satudata := connDatabase.NewDatabaseService(db) - - log.Println("REQUEST") - dataPractitioner := satudata.PractitionerGetData() - var responsePractitioner []satu_data.DataResponse - for _, k := range dataPractitioner { - gelarDepan := utils.ReplaceGelar(k.GelarDepan) - gelarBelakang := utils.ReplaceGelar(k.GelarBelakang) - namaLengkap := gelarDepan + " " + k.NamaLengkap + " " + gelarBelakang - namaLengkap = strings.TrimPrefix(namaLengkap, " ") - namaLengkap = strings.TrimSuffix(namaLengkap, " ") - - responsePractitioner = append(responsePractitioner, satu_data.DataResponse{ - ID: k.ID, - NIP: k.NIP, - JenisKelamin: k.JenisKelamin, - NamaLengkapFull: namaLengkap, - }) - } - - c.JSON(http.StatusOK, responsePractitioner) -} - -func GetDataMPasien(c *gin.Context) { - db := database.New().GetDB("simrs") - simrs := connDatabase.NewDatabaseService(db) - - dataMPasien := simrs.GetPasien() - c.JSON(http.StatusOK, dataMPasien) - -} +//func GetDataPractitioner(c *gin.Context) { +// db := database.New().GetDB("satudata") +// satudata := connDatabase.NewDatabaseService(db) +// +// log.Println("REQUEST") +// dataPractitioner := satudata.PractitionerGetData() +// var responsePractitioner []satu_data.DataResponse +// for _, k := range dataPractitioner { +// gelarDepan := utils.ReplaceGelar(k.GelarDepan) +// gelarBelakang := utils.ReplaceGelar(k.GelarBelakang) +// namaLengkap := gelarDepan + " " + k.NamaLengkap + " " + gelarBelakang +// namaLengkap = strings.TrimPrefix(namaLengkap, " ") +// namaLengkap = strings.TrimSuffix(namaLengkap, " ") +// +// responsePractitioner = append(responsePractitioner, satu_data.DataResponse{ +// ID: k.ID, +// NIP: k.NIP, +// JenisKelamin: k.JenisKelamin, +// NamaLengkapFull: namaLengkap, +// }) +// } +// +// c.JSON(http.StatusOK, responsePractitioner) +//} +// +//func GetDataMPasien(c *gin.Context) { +// db := database.New().GetDB("simrs") +// simrs := connDatabase.NewDatabaseService(db) +// +// dataMPasien := simrs.GetPasien() +// c.JSON(http.StatusOK, dataMPasien) +// +//} diff --git a/pkg/handlers/appointment/appointment.go b/pkg/handlers/appointment/appointment.go new file mode 100644 index 0000000..2a7917a --- /dev/null +++ b/pkg/handlers/appointment/appointment.go @@ -0,0 +1,29 @@ +package appointment + +import ( + "api-poliklinik/internal/database" + "api-poliklinik/pkg/database/mongo" + "github.com/gin-gonic/gin" + "net/http" + "os" +) + +func Getappointment(c *gin.Context) { + local := os.Getenv("MONGODB_DEV_LOCAL") + db := database.New(local).GetMongoDB() + if db == nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) + return + } + + mongoDB := mongo.NewDatabaseServiceMongo(db) + dataAppointment, errSelect := mongoDB.Getappointment() + if errSelect != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "data": dataAppointment, + "message": "location Sukses Ter-ambil ", + }) +} diff --git a/pkg/handlers/location/location.go b/pkg/handlers/location/location.go new file mode 100644 index 0000000..ec72b71 --- /dev/null +++ b/pkg/handlers/location/location.go @@ -0,0 +1,29 @@ +package location + +import ( + "api-poliklinik/internal/database" + "api-poliklinik/pkg/database/mongo" + "github.com/gin-gonic/gin" + "net/http" + "os" +) + +func Getlocation(c *gin.Context) { + local := os.Getenv("MONGODB_DEV_LOCAL") + db := database.New(local).GetMongoDB() + if db == nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) + return + } + + mongoDB := mongo.NewDatabaseServiceMongo(db) + dataLocation, errSelect := mongoDB.Getlocation() + if errSelect != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "data": dataLocation, + "message": "location Sukses Ter-ambil ", + }) +} diff --git a/pkg/handlers/migrasi/extension/extension.go b/pkg/handlers/migrasi/extension/extension.go index c9fa464..0cf003e 100644 --- a/pkg/handlers/migrasi/extension/extension.go +++ b/pkg/handlers/migrasi/extension/extension.go @@ -8,6 +8,7 @@ import ( _struct "api-poliklinik/pkg/models/struct" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson/primitive" + "log" "net/http" "os" "time" @@ -17,8 +18,8 @@ func Migrasibahasa(c *gin.Context) { db := database.New().GetDB("simrs") simrs := connDatabase.NewDatabaseService(db) - dataKelurahan := simrs.Getkelurahan() - if dataKelurahan == nil || len(dataKelurahan) == 0 { + datakomunikasi := simrs.Getbahasa() + if datakomunikasi == nil || len(datakomunikasi) == 0 { c.JSON(http.StatusNotFound, gin.H{ "status": "error", "message": "Tidak ada data pasien untuk dimigrasi", @@ -41,29 +42,29 @@ func Migrasibahasa(c *gin.Context) { failedCount := 0 var migratedIDs []string - for _, kelurahan := range dataKelurahan { + for _, komunikasi := range datakomunikasi { dateCreated := time.Now().Format("2006-01-02 15:04:05") objectID := primitive.NewObjectID() - var fhirkelurahan = mongomaster.Village{ - ResourceType: "Village", + var fhirkomunikasi = mongomaster.Communication{ + ResourceType: "Communication", ID: objectID, } - fhirkelurahan.Identifier = []_struct.Identifier{ + fhirkomunikasi.Identifier = []_struct.Identifier{ { Use: "usual", System: "", - Value: kelurahan.IDKelurahan, + Value: komunikasi.IDBahasa, Type: _struct.CodeableConcept{ Coding: []_struct.Coding{ { System: "", Version: "", - Code: "idkelurahan", - Display: "ID m_kelurahan Simrs 3.0", + Code: "idxbahasa", + Display: "ID m_bahasa Simrs 3.0", UserSelected: true, }, }, - Text: "ID m_kelurahan Simrs 3.0", + Text: "ID m_bahasa Simrs 3.0", }, Period: _struct.Period{ Start: "", @@ -76,23 +77,20 @@ func Migrasibahasa(c *gin.Context) { }, } - fhirkelurahan.Status = "active" - fhirkelurahan.Name = kelurahan.NamaKelurahan - fhirkelurahan.District = _struct.Reference{ - Reference: "Distric/" + kelurahan.IDKecamatan, - Display: kelurahan.NamaKecamatan, - } - fhirkelurahan.Period = _struct.Period{ + fhirkomunikasi.Status = "active" + fhirkomunikasi.Name = komunikasi.NamaBahasa + fhirkomunikasi.Description = "" + fhirkomunikasi.Period = _struct.Period{ Start: "", End: "", } - fhirkelurahan.CreatedAt = dateCreated - fhirkelurahan.UpdatedAt = dateCreated + fhirkomunikasi.CreatedAt = dateCreated + fhirkomunikasi.UpdatedAt = dateCreated - err := mongoDB.InsertVillage(fhirkelurahan) + err := mongoDB.Insertcommunication(fhirkomunikasi) if err != nil { - log.Printf("Gagal migrasi data kelurahan %s: %v", kelurahan.IDKelurahan, err) + log.Printf("Gagal migrasi data bahasa %s: %v", komunikasi.IDBahasa, err) failedCount++ continue } @@ -103,8 +101,584 @@ func Migrasibahasa(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "status": "success", - "message": "Migrasi data kelurahan ke FHIR berhasil", - "total": len(dataKelurahan), + "message": "Migrasi data bahasa ke FHIR berhasil", + "total": len(datakomunikasi), + "migrated": migratedCount, + "failed": failedCount, + "migrated_ids": migratedIDs, + "timestamp": time.Now().Format(time.RFC3339), + }) +} + +func Migrasidisbilitas(c *gin.Context) { + db := database.New().GetDB("simrs") + simrs := connDatabase.NewDatabaseService(db) + + datadisabilitas := simrs.Getdisabilitas() + if datadisabilitas == nil || len(datadisabilitas) == 0 { + c.JSON(http.StatusNotFound, gin.H{ + "status": "error", + "message": "Tidak ada data pasien untuk dimigrasi", + }) + return + } + + local := os.Getenv("MONGODB_DEV_MASTER") + mongoDBConn := database.New(local).GetMongoDB() + if mongoDBConn == nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "status": "error", + "message": "Koneksi database MongoDB gagal", + }) + return + } + mongoDB := mongo.NewDatabaseServiceMongo(mongoDBConn) + + migratedCount := 0 + failedCount := 0 + var migratedIDs []string + + for _, disabilitas := range datadisabilitas { + dateCreated := time.Now().Format("2006-01-02 15:04:05") + objectID := primitive.NewObjectID() + var fhirdisabilitas = mongomaster.Disability{ + ResourceType: "Disability", + ID: objectID, + } + fhirdisabilitas.Identifier = []_struct.Identifier{ + { + Use: "usual", + System: "", + Value: disabilitas.IDDisabilitas, + Type: _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "kode_disabilitas", + Display: "ID m_disabilitas Simrs 3.0", + UserSelected: true, + }, + }, + Text: "ID m_disabilitas Simrs 3.0", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + Assigner: _struct.Reference{ + Reference: "", + Display: "", + }, + }, + } + + fhirdisabilitas.Status = "active" + fhirdisabilitas.Name = disabilitas.NamaDisabilitas + fhirdisabilitas.Description = "" + fhirdisabilitas.Period = _struct.Period{ + Start: "", + End: "", + } + fhirdisabilitas.CreatedAt = dateCreated + fhirdisabilitas.UpdatedAt = dateCreated + + err := mongoDB.Insertdisability(fhirdisabilitas) + + if err != nil { + log.Printf("Gagal migrasi data disabilitas %s: %v", disabilitas.IDDisabilitas, err) + failedCount++ + continue + } + + migratedIDs = append(migratedIDs, objectID.Hex()) + migratedCount++ + } + + c.JSON(http.StatusOK, gin.H{ + "status": "success", + "message": "Migrasi data disabilitas ke FHIR berhasil", + "total": len(datadisabilitas), + "migrated": migratedCount, + "failed": failedCount, + "migrated_ids": migratedIDs, + "timestamp": time.Now().Format(time.RFC3339), + }) +} + +func Migrasipendidikan(c *gin.Context) { + db := database.New().GetDB("simrs") + simrs := connDatabase.NewDatabaseService(db) + + datapendidikan := simrs.Getpendidikan() + if datapendidikan == nil || len(datapendidikan) == 0 { + c.JSON(http.StatusNotFound, gin.H{ + "status": "error", + "message": "Tidak ada data pasien untuk dimigrasi", + }) + return + } + + local := os.Getenv("MONGODB_DEV_MASTER") + mongoDBConn := database.New(local).GetMongoDB() + if mongoDBConn == nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "status": "error", + "message": "Koneksi database MongoDB gagal", + }) + return + } + mongoDB := mongo.NewDatabaseServiceMongo(mongoDBConn) + + migratedCount := 0 + failedCount := 0 + var migratedIDs []string + + for _, pendidikan := range datapendidikan { + dateCreated := time.Now().Format("2006-01-02 15:04:05") + objectID := primitive.NewObjectID() + var fhirpendidikan = mongomaster.Education{ + ResourceType: "Education", + ID: objectID, + } + fhirpendidikan.Identifier = []_struct.Identifier{ + { + Use: "usual", + System: "", + Value: pendidikan.IDPendidikan, + Type: _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "id_pendidikan", + Display: "ID m_pendidikan_pasien Simrs 3.0", + UserSelected: true, + }, + }, + Text: "ID m_pendidikan_pasien Simrs 3.0", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + Assigner: _struct.Reference{ + Reference: "", + Display: "", + }, + }, + } + + fhirpendidikan.Status = "active" + fhirpendidikan.Name = pendidikan.NamaPendidikan + fhirpendidikan.Description = "" + fhirpendidikan.Period = _struct.Period{ + Start: "", + End: "", + } + fhirpendidikan.CreatedAt = dateCreated + fhirpendidikan.UpdatedAt = dateCreated + + err := mongoDB.Inserteducation(fhirpendidikan) + + if err != nil { + log.Printf("Gagal migrasi data pendidikan %s: %v", pendidikan.IDPendidikan, err) + failedCount++ + continue + } + + migratedIDs = append(migratedIDs, objectID.Hex()) + migratedCount++ + } + + c.JSON(http.StatusOK, gin.H{ + "status": "success", + "message": "Migrasi data pendidikan ke FHIR berhasil", + "total": len(datapendidikan), + "migrated": migratedCount, + "failed": failedCount, + "migrated_ids": migratedIDs, + "timestamp": time.Now().Format(time.RFC3339), + }) +} + +func Migrasipekerjaan(c *gin.Context) { + db := database.New().GetDB("simrs") + simrs := connDatabase.NewDatabaseService(db) + + datapekerjaan := simrs.Getpekerjaan() + if datapekerjaan == nil || len(datapekerjaan) == 0 { + c.JSON(http.StatusNotFound, gin.H{ + "status": "error", + "message": "Tidak ada data pasien untuk dimigrasi", + }) + return + } + + local := os.Getenv("MONGODB_DEV_MASTER") + mongoDBConn := database.New(local).GetMongoDB() + if mongoDBConn == nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "status": "error", + "message": "Koneksi database MongoDB gagal", + }) + return + } + mongoDB := mongo.NewDatabaseServiceMongo(mongoDBConn) + + migratedCount := 0 + failedCount := 0 + var migratedIDs []string + + for _, pekerjaan := range datapekerjaan { + dateCreated := time.Now().Format("2006-01-02 15:04:05") + objectID := primitive.NewObjectID() + var fhirpekerjaan = mongomaster.Job{ + ResourceType: "Job", + ID: objectID, + } + fhirpekerjaan.Identifier = []_struct.Identifier{ + { + Use: "usual", + System: "", + Value: pekerjaan.IDPekerjaan, + Type: _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "idxpekerjaan", + Display: "ID m_pekerjaan Simrs 3.0", + UserSelected: true, + }, + }, + Text: "ID m_pekerjaan Simrs 3.0", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + Assigner: _struct.Reference{ + Reference: "", + Display: "", + }, + }, + } + + fhirpekerjaan.Status = "active" + fhirpekerjaan.Name = pekerjaan.NamaPekerjaan + fhirpekerjaan.Description = "" + fhirpekerjaan.Period = _struct.Period{ + Start: "", + End: "", + } + fhirpekerjaan.CreatedAt = dateCreated + fhirpekerjaan.UpdatedAt = dateCreated + + err := mongoDB.Insertjob(fhirpekerjaan) + + if err != nil { + log.Printf("Gagal migrasi data pekerjaan %s: %v", pekerjaan.IDPekerjaan, err) + failedCount++ + continue + } + + migratedIDs = append(migratedIDs, objectID.Hex()) + migratedCount++ + } + + c.JSON(http.StatusOK, gin.H{ + "status": "success", + "message": "Migrasi data pekerjaan ke FHIR berhasil", + "total": len(datapekerjaan), + "migrated": migratedCount, + "failed": failedCount, + "migrated_ids": migratedIDs, + "timestamp": time.Now().Format(time.RFC3339), + }) +} + +func Migrasipernikahan(c *gin.Context) { + db := database.New().GetDB("simrs") + simrs := connDatabase.NewDatabaseService(db) + + datapernikahan := simrs.Getstatus() + if datapernikahan == nil || len(datapernikahan) == 0 { + c.JSON(http.StatusNotFound, gin.H{ + "status": "error", + "message": "Tidak ada data pasien untuk dimigrasi", + }) + return + } + + local := os.Getenv("MONGODB_DEV_MASTER") + mongoDBConn := database.New(local).GetMongoDB() + if mongoDBConn == nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "status": "error", + "message": "Koneksi database MongoDB gagal", + }) + return + } + mongoDB := mongo.NewDatabaseServiceMongo(mongoDBConn) + + migratedCount := 0 + failedCount := 0 + var migratedIDs []string + + for _, pernikahan := range datapernikahan { + dateCreated := time.Now().Format("2006-01-02 15:04:05") + objectID := primitive.NewObjectID() + var fhirpernikahan = mongomaster.MartialStatus{ + ResourceType: "Martial Status", + ID: objectID, + } + fhirpernikahan.Identifier = []_struct.Identifier{ + { + Use: "usual", + System: "", + Value: pernikahan.IDStatus, + Type: _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "idxstatus", + Display: "ID m_status_pasien Simrs 3.0", + UserSelected: true, + }, + }, + Text: "ID m_status_pasien Simrs 3.0", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + Assigner: _struct.Reference{ + Reference: "", + Display: "", + }, + }, + } + + fhirpernikahan.Status = "active" + fhirpernikahan.Name = pernikahan.NamaStatus + fhirpernikahan.Description = "" + fhirpernikahan.Period = _struct.Period{ + Start: "", + End: "", + } + fhirpernikahan.CreatedAt = dateCreated + fhirpernikahan.UpdatedAt = dateCreated + + err := mongoDB.Insertmartial(fhirpernikahan) + + if err != nil { + log.Printf("Gagal migrasi data pernikahan %s: %v", pernikahan.IDStatus, err) + failedCount++ + continue + } + + migratedIDs = append(migratedIDs, objectID.Hex()) + migratedCount++ + } + + c.JSON(http.StatusOK, gin.H{ + "status": "success", + "message": "Migrasi data pernikahan ke FHIR berhasil", + "total": len(datapernikahan), + "migrated": migratedCount, + "failed": failedCount, + "migrated_ids": migratedIDs, + "timestamp": time.Now().Format(time.RFC3339), + }) +} + +func Migrasiagama(c *gin.Context) { + db := database.New().GetDB("simrs") + simrs := connDatabase.NewDatabaseService(db) + + dataagama := simrs.Getagama() + if dataagama == nil || len(dataagama) == 0 { + c.JSON(http.StatusNotFound, gin.H{ + "status": "error", + "message": "Tidak ada data pasien untuk dimigrasi", + }) + return + } + + local := os.Getenv("MONGODB_DEV_MASTER") + mongoDBConn := database.New(local).GetMongoDB() + if mongoDBConn == nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "status": "error", + "message": "Koneksi database MongoDB gagal", + }) + return + } + mongoDB := mongo.NewDatabaseServiceMongo(mongoDBConn) + + migratedCount := 0 + failedCount := 0 + var migratedIDs []string + + for _, agama := range dataagama { + dateCreated := time.Now().Format("2006-01-02 15:04:05") + objectID := primitive.NewObjectID() + var fhiragama = mongomaster.Religion{ + ResourceType: "Religion", + ID: objectID, + } + fhiragama.Identifier = []_struct.Identifier{ + { + Use: "usual", + System: "", + Value: agama.IDAgama, + Type: _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "idagama", + Display: "ID m_agama_pasien Simrs 3.0", + UserSelected: true, + }, + }, + Text: "ID m_agama_pasien Simrs 3.0", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + Assigner: _struct.Reference{ + Reference: "", + Display: "", + }, + }, + } + + fhiragama.Status = "active" + fhiragama.Name = agama.NamaAgama + fhiragama.Description = "" + fhiragama.Period = _struct.Period{ + Start: "", + End: "", + } + fhiragama.CreatedAt = dateCreated + fhiragama.UpdatedAt = dateCreated + + err := mongoDB.Insertreligion(fhiragama) + + if err != nil { + log.Printf("Gagal migrasi data agama %s: %v", agama.IDAgama, err) + failedCount++ + continue + } + + migratedIDs = append(migratedIDs, objectID.Hex()) + migratedCount++ + } + + c.JSON(http.StatusOK, gin.H{ + "status": "success", + "message": "Migrasi data agama ke FHIR berhasil", + "total": len(dataagama), + "migrated": migratedCount, + "failed": failedCount, + "migrated_ids": migratedIDs, + "timestamp": time.Now().Format(time.RFC3339), + }) +} + +func Migrasisuku(c *gin.Context) { + db := database.New().GetDB("simrs") + simrs := connDatabase.NewDatabaseService(db) + + datasuku := simrs.Getsuku() + if datasuku == nil || len(datasuku) == 0 { + c.JSON(http.StatusNotFound, gin.H{ + "status": "error", + "message": "Tidak ada data pasien untuk dimigrasi", + }) + return + } + + local := os.Getenv("MONGODB_DEV_MASTER") + mongoDBConn := database.New(local).GetMongoDB() + if mongoDBConn == nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "status": "error", + "message": "Koneksi database MongoDB gagal", + }) + return + } + mongoDB := mongo.NewDatabaseServiceMongo(mongoDBConn) + + migratedCount := 0 + failedCount := 0 + var migratedIDs []string + + for _, suku := range datasuku { + dateCreated := time.Now().Format("2006-01-02 15:04:05") + objectID := primitive.NewObjectID() + var fhirsuku = mongomaster.Tribe{ + ResourceType: "Tribe", + ID: objectID, + } + fhirsuku.Identifier = []_struct.Identifier{ + { + Use: "usual", + System: "", + Value: suku.IDSuku, + Type: _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "idxsuku", + Display: "ID m_suku Simrs 3.0", + UserSelected: true, + }, + }, + Text: "ID m_suku Simrs 3.0", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + Assigner: _struct.Reference{ + Reference: "", + Display: "", + }, + }, + } + + fhirsuku.Status = "active" + fhirsuku.Name = suku.NamaSuku + fhirsuku.Description = "" + fhirsuku.Period = _struct.Period{ + Start: "", + End: "", + } + fhirsuku.CreatedAt = dateCreated + fhirsuku.UpdatedAt = dateCreated + + err := mongoDB.Inserttribe(fhirsuku) + + if err != nil { + log.Printf("Gagal migrasi data suku %s: %v", suku.IDSuku, err) + failedCount++ + continue + } + + migratedIDs = append(migratedIDs, objectID.Hex()) + migratedCount++ + } + + c.JSON(http.StatusOK, gin.H{ + "status": "success", + "message": "Migrasi data suku ke FHIR berhasil", + "total": len(datasuku), "migrated": migratedCount, "failed": failedCount, "migrated_ids": migratedIDs, diff --git a/pkg/handlers/migrasi/location/location.go b/pkg/handlers/migrasi/location/location.go index 19edfaf..9d93c13 100644 --- a/pkg/handlers/migrasi/location/location.go +++ b/pkg/handlers/migrasi/location/location.go @@ -1,401 +1,501 @@ package location -// -// -//// Membuat instance Location -//fhirLocation := &models.Location{ -//ResourceType: "Location", -//ID: primitive.NewObjectID(), -//} -// -//// Identifier -//fhirLocation.Identifier = []_struct.Identifier{ -//{ -//Use: "official", -//Type: _struct.CodeableConcept{ -//Coding: []_struct.Coding{ -//{ -//System: "", -//Version: "", -//Code: "", -//Display: "ID m_ruang SIMRS", -//UserSelected: true, -//}, -//}, -//Text: "ID m_ruang SIMRS", -//}, -//System: "", -//Value: "227", -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//Assigner: _struct.Reference{ -//Reference: "", -//Display: "", -//}, -//}, -//{ -//Use: "official", -//Type: _struct.CodeableConcept{ -//Coding: []_struct.Coding{ -//{ -//System: "", -//Version: "", -//Code: "", -//Display: "Kode Ruang", -//UserSelected: true, -//}, -//}, -//Text: "Kode Ruang", -//}, -//System: "", -//Value: "KL-BDH", -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//Assigner: _struct.Reference{ -//Reference: "", -//Display: "", -//}, -//}, -//} -// -//// Status -//fhirLocation.Status = "active" -// -//// OperationalStatus -//fhirLocation.OperationalStatus = _struct.Coding{ -//System: "", -//Version: "", -//Code: "", -//Display: "", -//UserSelected: false, -//} -// -//// Name -//fhirLocation.Name = "Poliklinik Bedah TKV" -// -//// Alias -//fhirLocation.Alias = []string{"Poli Bedah TKV", "Klinik Bedah TKV", "Bedah TKV"} -// -//// Description -//fhirLocation.Description = "Lokasi layanan rawat jalan untuk pasien bedah TKV" -// -//// Mode -//fhirLocation.Mode = "instance" -// -//// Type -//fhirLocation.Type = []_struct.CodeableConcept{ -//{ -//Coding: []_struct.Coding{ -//{ -//System: "http://terminology.hl7.org/CodeSystem/v3-RoleCode", -//Version: "", -//Code: "SU", -//Display: "Surgery clinic", -//UserSelected: false, -//}, -//}, -//Text: "Poliklinik Rawat Jalan", -//}, -//{ -//Coding: []_struct.Coding{ -//{ -//System: "", -//Version: "", -//Code: "IRJA", -//Display: "Instalasi Rawat Jalan", -//UserSelected: false, -//}, -//}, -//Text: "Instalasi Rawat Jalan", -//}, -//{ -//Coding: []_struct.Coding{ -//{ -//System: "", -//Version: "", -//Code: "SUBSISTEM", -//Display: "Rawat Jalan Reguler", -//UserSelected: false, -//}, -//}, -//Text: "Rawat Jalan Reguler", -//}, -//} -// -//// Contact -//fhirLocation.Contact = []_struct.ExtendedContactDetail{ -//{ -//Purpose: _struct.CodeableConcept{ -//Coding: []_struct.Coding{ -//{ -//System: "http://terminology.hl7.org/CodeSystem/contactentity-type", -//Code: "PATINF", -//Display: "Patient", -//}, -//}, -//}, -//Telecom: []_struct.ContactPoint{ -//{ -//System: "pager", -//Value: "1243", -//Use: "work", -//Rank: 1, -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//}, -//}, -//Address: _struct.Address{ -//Use: "work", -//Type: "both", -//Text: "Jl. Jaksa Agung Suprapto No.2, Klojen, Kec. Klojen, Kota Malang, Jawa Timur 65112", -//Line: []string{"Jl. Jaksa Agung Suprapto No.2"}, -//Village: "Klojen", -//District: "Klojen", -//City: "Malang", -//State: "Jawa Timur", -//PostalCode: "65112", -//Country: "Indonesia", -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//Extension: []_struct.Extension{ -//{ -//URL: "", -//Extension: []_struct.ExtensionDetail{ -//{ -//URL: "state", -//ValueDisplay: "Jawa Timur", -//ValueCode: "35", -//}, -//{ -//URL: "city", -//ValueDisplay: "Malang", -//ValueCode: "3573", -//}, -//{ -//URL: "district", -//ValueDisplay: "Klojen", -//ValueCode: "3573030", -//}, -//{ -//URL: "village", -//ValueDisplay: "Klojen", -//ValueCode: "3573030008", -//}, -//{ -//URL: "rt", -//ValueDisplay: "", -//ValueCode: "", -//}, -//{ -//URL: "rw", -//ValueDisplay: "", -//ValueCode: "", -//}, -//}, -//}, -//}, -//}, -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//}, -//} -// -//// Address -//fhirLocation.Address = _struct.Address{ -//Use: "work", -//Type: "both", -//Text: "Jl. Jaksa Agung Suprapto No.2, Klojen, Kec. Klojen, Kota Malang, Jawa Timur 65112", -//Line: []string{"Jl. Jaksa Agung Suprapto No.2"}, -//Village: "Klojen", -//District: "Klojen", -//City: "Malang", -//State: "Jawa Timur", -//PostalCode: "65112", -//Country: "Indonesia", -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//} -// -//// Form -//fhirLocation.Form = []_struct.CodeableConcept{ -//{ -//Coding: []_struct.Coding{ -//{ -//System: "", -//Version: "", -//Code: "", -//Display: "", -//UserSelected: false, -//}, -//}, -//Text: "", -//}, -//} -// -//// Position -//fhirLocation.Position = _struct.Position{ -//Longitude: 112.630348, -//Latitude: -7.981894, -//Altitude: 440, -//} -// -//// ManagingOrganization -//fhirLocation.ManagingOrganization = _struct.Reference{ -//Reference: "Organization/1", -//Display: "RSUD dr. Saiful Anwar Jatim Prov", -//} -// -//// PartOf -//fhirLocation.PartOf = _struct.Reference{ -//Reference: "", -//Display: "", -//} -// -//// Characteristic -//fhirLocation.Characteristic = []_struct.CodeableConcept{ -//{ -//Coding: []_struct.Coding{ -//{ -//System: "", -//Version: "", -//Code: "", -//Display: "", -//UserSelected: false, -//}, -//}, -//Text: "", -//}, -//} -// -//// HoursOfOperation -//fhirLocation.HoursOfOperation = []_struct.HoursOfOperation{ -//{ -//AvailableTime: []_struct.AvailableTime{ -//{ -//DaysOfWeek: []string{"mon", "tue", "wed", "thu", "fri"}, -//AllDay: false, -//AvailableStartTime: "07:00", -//AvailableEndTime: "15:00", -//}, -//}, -//NotAvailableTime: []_struct.NotAvailableTime{ -//{ -//Description: "", -//During: _struct.During{ -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//}, -//}, -//}, -//}, -//} -// -//// VirtualService -//fhirLocation.VirtualService = []_struct.VirtualService{ -//{ -//ChannelType: _struct.Coding{ -//System: "", -//Version: "", -//Code: "", -//Display: "", -//UserSelected: false, -//}, -//AddressUrl: "", -//AddressString: "", -//AddressContactPoint: _struct.ContactPoint{ -//System: "", -//Value: "", -//Use: "", -//Rank: 0, -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//}, -//AddressExtendedContactDetail: _struct.ExtendedContactDetail{ -//Purpose: _struct.CodeableConcept{ -//Coding: []_struct.Coding{ -//{ -//System: "", -//Code: "", -//Display: "", -//}, -//}, -//}, -//Name: []_struct.HumanName{ -//{ -//Use: "", -//Text: "", -//Family: "", -//Given: []string{}, -//Prefix: []string{}, -//Suffix: []string{}, -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//}, -//}, -//Telecom: []_struct.ContactPoint{ -//{ -//System: "", -//Value: "", -//Use: "", -//Rank: 0, -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//}, -//}, -//Address: _struct.Address{ -//Use: "", -//Type: "", -//Text: "", -//Line: []string{}, -//City: "", -//District: "", -//State: "", -//PostalCode: "", -//Country: "", -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//}, -//Organization: _struct.Reference{ -//Reference: "", -//Display: "", -//}, -//Period: _struct.Period{ -//Start: "", -//End: "", -//}, -//}, -//AdditionalInfo: []string{}, -//MaxParticipants: 0, -//SessionKey: "", -//}, -//} -// -//// Endpoint -//fhirLocation.Endpoint = []_struct.Reference{ -//{ -//Reference: "", -//Display: "", -//}, -//} +import ( + "api-poliklinik/internal/database" + "api-poliklinik/pkg/database/mongo" + connDatabase "api-poliklinik/pkg/database/satu_data" + "api-poliklinik/pkg/models/mongo/location" + _struct "api-poliklinik/pkg/models/struct" + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson/primitive" + "log" + "net/http" + "os" + "strings" + "time" +) + +func Migrasilokasi(c *gin.Context) { + + db := database.New().GetDB("simrs") + simrs := connDatabase.NewDatabaseService(db) + + dataLokasi := simrs.Getruang() + if dataLokasi == nil || len(dataLokasi) == 0 { + c.JSON(http.StatusNotFound, gin.H{ + "status": "error", + "message": "Tidak ada data pasien untuk dimigrasi", + }) + return + } + + local := os.Getenv("MONGODB_DEV_LOCAL") + mongoDBConn := database.New(local).GetMongoDB() + if mongoDBConn == nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "status": "error", + "message": "Koneksi database MongoDB gagal", + }) + return + } + mongoDB := mongo.NewDatabaseServiceMongo(mongoDBConn) + + migratedCount := 0 + failedCount := 0 + var migratedIDs []string + + for _, lokasi := range dataLokasi { + objectID := primitive.NewObjectID() + dateCreated := time.Now().Format("2006-01-02 15:04:05") + var code, display, text string + + // Menentukan jenis subsistem berdasarkan dua kata pertama saja + if strings.HasPrefix(lokasi.Subsistem, "RAWAT INAP") { + code = "IRNA" + display = "Instalasi Rawat Inap" + text = "Rawat Inap" + } else if strings.HasPrefix(lokasi.Subsistem, "RAWAT JALAN") { + code = "IRJA" + display = "Instalasi Rawat Jalan" + text = "Rawat Jalan" + } else { + // Untuk kasus lain yang tidak teridentifikasi + code = "UNKNOWN" + display = "Tidak Diketahui" + text = lokasi.Subsistem + } + var fhirLokasi = location.Location{ + ResourceType: "Location", + ID: objectID, + Status: true, + } + fhirLokasi.Identifier = []_struct.Identifier{ + { + Use: "official", + System: "", + Value: lokasi.IDRuang, + Type: _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "ID", + Display: "ID m_ruang SIMRS", + }, + }, + Text: "ID m_ruang SIMRS", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + Assigner: _struct.Reference{ + Reference: "", + Display: "", + }, + }, + { + Use: "official", + System: "", + Value: lokasi.Kdruang, + Type: _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "", + Display: "Kode Ruang", + }, + }, + Text: "Kode Ruang", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + Assigner: _struct.Reference{ + Reference: "", + Display: "", + }, + }, { + Use: "official", + System: "", + Value: lokasi.Kdunit, + Type: _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "", + Display: "Kode Unit", + }, + }, + Text: "Kode Unit", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + Assigner: _struct.Reference{ + Reference: "", + Display: "", + }, + }, + } + fhirLokasi.OperationalStatus = _struct.Coding{ + System: "", + Version: "", + Code: "", + Display: "", + UserSelected: false, + } + fhirLokasi.Name = lokasi.NamaRuang + fhirLokasi.Alias = []string{lokasi.NamaRuang} + fhirLokasi.Description = lokasi.DesRuang + fhirLokasi.Mode = "instance" + fhirLokasi.Type = []_struct.CodeableConcept{ + { + Coding: []_struct.Coding{ + { + System: "http://terminology.hl7.org/CodeSystem/v3-RoleCode", + Version: "", + Code: lokasi.Kelas, + Display: lokasi.KelompokRuang, + UserSelected: true, + }, + }, + Text: "Poliklinik " + text, + }, + { + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: code, + Display: display, + UserSelected: true, + }, + }, + Text: "Instalasi " + text, + }, + { + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "SUBSISTEM", + Display: lokasi.Subsistem, + UserSelected: true, + }, + }, + Text: lokasi.Subsistem, + }, + { + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "PARTIAL", + Display: lokasi.Partial, + UserSelected: true, + }, + }, + Text: lokasi.Partial, + }, + } + fhirLokasi.Contact = _struct.ExtendedContactDetail{ + + Purpose: _struct.Purpose{ + Coding: []_struct.Coding{ + { + System: "http://terminology.hl7.org/CodeSystem/contactentity-type", + Version: "", + Code: "PATINF", + Display: "Patient", + UserSelected: true, + }, + }, + }, + Telecom: []_struct.ContactPoint{ + { + System: "pager", + Value: "1243", + Use: "work", + Rank: 1, + Period: _struct.Period{ + Start: "", + End: "", + }, + }, + }, + Address: []_struct.Address{ + { + Use: "work", + Type: "both", + Text: "Jl. Jaksa Agung Suprapto No.2, Klojen, Kec. Klojen, Kota Malang, Jawa Timur 65112", + Line: []string{"Jl. Jaksa Agung Suprapto No.2"}, + Village: "Klojen", + District: "Klojen", + City: "Malang", + State: "Jawa Timur", + PostalCode: "65112", + Country: "Indonesia", + Period: _struct.Period{ + Start: "", + End: "", + }, + Extension: []_struct.Extension{ + { + URL: "", + Extension: []_struct.ExtensionDetail{ + { + URL: "state", + ValueDisplay: "Jawa Timur", + ValueCode: "35", + }, + { + URL: "city", + ValueDisplay: "Malang", + ValueCode: "3573", + }, + { + URL: "district", + ValueDisplay: "Klojen", + ValueCode: "3573030", + }, + { + URL: "village", + ValueDisplay: "Klojen", + ValueCode: "3573030008", + }, + { + URL: "rt", + ValueDisplay: "", + ValueCode: "", + }, + { + URL: "rw", + ValueDisplay: "", + ValueCode: "", + }, + }, + }, + }, + }, + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + } + + fhirLokasi.Address = _struct.Address{ + + Use: "work", + Type: "both", + Text: "Jl. Jaksa Agung Suprapto No.2, Klojen, Kec. Klojen, Kota Malang, Jawa Timur 65112", + Line: []string{"Jl. Jaksa Agung Suprapto No.2, Klojen, Kec. Klojen, Kota Malang, Jawa Timur 65112"}, + Village: "Klojen", + District: "Klojen", + City: "Malang", + State: "Jawa Timur", + PostalCode: "65112", + Country: "Indonesia", + Period: _struct.Period{ + Start: "", + End: "", + }, + } + fhirLokasi.Form = _struct.CodeableConcept{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "", + Display: "", + UserSelected: false, + }, + }, + Text: "", + } + fhirLokasi.Position = _struct.Position{ + Latitude: 112.630348, + Longitude: -7.981894, + Altitude: 0, + } + + fhirLokasi.ManagingOrganization = _struct.Reference{ + Reference: "Organization/1", + Display: "RSUD dr. Saiful Anwar Jatim Prov", + } + fhirLokasi.PartOf = _struct.Reference{ + Reference: "", + Display: "", + } + fhirLokasi.Characteristic = []_struct.CodeableConcept{ + { + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "", + Display: "", + UserSelected: false, + }, + }, + Text: "", + }, + } + + fhirLokasi.HoursOfOperation = []_struct.Availability{ + { + AvailableTime: []_struct.AvailabilityAvailableTime{ + { + DaysOfWeek: []string{"mon", "tue", "wed", "thu", "fri"}, + AllDay: false, + AvailableStartTime: "07:00", + AvailableEndTime: "15:00", + }, + }, + NotAvailableTime: []_struct.AvailabilityNotAvailable{ + { + Description: "", + During: _struct.Period{ + Start: "", + End: "", + }, + }, + }, + }, + } + + fhirLokasi.VirtualService = []_struct.VirtualService{ + { + ChannelType: _struct.Coding{ + System: "", + Version: "", + Code: "", + Display: "", + UserSelected: false, + }, + AddressUrl: "", + AddressString: "", + AddressContactPoint: _struct.ContactPoint{ + System: "", + Value: "", + Use: "", + Rank: 0, + Period: _struct.Period{ + Start: "", + End: "", + }, + }, + AddressExtendedContact: _struct.ExtendedContactDetail{ + Purpose: _struct.Purpose{ + Coding: []_struct.Coding{ + { + System: "", + Version: "", + Code: "", + Display: "", + UserSelected: false, + }, + }, + }, + Name: []_struct.HumanName{ + { + Use: "", + Text: "", + Family: "", + Given: []string{""}, + Prefix: []string{""}, + Suffix: []string{""}, + Period: _struct.Period{ + Start: "", + End: "", + }, + }, + }, + Telecom: []_struct.ContactPoint{ + { + System: "", + Value: "", + Use: "", + Rank: 0, + Period: _struct.Period{ + Start: "", + End: "", + }, + }, + }, + Address: []_struct.Address{ + { + Use: "", + Type: "", + Text: "", + Line: []string{""}, + City: "", + District: "", + State: "", + PostalCode: "", + Country: "", + Period: _struct.Period{ + Start: "", + End: "", + }, + }, + }, + Organization: _struct.Reference{ + Reference: "", + Display: "", + }, + Period: _struct.Period{ + Start: "", + End: "", + }, + }, + AdditionalInfo: []string{""}, + MaxParticipants: 0, + SessionKey: "", + }, + } + fhirLokasi.Endpoint = _struct.Reference{ + Reference: "", + Display: "", + } + fhirLokasi.CreatedAt = dateCreated + fhirLokasi.UpdatedAt = dateCreated + fhirLokasi.Extension = []_struct.Extension{ + { + URL: "", + Extension: []_struct.ExtensionDetail{ + { + URL: "", + ValueDisplay: "", + ValueCode: "", + }, + }, + }, + } + err := mongoDB.Insertlokasi(fhirLokasi) + + if err != nil { + log.Printf("Gagal migrasi data praktisi %s: %v", lokasi.IDRuang, err) + failedCount++ + continue + } + + migratedIDs = append(migratedIDs, objectID.Hex()) + migratedCount++ + } + + c.JSON(http.StatusOK, gin.H{ + "status": "success", + "message": "Migrasi data praktisi ke FHIR berhasil", + "total": len(dataLokasi), + "migrated": migratedCount, + "failed": failedCount, + "migrated_ids": migratedIDs, + "timestamp": time.Now().Format(time.RFC3339), + }) +} diff --git a/pkg/handlers/migrasi/migrasi.go b/pkg/handlers/migrasi/migrasi.go index 6d2e22b..09aeee4 100644 --- a/pkg/handlers/migrasi/migrasi.go +++ b/pkg/handlers/migrasi/migrasi.go @@ -5,9 +5,7 @@ import ( "api-poliklinik/pkg/database/mongo" connDatabase "api-poliklinik/pkg/database/satu_data" "api-poliklinik/pkg/models/mongo/insertpatient" - Practitionermongo "api-poliklinik/pkg/models/mongo/practitioner" _struct "api-poliklinik/pkg/models/struct" - "api-poliklinik/utils" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson/primitive" "log" @@ -17,149 +15,6 @@ import ( "time" ) -func MigratePractitionerToFHIR(c *gin.Context) { - // 1. Ambil data dari PostgreSQL - db := database.New().GetDB("satudata") - satudata := connDatabase.NewDatabaseService(db) - - // Mendapatkan data praktisi dari PostgreSQL - dataPractitioner := satudata.PractitionerGetData() - if dataPractitioner == nil || len(dataPractitioner) == 0 { - c.JSON(http.StatusNotFound, gin.H{ - "status": "error", - "message": "Tidak ada data praktisi untuk dimigrasi", - }) - return - } - - // 2. Setup koneksi MongoDB - berdasarkan contoh yang diberikan - local := os.Getenv("MONGODB_DEV_LOCAL") - mongoDBConn := database.New(local).GetMongoDB() - if mongoDBConn == nil { - c.JSON(http.StatusInternalServerError, gin.H{ - "status": "error", - "message": "Koneksi database MongoDB gagal", - }) - return - } - mongoDB := mongo.NewDatabaseServiceMongo(mongoDBConn) - - // 3. Transformasi dan migrasi data - migratedCount := 0 - failedCount := 0 - var migratedIDs []string - - for _, practitioner := range dataPractitioner { - // Membuat nama lengkap dengan gelar - gelarDepan := utils.ReplaceGelar(practitioner.GelarDepan) - gelarBelakang := utils.ReplaceGelar(practitioner.GelarBelakang) - namaLengkap := gelarDepan + " " + practitioner.NamaLengkap + " " + gelarBelakang - namaLengkap = strings.TrimPrefix(namaLengkap, " ") - namaLengkap = strings.TrimSuffix(namaLengkap, " ") - - // Mengonversi jenis kelamin ke format FHIR (male/female) - gender := "unknown" - if strings.ToLower(practitioner.JenisKelamin) == "laki-laki" { - gender = "male" - } else if strings.ToLower(practitioner.JenisKelamin) == "perempuan" { - gender = "female" - } - - objectID := primitive.NewObjectID() - - var fhirPractitioner = Practitionermongo.Practitioner{ - ResourceType: "Patient", - ID: objectID, - Identifier: []_struct.Identifier{ - { - Use: "usual", - Type: _struct.CodeableConcept{ - Coding: []_struct.Coding{ - { - System: "", - Version: "", - Code: "IDSIM", - Display: "SIMRS ID", - UserSelected: true, - }, - }, - Text: "SIMRS ID", - }, - System: "http://example.org/fhir/identifier/nip", - Value: practitioner.ID, - Period: _struct.Period{}, - Assigner: _struct.Reference{}, - }, - { - Use: "usual", - Type: _struct.CodeableConcept{ - Coding: []_struct.Coding{ - { - System: "", - Version: "", - Code: "NIP", - Display: "Nomor Induk Pegawai", - UserSelected: true, - }, - }, - Text: "Nomor Induk Pegawai", - }, - System: "http://example.org/fhir/identifier/nip", - Value: practitioner.NIP, - Period: _struct.Period{}, - Assigner: _struct.Reference{}, - }, - }, - Active: true, - Name: []_struct.HumanName{ - { - Use: "official", - Text: namaLengkap, - Family: practitioner.NamaLengkap, - Given: []string{gelarDepan, gelarBelakang}, - }, - }, - Gender: gender, - - Extension: []_struct.Extension{ - { - URL: "http://example.org/fhir/StructureDefinition/practitioner-originalData", - Extension: []_struct.ExtensionDetail{ - { - URL: "originalId", - ValueDisplay: practitioner.ID, - }, - { - URL: "sourceSystem", - ValueDisplay: "PostgreSQL", - }, - }, - }, - }, - } // Menyimpan ke MongoDB - err := mongoDB.InsertPractitioner(fhirPractitioner) - if err != nil { - log.Printf("Gagal migrasi data praktisi %s: %v", practitioner.ID, err) - failedCount++ - continue - } - - migratedIDs = append(migratedIDs, objectID.Hex()) - migratedCount++ - } - - // 4. Mengembalikan hasil migrasi - c.JSON(http.StatusOK, gin.H{ - "status": "success", - "message": "Migrasi data praktisi ke FHIR berhasil", - "total": len(dataPractitioner), - "migrated": migratedCount, - "failed": failedCount, - "migrated_ids": migratedIDs, - "timestamp": time.Now().Format(time.RFC3339), - }) -} - func MigratePasienToFHIR(c *gin.Context) { // 1. Ambil data dari PostgreSQL db := database.New().GetDB("simrs") diff --git a/pkg/models/mongo/appointment/appointment.go b/pkg/models/mongo/appointment/appointment.go new file mode 100644 index 0000000..9f3523e --- /dev/null +++ b/pkg/models/mongo/appointment/appointment.go @@ -0,0 +1,51 @@ +package appointment + +import ( + _struct "api-poliklinik/pkg/models/struct" + "go.mongodb.org/mongo-driver/bson/primitive" +) + +type Appointment struct { + ResourceType string `json:"resourceType" bson:"resourceType"` + ID primitive.ObjectID `json:"id" bson:"_id"` + Identifier []_struct.Identifier `json:"identifier" bson:"identifier"` + Status string `json:"status" bson:"status"` + CancellationReason _struct.CodeableConcept `json:"cancellationReason" bson:"cancellationReason"` + Class []_struct.CodeableConcept `json:"class" bson:"class"` + ServiceCategory []_struct.CodeableConcept `json:"serviceCategory" bson:"serviceCategory"` + ServiceType []_struct.Value `json:"serviceType" bson:"serviceType"` + Specialty []_struct.CodeableConcept `json:"specialty" bson:"specialty"` + AppoinmentType _struct.CodeableConcept `json:"appoinmentType" bson:"appoinmentType"` + Reason []_struct.Value `json:"reason" bson:"reason"` + Priority _struct.CodeableConcept `json:"priority" bson:"priority"` + Description string `json:"description" bson:"description"` + Replaces _struct.Reference `json:"replaces" bson:"replaces"` + VirtualServiceDetail []_struct.VirtualService `json:"virtualServiceDetail" bson:"virtualServiceDetail"` + SupportingInformation []_struct.Reference `json:"supportingInformation" bson:"supportingInformation"` + PreviousAppointment _struct.Reference `json:"previousAppointment" bson:"previousAppointment"` + OriginatingAppointment _struct.Reference `json:"originatingAppointment" bson:"originatingAppointment"` + Start string `json:"start" bson:"start"` + End string `json:"end" bson:"end"` + MinutesDuration int `json:"minutesDuration" bson:"minutesDuration"` + RequestedPeriod []_struct.Period `json:"requestedPeriod" bson:"requestedPeriod"` + Slot []_struct.Reference `json:"slot" bson:"slot"` + Account []_struct.Reference `json:"account" bson:"account"` + Created string `json:"created" bson:"created"` + CancellationDate string `json:"cancellationDate" bson:"cancellationDate"` + Note []_struct.Note `json:"note" bson:"note"` + PatientInstruction []_struct.Concept `json:"patientInstruction" bson:"patientInstruction"` + BasedOn []_struct.Reference `json:"basedOn" bson:"basedOn"` + Subject _struct.Reference `json:"subject" bson:"subject"` + Participant []_struct.Participant `json:"participant" bson:"participant"` + RecurrenceId int `json:"recurrenceId" bson:"recurrenceId"` + OccurrenceChanged bool `json:"occurrenceChanged" bson:"occurrenceChanged"` + RecurrenceTemple []_struct.RecurrenceTemple `json:"recurrenceTemple" bson:"recurrenceTemple"` + WeeklyTemple _struct.WeeklyTemple `json:"weeklyTemple" bson:"weeklyTemple"` + MonthlyTemple _struct.MonthlyTemple `json:"monthlyTemple" bson:"monthlyTemple"` + YearlyTemple _struct.YearlyTemple `json:"yearlyTemple" bson:"yearlyTemple"` + ExcludingDate []string `json:"excludingDate" bson:"excludingDate"` + ExcludingRecurrenceId []int `json:"excludingRecurrenceId" bson:"excludingRecurrenceId"` + CreatedAt string `json:"createdAt" bson:"createdAt"` + UpdatedAt string `json:"updatedAt" bson:"updatedAt"` + Extension []_struct.Extension `json:"extension" bson:"extension"` +} diff --git a/pkg/models/mongo/location/location.go b/pkg/models/mongo/location/location.go index 4c40e4e..ddafc54 100644 --- a/pkg/models/mongo/location/location.go +++ b/pkg/models/mongo/location/location.go @@ -6,25 +6,29 @@ import ( ) type Location struct { - ResourceType string `bson:"resourceType"` - ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` - Identifier []_struct.Identifier `bson:"identifier,omitempty" json:"identifier,omitempty"` - Status bool `bson:"status" json:"status"` - OperationaStatus _struct.Coding `bson:"operationalstatus,omitempty" json:"operational,omitempty"` - Name string `bson:"name" json:"name"` - Alias []string `bson:"alias,omitempty" json:"alias,omitempty"` - Description string `bson:"description,omitempty" json:"description,omitempty"` - Mode string `bson:"mode,omitempty" json:"mode,omitempty"` - Type []_struct.CodeableConcept `bson:"type,omitempty" json:"type,omitempty"` - Contact []_struct.ExtendedContactDetail `bson:"contact,omitempty" json:"contact,omitempty"` - Telecom []_struct.ContactPoint `bson:"telecom,omitempty" json:"telecom,omitempty"` - Address _struct.Address `bson:"address,omitempty" json:"address,omitempty"` - Form []_struct.CodeableConcept `bson:"form,omitempty" json:"form,omitempty"` - Position _struct.Position `bson:"position,omitempty" json:"position,omitempty"` - ManagingOrganization _struct.Reference `bson:"managingOrganization,omitempty" json:"managingOrganization,omitempty"` - PartOf _struct.Reference `bson:"partOf,omitempty" json:"partOf,omitempty"` - Characteristic []_struct.CodeableConcept `bson:"characteristic,omitempty" json:"characteristic,omitempty"` - HoursOfOperation []_struct.Availability `bson:"hoursOfOperation,omitempty" json:"hoursOfOperation,omitempty"` - VirtualService _struct.VirtualService `bson:"virtualService,omitempty" json:"virtualService,omitempty"` - Endpoint _struct.Reference `bson:"endpoint,omitempty" json:"endpoint,omitempty"` + ResourceType string `bson:"resourceType"` + ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` + Identifier []_struct.Identifier `bson:"identifier,omitempty" json:"identifier,omitempty"` + Status bool `bson:"status" json:"status"` + OperationalStatus _struct.Coding `bson:"operationalstatus" json:"operational,omitempty"` + Name string `bson:"name" json:"name"` + Alias []string `bson:"alias,omitempty" json:"alias,omitempty"` + Description string `bson:"description,omitempty" json:"description,omitempty"` + Mode string `bson:"mode,omitempty" json:"mode,omitempty"` + Type []_struct.CodeableConcept `bson:"type,omitempty" json:"type,omitempty"` + Contact _struct.ExtendedContactDetail `bson:"contact,omitempty" json:"contact,omitempty"` + Telecom []_struct.ContactPoint `bson:"telecom,omitempty" json:"telecom,omitempty"` + Address _struct.Address `bson:"address,omitempty" json:"address,omitempty"` + Form _struct.CodeableConcept `bson:"form,omitempty" json:"form,omitempty"` + Position _struct.Position `bson:"position,omitempty" json:"position,omitempty"` + ManagingOrganization _struct.Reference `bson:"managingOrganization,omitempty" json:"managingOrganization,omitempty"` + PartOf _struct.Reference `bson:"partOf,omitempty" json:"partOf,omitempty"` + Characteristic []_struct.CodeableConcept `bson:"characteristic,omitempty" json:"characteristic,omitempty"` + HoursOfOperation []_struct.Availability `bson:"hoursOfOperation,omitempty" json:"hoursOfOperation,omitempty"` + VirtualService []_struct.VirtualService `bson:"virtualService,omitempty" json:"virtualService,omitempty"` + Endpoint _struct.Reference `bson:"endpoint,omitempty" json:"endpoint,omitempty"` + CreatedAt string `bson:"createdAt" json:"createdAt"` + UpdatedAt string `bson:"updatedAt" json:"updatedAt"` + DeletedAt string `bson:"deletedAt" json:"deletedAt"` + Extension []_struct.Extension `bson:"extension,omitempty" json:"extension,omitempty"` } diff --git a/pkg/models/mongo/master/masteraddress/masteraddress.go b/pkg/models/mongo/master/masteraddress/masteraddress.go index 7d67071..6c529bf 100644 --- a/pkg/models/mongo/master/masteraddress/masteraddress.go +++ b/pkg/models/mongo/master/masteraddress/masteraddress.go @@ -51,3 +51,87 @@ type Village struct { CreatedAt string `bson:"createdAt" json:"createdAt"` UpdatedAt string `bson:"updatedAt" json:"updatedAt"` } + +type Communication struct { + ResourceType string `json:"resourceType" bson:"resourceType,omitempty" ` + ID primitive.ObjectID `bson:"_id,omitempty" json:"id" ` + Identifier []_struct.Identifier `bson:"identifier" json:"identifier"` + Status string `bson:"status" json:"status"` + Name string `bson:"name" json:"name"` + Description string `bson:"description" json:"description"` + Period _struct.Period `bson:"period" json:"period"` + CreatedAt string `bson:"createdAt" json:"createdAt"` + UpdatedAt string `bson:"updatedAt" json:"updatedAt"` +} + +type Disability struct { + ResourceType string `json:"resourceType" bson:"resourceType,omitempty" ` + ID primitive.ObjectID `bson:"_id,omitempty" json:"id" ` + Identifier []_struct.Identifier `bson:"identifier" json:"identifier"` + Status string `bson:"status" json:"status"` + Name string `bson:"name" json:"name"` + Description string `bson:"description" json:"description"` + Period _struct.Period `bson:"period" json:"period"` + CreatedAt string `bson:"createdAt" json:"createdAt"` + UpdatedAt string `bson:"updatedAt" json:"updatedAt"` +} + +type Education struct { + ResourceType string `json:"resourceType" bson:"resourceType,omitempty" ` + ID primitive.ObjectID `bson:"_id,omitempty" json:"id" ` + Identifier []_struct.Identifier `bson:"identifier" json:"identifier"` + Status string `bson:"status" json:"status"` + Name string `bson:"name" json:"name"` + Description string `bson:"description" json:"description"` + Period _struct.Period `bson:"period" json:"period"` + CreatedAt string `bson:"createdAt" json:"createdAt"` + UpdatedAt string `bson:"updatedAt" json:"updatedAt"` +} + +type Job struct { + ResourceType string `json:"resourceType" bson:"resourceType,omitempty" ` + ID primitive.ObjectID `bson:"_id,omitempty" json:"id" ` + Identifier []_struct.Identifier `bson:"identifier" json:"identifier"` + Status string `bson:"status" json:"status"` + Name string `bson:"name" json:"name"` + Description string `bson:"description" json:"description"` + Period _struct.Period `bson:"period" json:"period"` + CreatedAt string `bson:"createdAt" json:"createdAt"` + UpdatedAt string `bson:"updatedAt" json:"updatedAt"` +} + +type MartialStatus struct { + ResourceType string `json:"resourceType" bson:"resourceType,omitempty" ` + ID primitive.ObjectID `bson:"_id,omitempty" json:"id" ` + Identifier []_struct.Identifier `bson:"identifier" json:"identifier"` + Status string `bson:"status" json:"status"` + Name string `bson:"name" json:"name"` + Description string `bson:"description" json:"description"` + Period _struct.Period `bson:"period" json:"period"` + CreatedAt string `bson:"createdAt" json:"createdAt"` + UpdatedAt string `bson:"updatedAt" json:"updatedAt"` +} + +type Religion struct { + ResourceType string `json:"resourceType" bson:"resourceType,omitempty" ` + ID primitive.ObjectID `bson:"_id,omitempty" json:"id" ` + Identifier []_struct.Identifier `bson:"identifier" json:"identifier"` + Status string `bson:"status" json:"status"` + Name string `bson:"name" json:"name"` + Description string `bson:"description" json:"description"` + Period _struct.Period `bson:"period" json:"period"` + CreatedAt string `bson:"createdAt" json:"createdAt"` + UpdatedAt string `bson:"updatedAt" json:"updatedAt"` +} + +type Tribe struct { + ResourceType string `json:"resourceType" bson:"resourceType,omitempty" ` + ID primitive.ObjectID `bson:"_id,omitempty" json:"id" ` + Identifier []_struct.Identifier `bson:"identifier" json:"identifier"` + Status string `bson:"status" json:"status"` + Name string `bson:"name" json:"name"` + Description string `bson:"description" json:"description"` + Period _struct.Period `bson:"period" json:"period"` + CreatedAt string `bson:"createdAt" json:"createdAt"` + UpdatedAt string `bson:"updatedAt" json:"updatedAt"` +} diff --git a/pkg/models/simrs/icd.go b/pkg/models/simrs/icd.go new file mode 100644 index 0000000..a24bf83 --- /dev/null +++ b/pkg/models/simrs/icd.go @@ -0,0 +1,8 @@ +package simrs + +type Icd10 struct { + IDIcd string `gorm:"column:id_idicd" json:"id_icd"` + NamaIcd string `gorm:"column:nm_icd" json:"nama_icd"` + DesJenisPenyakit string `gorm:"column:des_deskripsijenispenyakit" json:"des_jenis_penyakit"` + PenyebabPenyakit string `gorm:"column:com_penyebabpenyakit" json:"penyebab_penyakit"` +} diff --git a/pkg/models/simrs/location.go b/pkg/models/simrs/location.go new file mode 100644 index 0000000..33e3286 --- /dev/null +++ b/pkg/models/simrs/location.go @@ -0,0 +1,15 @@ +package simrs + +type Location struct { + IDRuang string `gorm:"column:id_idruang" json:"id_ruang"` + Kdruang string `gorm:"column:id_kdruang" json:"kd_ruang"` + Kdunit string `gorm:"column:id_kdunit" json:"kd_unit"` + Status string `gorm:"column:st_status" json:"status"` + NamaRuang string `gorm:"column:nm_namaruang" json:"nama_ruang"` + DesRuang string `gorm:"column:des_keterangan" json:"des_ruang"` + Kelas string `gorm:"column:tp_kelas" json:"kelas"` + KelompokRuang string `gorm:"column:tp_kelompokruang" json:"kelompong_ruang"` + Typeruang string `gorm:"column:tp_typeruang" json:"typeruang"` + Subsistem string `gorm:"column:tp_subsistem" json:"subsistem"` + Partial string `gorm:"column:tp_partial" json:"partial"` +} diff --git a/pkg/models/simrs/practitioner.go b/pkg/models/simrs/practitioner.go new file mode 100644 index 0000000..5ce1af8 --- /dev/null +++ b/pkg/models/simrs/practitioner.go @@ -0,0 +1,32 @@ +package simrs + +type Practitionerdoktersimrs struct { + IDDokter string `gorm:"column:id_kddokter" json:"kd_dokter"` + KDPoly string `gorm:"column:id_kdpoly" json:"kdpoly"` + NIP string `gorm:"column:id_kodedpjp" json:"kodedpjp"` + Aktif string `gorm:"column:st_aktif" json:"aktif"` + NamaDokter string `gorm:"column:nm_namadokter" json:"nama_dokter"` + NomorHP string `gorm:"column:te_nomorhp" json:"nomor_hp"` + Email string `gorm:"column:te_email" json:"email"` + QuSIP string `gorm:"column:qu_sip" json:"qu_sip"` + QuSPK string `gorm:"column:qu_spk" json:"qu_spk"` + SMF string `gorm:"column:EX_smf" json:"smf"` + Kategori string `gorm:"column:ex_kategori" json:"kategori"` +} + +type Practitionerperawatsimrs struct { + IDPerawat string `gorm:"column:id_perawat" json:"id_perawat"` + NIPPer string `gorm:"column:id_nip" json:"ni["` + Noktp string `gorm:"column:id_noktp" json:"id_noktp"` + Status string `gorm:"column:st_status" json:"status"` + NamaPerawat string `gorm:"column:nm_nama" json:"nama_perawat"` + Telepon string `gorm:"column:te_telpon" json:"telepon"` + JenisKelamain string `gorm:"column:ge_jeniskelamain" json:"jenis_kelamain"` + Tgllahir string `gorm:"column:bir_tgllahir" json:"tgllahir"` + Alamat string `gorm:"column:ad_alamat" json:"alamat"` + Kelurahan string `gorm:"column:ad_kelurahan" json:"kelurahan"` + Kecamatan string `gorm:"column:ad_kecamatan" json:"kecamatan"` + Kota string `gorm:"column:ad_kota" json:"kota"` + Provinsi string `gorm:"column:provinsi" json:"provinsi"` + Tempatlahir string `gorm:"column:ex_tempatlahir" json:"tempatlahir"` +} diff --git a/pkg/models/struct/fhir.go b/pkg/models/struct/fhir.go index 1fa678e..f7e5649 100644 --- a/pkg/models/struct/fhir.go +++ b/pkg/models/struct/fhir.go @@ -109,7 +109,7 @@ type Contact struct { type Communication struct { Language CodeableConcept `json:"language,omitempty" bson:"language"` - Text string `json:"preferred,omitempty" bson:"preferred"` + Text string `json:"text,omitempty" bson:"text"` } type Link struct { @@ -133,6 +133,7 @@ type ExtendedContactDetail struct { type Purpose struct { Purpose CodeableConcept `json:"purpose" bson:"purpose"` + Coding []Coding `json:"coding" bson:"coding"` } type Reason struct { @@ -199,7 +200,7 @@ type VirtualService struct { AddressContactPoint ContactPoint `json:"addressContactPoint,omitempty" bson:"addressContactPoint,omitempty"` AddressExtendedContact ExtendedContactDetail `json:"addressExtendedContact,omitempty" bson:"addressExtendedContact,omitempty"` AdditionalInfo []string `json:"additionalInfo,omitempty" bson:"additionalInfo,omitempty"` - MaxParticipants string `json:"maxParticipants,omitempty" bson:"maxParticipants,omitempty"` + MaxParticipants int `json:"maxParticipants,omitempty" bson:"maxParticipants,omitempty"` SessionKey string `json:"sessionKey,omitempty" bson:"sessionKey,omitempty"` } @@ -207,3 +208,56 @@ type Payload struct { Type CodeableConcept `json:"type,omitempty" bson:"type,omitempty"` Mimetype []string `json:"mimetype,omitempty" bson:"mimetype,omitempty"` } + +type Note struct { + Author Author `json:"author" bson:"author"` + Time string `json:"time" bson:"time"` + Text string `json:"text" bson:"text"` +} + +type Author struct { + AuthorReference Reference `json:"authorReference" bson:"authorReference"` + AuthorString string `json:"authorString" bson:"authorString"` +} + +type Concept struct { + Concept CodeableConcept `json:"concept" bson:"concept"` + Reference Reference `json:"reference" bson:"reference"` +} + +type Participant struct { + Type []CodeableConcept `json:"type" bson:"type"` + Period Period `json:"period" bson:"period"` + Actor Reference `json:"actor" bson:"actor"` + Required bool `json:"required" bson:"required"` + Status string `json:"status" bson:"status"` +} + +type RecurrenceTemple struct { + Timezone CodeableConcept `json:"timezone" bson:"timezone"` + RecurrenceType CodeableConcept `json:"recurrenceType" bson:"recurrenceType"` + LastOccurrenceDate string `json:"lastOccurrenceDate" bson:"lastOccurrenceDate"` + OccurenceCount int `json:"occurenceCount" bson:"occurenceCount"` + OccurenceDate []string `json:"occurenceDate" bson:"occurenceDate"` +} + +type WeeklyTemple struct { + Monday bool `json:"monday" bson:"monday"` + Tuesday bool `json:"tuesday" bson:"tuesday"` + Wednesday bool `json:"wednesday" bson:"wednesday"` + Thursday bool `json:"thursday" bson:"thursday"` + Friday bool `json:"friday" bson:"friday"` + Saturday bool `json:"saturday" bson:"saturday"` + Sunday bool `json:"sunday" bson:"sunday"` +} + +type MonthlyTemple struct { + DayOfmonth bool `json:"dayOfmonth" bson:"dayOfmonth"` + NthWeekOfMonth Coding `json:"nthWeekOfMonth" bson:"nthWeekOfMonth"` + DayOfWeek Coding `json:"dayOfWeek" bson:"dayOfWeek"` + MonthInterval int `json:"monthInterval" bson:"monthInterval"` +} + +type YearlyTemple struct { + YearInterval int `json:"yearInterval" bson:"yearInterval"` +}