pembaruhan baru

This commit is contained in:
2025-05-14 09:44:08 +07:00
parent dc0b822440
commit 1fb1caaf19
20 changed files with 1964 additions and 671 deletions

No files matched your search

+499 -399
View File
@@ -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),
})
}