409 lines
9.8 KiB
Go
409 lines
9.8 KiB
Go
package address
|
|
|
|
import (
|
|
"api-poliklinik/internal/database"
|
|
"api-poliklinik/pkg/database/mongo"
|
|
connDatabase "api-poliklinik/pkg/database/satu_data"
|
|
mongomaster "api-poliklinik/pkg/models/mongo/master/masteraddress"
|
|
_struct "api-poliklinik/pkg/models/struct"
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func Migrasiprovinsi(c *gin.Context) {
|
|
db := database.New().GetDB("simrs")
|
|
simrs := connDatabase.NewDatabaseService(db)
|
|
|
|
dataProvinsi := simrs.Getprovinsi()
|
|
if dataProvinsi == nil || len(dataProvinsi) == 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 _, provinsi := range dataProvinsi {
|
|
dateCreated := time.Now().Format("2006-01-02 15:04:05")
|
|
objectID := primitive.NewObjectID()
|
|
var fhirProvinsi = mongomaster.State{
|
|
ResourceType: "State",
|
|
ID: objectID,
|
|
}
|
|
// Mengisi properti Identifier
|
|
fhirProvinsi.Identifier = []_struct.Identifier{
|
|
{
|
|
Use: "usual",
|
|
System: "",
|
|
Value: provinsi.IDProvinsi,
|
|
Type: _struct.CodeableConcept{
|
|
Coding: []_struct.Coding{
|
|
{
|
|
System: "",
|
|
Version: "",
|
|
Code: "idprovinsi",
|
|
Display: "ID m_provinsi Simrs 3.0",
|
|
UserSelected: true,
|
|
},
|
|
},
|
|
Text: "ID m_provinsi Simrs 3.0",
|
|
},
|
|
Period: _struct.Period{
|
|
Start: "",
|
|
End: "",
|
|
},
|
|
Assigner: _struct.Reference{
|
|
Reference: "",
|
|
Display: "",
|
|
},
|
|
},
|
|
}
|
|
|
|
fhirProvinsi.Status = "active"
|
|
fhirProvinsi.Name = provinsi.NamaProvinsi
|
|
fhirProvinsi.Period = _struct.Period{
|
|
Start: "",
|
|
End: "",
|
|
}
|
|
fhirProvinsi.CreatedAt = dateCreated
|
|
fhirProvinsi.UpdatedAt = dateCreated
|
|
|
|
err := mongoDB.InsertState(fhirProvinsi)
|
|
|
|
if err != nil {
|
|
log.Printf("Gagal migrasi data praktisi %s: %v", provinsi.IDProvinsi, err)
|
|
failedCount++
|
|
continue
|
|
}
|
|
|
|
migratedIDs = append(migratedIDs, objectID.Hex())
|
|
migratedCount++
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "success",
|
|
"message": "Migrasi data provinsi ke FHIR berhasil",
|
|
"total": len(dataProvinsi),
|
|
"migrated": migratedCount,
|
|
"failed": failedCount,
|
|
"migrated_ids": migratedIDs,
|
|
"timestamp": time.Now().Format(time.RFC3339),
|
|
})
|
|
}
|
|
|
|
func Migrasikota(c *gin.Context) {
|
|
db := database.New().GetDB("simrs")
|
|
simrs := connDatabase.NewDatabaseService(db)
|
|
|
|
dataKota := simrs.Getkota()
|
|
if dataKota == nil || len(dataKota) == 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 _, kota := range dataKota {
|
|
dateCreated := time.Now().Format("2006-01-02 15:04:05")
|
|
objectID := primitive.NewObjectID()
|
|
var fhirkota = mongomaster.City{
|
|
ResourceType: "City",
|
|
ID: objectID,
|
|
}
|
|
fhirkota.Identifier = []_struct.Identifier{
|
|
{
|
|
Use: "usual",
|
|
System: "",
|
|
Value: kota.IDKota,
|
|
Type: _struct.CodeableConcept{
|
|
Coding: []_struct.Coding{
|
|
{
|
|
System: "",
|
|
Version: "",
|
|
Code: "idkota",
|
|
Display: "ID m_kota Simrs 3.0",
|
|
UserSelected: true,
|
|
},
|
|
},
|
|
Text: "ID m_kota Simrs 3.0",
|
|
},
|
|
Period: _struct.Period{
|
|
Start: "",
|
|
End: "",
|
|
},
|
|
Assigner: _struct.Reference{
|
|
Reference: "",
|
|
Display: "",
|
|
},
|
|
},
|
|
}
|
|
|
|
fhirkota.Status = "active"
|
|
fhirkota.Name = kota.NamaKota
|
|
fhirkota.State = _struct.Reference{
|
|
Reference: "Provinsi/" + kota.IDProvinsi,
|
|
Display: kota.NamaProvinsi,
|
|
}
|
|
fhirkota.Period = _struct.Period{
|
|
Start: "",
|
|
End: "",
|
|
}
|
|
fhirkota.CreatedAt = dateCreated
|
|
fhirkota.UpdatedAt = dateCreated
|
|
|
|
err := mongoDB.InsertCity(fhirkota)
|
|
|
|
if err != nil {
|
|
log.Printf("Gagal migrasi data kora %s: %v", kota.IDKota, err)
|
|
failedCount++
|
|
continue
|
|
}
|
|
|
|
migratedIDs = append(migratedIDs, objectID.Hex())
|
|
migratedCount++
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "success",
|
|
"message": "Migrasi data kota ke FHIR berhasil",
|
|
"total": len(dataKota),
|
|
"migrated": migratedCount,
|
|
"failed": failedCount,
|
|
"migrated_ids": migratedIDs,
|
|
"timestamp": time.Now().Format(time.RFC3339),
|
|
})
|
|
}
|
|
|
|
func Migrasikecamatan(c *gin.Context) {
|
|
db := database.New().GetDB("simrs")
|
|
simrs := connDatabase.NewDatabaseService(db)
|
|
|
|
dataKecamatan := simrs.Getkecamatan()
|
|
if dataKecamatan == nil || len(dataKecamatan) == 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 _, kecamatan := range dataKecamatan {
|
|
dateCreated := time.Now().Format("2006-01-02 15:04:05")
|
|
objectID := primitive.NewObjectID()
|
|
var fhirkecamatan = mongomaster.District{
|
|
ResourceType: "District",
|
|
ID: objectID,
|
|
}
|
|
fhirkecamatan.Identifier = []_struct.Identifier{
|
|
{
|
|
Use: "usual",
|
|
System: "",
|
|
Value: kecamatan.IDKecamatan,
|
|
Type: _struct.CodeableConcept{
|
|
Coding: []_struct.Coding{
|
|
{
|
|
System: "",
|
|
Version: "",
|
|
Code: "idkecamatan",
|
|
Display: "ID m_kecamatan Simrs 3.0",
|
|
UserSelected: true,
|
|
},
|
|
},
|
|
Text: "ID m_kecamatan Simrs 3.0",
|
|
},
|
|
Period: _struct.Period{
|
|
Start: "",
|
|
End: "",
|
|
},
|
|
Assigner: _struct.Reference{
|
|
Reference: "",
|
|
Display: "",
|
|
},
|
|
},
|
|
}
|
|
|
|
fhirkecamatan.Status = "active"
|
|
fhirkecamatan.Name = kecamatan.NamaKecamatan
|
|
fhirkecamatan.City = _struct.Reference{
|
|
Reference: "City/" + kecamatan.IDKota,
|
|
Display: kecamatan.NamaKota,
|
|
}
|
|
fhirkecamatan.Period = _struct.Period{
|
|
Start: "",
|
|
End: "",
|
|
}
|
|
fhirkecamatan.CreatedAt = dateCreated
|
|
fhirkecamatan.UpdatedAt = dateCreated
|
|
|
|
err := mongoDB.InsertDistrict(fhirkecamatan)
|
|
|
|
if err != nil {
|
|
log.Printf("Gagal migrasi data kora %s: %v", kecamatan.IDKecamatan, err)
|
|
failedCount++
|
|
continue
|
|
}
|
|
|
|
migratedIDs = append(migratedIDs, objectID.Hex())
|
|
migratedCount++
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "success",
|
|
"message": "Migrasi data kecamatan ke FHIR berhasil",
|
|
"total": len(dataKecamatan),
|
|
"migrated": migratedCount,
|
|
"failed": failedCount,
|
|
"migrated_ids": migratedIDs,
|
|
"timestamp": time.Now().Format(time.RFC3339),
|
|
})
|
|
}
|
|
|
|
func Migrasikelurahan(c *gin.Context) {
|
|
db := database.New().GetDB("simrs")
|
|
simrs := connDatabase.NewDatabaseService(db)
|
|
|
|
dataKelurahan := simrs.Getkelurahan()
|
|
if dataKelurahan == nil || len(dataKelurahan) == 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 _, kelurahan := range dataKelurahan {
|
|
dateCreated := time.Now().Format("2006-01-02 15:04:05")
|
|
objectID := primitive.NewObjectID()
|
|
var fhirkelurahan = mongomaster.Village{
|
|
ResourceType: "Village",
|
|
ID: objectID,
|
|
}
|
|
fhirkelurahan.Identifier = []_struct.Identifier{
|
|
{
|
|
Use: "usual",
|
|
System: "",
|
|
Value: kelurahan.IDKelurahan,
|
|
Type: _struct.CodeableConcept{
|
|
Coding: []_struct.Coding{
|
|
{
|
|
System: "",
|
|
Version: "",
|
|
Code: "idkelurahan",
|
|
Display: "ID m_kelurahan Simrs 3.0",
|
|
UserSelected: true,
|
|
},
|
|
},
|
|
Text: "ID m_kelurahan Simrs 3.0",
|
|
},
|
|
Period: _struct.Period{
|
|
Start: "",
|
|
End: "",
|
|
},
|
|
Assigner: _struct.Reference{
|
|
Reference: "",
|
|
Display: "",
|
|
},
|
|
},
|
|
}
|
|
|
|
fhirkelurahan.Status = "active"
|
|
fhirkelurahan.Name = kelurahan.NamaKelurahan
|
|
fhirkelurahan.District = _struct.Reference{
|
|
Reference: "Distric/" + kelurahan.IDKecamatan,
|
|
Display: kelurahan.NamaKecamatan,
|
|
}
|
|
fhirkelurahan.Period = _struct.Period{
|
|
Start: "",
|
|
End: "",
|
|
}
|
|
fhirkelurahan.CreatedAt = dateCreated
|
|
fhirkelurahan.UpdatedAt = dateCreated
|
|
|
|
err := mongoDB.InsertVillage(fhirkelurahan)
|
|
|
|
if err != nil {
|
|
log.Printf("Gagal migrasi data kelurahan %s: %v", kelurahan.IDKelurahan, err)
|
|
failedCount++
|
|
continue
|
|
}
|
|
|
|
migratedIDs = append(migratedIDs, objectID.Hex())
|
|
migratedCount++
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "success",
|
|
"message": "Migrasi data kelurahan ke FHIR berhasil",
|
|
"total": len(dataKelurahan),
|
|
"migrated": migratedCount,
|
|
"failed": failedCount,
|
|
"migrated_ids": migratedIDs,
|
|
"timestamp": time.Now().Format(time.RFC3339),
|
|
})
|
|
}
|