105 lines
3.4 KiB
Go
105 lines
3.4 KiB
Go
package management
|
||
|
||
import (
|
||
"encoding/json"
|
||
"fmt"
|
||
"nCovTrack-Backend/global"
|
||
"nCovTrack-Backend/models"
|
||
"nCovTrack-Backend/utils"
|
||
"strings"
|
||
"time"
|
||
)
|
||
|
||
func fakerGetRequest(uri string) string {
|
||
resStr := utils.GetWhioutHeader(global.FACKER_HOST + uri)
|
||
var res utils.GinResponse
|
||
_ = json.Unmarshal([]byte(resStr), &res)
|
||
dataStr, _ := json.Marshal(res.Data)
|
||
return string(dataStr)
|
||
}
|
||
|
||
func queryHotelContacts(identification string) []models.HotelContactRequest {
|
||
dataStr := fakerGetRequest("query/contacts/hotel/" + identification)
|
||
var data []models.HotelContactRequest
|
||
err := json.Unmarshal([]byte(dataStr), &data)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
return data
|
||
}
|
||
|
||
func queryRailwayContacts(identification string) []models.RailwayContactRequest {
|
||
dataStr := fakerGetRequest("query/contacts/railway/" + identification)
|
||
var data []models.RailwayContactRequest
|
||
err := json.Unmarshal([]byte(dataStr), &data)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
return data
|
||
}
|
||
|
||
func queryPatients(identification string) []models.PatientRequest {
|
||
dataStr := fakerGetRequest("query/contacts/railway/" + identification)
|
||
var data []models.PatientRequest
|
||
err := json.Unmarshal([]byte(dataStr), &data)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
return data
|
||
}
|
||
|
||
func queryContacts(identification string) []models.BackObservation {
|
||
hotelContacts := queryHotelContacts(identification)
|
||
railwayContacts := queryRailwayContacts(identification)
|
||
observations := append(fakerContacts2Observations(hotelContacts), fakerContacts2Observations(railwayContacts)...)
|
||
return observations
|
||
}
|
||
|
||
func splitFakerAddress(fakerAddress string) string {
|
||
addresses := strings.Split(fakerAddress, " ")
|
||
return addresses[1] + " " + addresses[2]
|
||
}
|
||
|
||
func fakerContacts2Observations(contacts any) []models.BackObservation {
|
||
var observations []models.BackObservation
|
||
switch contacts.(type) {
|
||
case []models.HotelContactRequest:
|
||
for _, contact := range contacts.([]models.HotelContactRequest) {
|
||
tranjectory := fmt.Sprintf("在%s-%s期间,与患者同期留宿%s", contact.InData.String(), contact.OutData.String(), contact.HotelName)
|
||
observation := &models.BackObservation{
|
||
Name: contact.Name,
|
||
Age: contact.Age,
|
||
Sex: contact.Sex,
|
||
Phone: contact.Phone,
|
||
Identification: contact.Identification,
|
||
Region: splitFakerAddress(contact.Address),
|
||
Address: "",
|
||
HealthSituation: global.HEALTH_SITUATION_ID_MAP["CONTACT"],
|
||
HealthChangeTime: time.Now(),
|
||
MeasureSituation: global.MEASURE_SITUATION_ID_MAP["NOMEASURE"],
|
||
Trajectory: tranjectory,
|
||
}
|
||
observations = append(observations, *observation)
|
||
}
|
||
case []models.RailwayContactRequest:
|
||
for _, contact := range contacts.([]models.RailwayContactRequest) {
|
||
tranjectory := fmt.Sprintf("在%s,与患者同期乘坐%s", contact.Launch.String(), contact.Train)
|
||
observation := &models.BackObservation{
|
||
Name: contact.Name,
|
||
Age: contact.Age,
|
||
Sex: contact.Sex,
|
||
Phone: contact.Phone,
|
||
Identification: contact.Identification,
|
||
Region: splitFakerAddress(contact.Address),
|
||
Address: "",
|
||
HealthSituation: global.HEALTH_SITUATION_ID_MAP["CONTACT"],
|
||
HealthChangeTime: time.Now(),
|
||
MeasureSituation: global.MEASURE_SITUATION_ID_MAP["NOMEASURE"],
|
||
Trajectory: tranjectory,
|
||
}
|
||
observations = append(observations, *observation)
|
||
}
|
||
}
|
||
return observations
|
||
}
|