udpate insert patient
This commit is contained in:
@@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -20,6 +21,7 @@ type Server struct {
|
|||||||
|
|
||||||
func NewServer() *http.Server {
|
func NewServer() *http.Server {
|
||||||
port, _ := strconv.Atoi(os.Getenv("PORT"))
|
port, _ := strconv.Atoi(os.Getenv("PORT"))
|
||||||
|
log.Println("PORT: ", port)
|
||||||
master := os.Getenv("BLUEPRINT_DB_MASTER")
|
master := os.Getenv("BLUEPRINT_DB_MASTER")
|
||||||
NewServer := &Server{
|
NewServer := &Server{
|
||||||
port: port,
|
port: port,
|
||||||
|
|||||||
@@ -11,15 +11,7 @@ import (
|
|||||||
func (s *DatabaseService) InsertPatient(req *patient.Patient) error {
|
func (s *DatabaseService) InsertPatient(req *patient.Patient) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_, err := s.DB.Collection("patient").InsertOne(ctx, patient.Patient{
|
_, err := s.DB.Collection("patient").InsertOne(ctx, req)
|
||||||
ID: req.ID,
|
|
||||||
NoRM: req.NoRM,
|
|
||||||
Name: req.Name,
|
|
||||||
Telecom: req.Telecom,
|
|
||||||
Gender: req.Gender,
|
|
||||||
BirthDate: req.BirthDate,
|
|
||||||
Address: req.Address,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package patient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"template_blueprint/internal/database"
|
"template_blueprint/internal/database"
|
||||||
"template_blueprint/pkg/database/mongo"
|
"template_blueprint/pkg/database/mongo"
|
||||||
"template_blueprint/pkg/models/patient"
|
"template_blueprint/pkg/models/patient"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InsertPatient(c *gin.Context) {
|
func InsertPatient(c *gin.Context) {
|
||||||
@@ -18,14 +18,18 @@ func InsertPatient(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
mongoDB := mongo.NewDatabaseService(db)
|
mongoDB := mongo.NewDatabaseService(db)
|
||||||
var reqInsert *patient.Patient
|
var req *patient.Patient
|
||||||
err := c.Bind(&reqInsert)
|
err := c.Bind(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reqInsert.ID = uuid.New().String()
|
|
||||||
errInsert := mongoDB.InsertPatient(reqInsert)
|
dateCreated := time.Now().Format("2006-01-02 15:04:05")
|
||||||
|
req.ResourceType = "Patient"
|
||||||
|
req.CreatedAt = dateCreated
|
||||||
|
|
||||||
|
errInsert := mongoDB.InsertPatient(req)
|
||||||
if errInsert != nil {
|
if errInsert != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"message": errInsert.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"message": errInsert.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,11 +1,167 @@
|
|||||||
package patient
|
package patient
|
||||||
|
|
||||||
type Patient struct {
|
type Coding struct {
|
||||||
ID string `bson:"_id"`
|
System string `bson:"system,omitempty"`
|
||||||
NoRM string `bson:"norm"`
|
Version string `bson:"version,omitempty"`
|
||||||
Name string `bson:"name"`
|
Code string `bson:"code,omitempty"`
|
||||||
Telecom string `bson:"telecom"`
|
Display string `bson:"display,omitempty"`
|
||||||
Gender string `bson:"gender"`
|
UserSelected bool `bson:"userSelected,omitempty"`
|
||||||
BirthDate string `bson:"birthDate"`
|
}
|
||||||
Address string `bson:"address"`
|
|
||||||
|
type Identifier struct {
|
||||||
|
Use string `bson:"use,omitempty"`
|
||||||
|
Type CodeableConcept `bson:"type,omitempty"`
|
||||||
|
System string `bson:"system,omitempty"`
|
||||||
|
Value string `bson:"value,omitempty"`
|
||||||
|
Period Period `bson:"period,omitempty"`
|
||||||
|
Assigner struct{} `bson:"assigner,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CodeableConcept struct {
|
||||||
|
Coding []Coding `bson:"coding,omitempty"`
|
||||||
|
Text string `bson:"text,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Period struct {
|
||||||
|
Start string `bson:"start,omitempty"`
|
||||||
|
End string `bson:"end,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContactPoint struct {
|
||||||
|
System string `bson:"system,omitempty"`
|
||||||
|
Value string `bson:"value,omitempty"`
|
||||||
|
Use string `bson:"use,omitempty"`
|
||||||
|
Rank int `bson:"rank,omitempty"`
|
||||||
|
Period Period `bson:"period,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HumanName struct {
|
||||||
|
Use string `bson:"use,omitempty"`
|
||||||
|
Text string `bson:"text,omitempty"`
|
||||||
|
Family string `bson:"family,omitempty"`
|
||||||
|
Given []string `bson:"given,omitempty"`
|
||||||
|
Prefix []string `bson:"prefix,omitempty"`
|
||||||
|
Suffix []string `bson:"suffix,omitempty"`
|
||||||
|
Period Period `bson:"period,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Address struct {
|
||||||
|
Use string `bson:"use,omitempty"`
|
||||||
|
Type string `bson:"type,omitempty"`
|
||||||
|
Text string `bson:"text,omitempty"`
|
||||||
|
Line []string `bson:"line,omitempty"`
|
||||||
|
City string `bson:"city,omitempty"`
|
||||||
|
District string `bson:"district,omitempty"`
|
||||||
|
State string `bson:"state,omitempty"`
|
||||||
|
PostalCode string `bson:"postalCode,omitempty"`
|
||||||
|
Country string `bson:"country,omitempty"`
|
||||||
|
Period Period `bson:"period,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Organization struct {
|
||||||
|
Reference string `bson:"reference,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Contact struct {
|
||||||
|
Relationship []CodeableConcept `bson:"relationship,omitempty"`
|
||||||
|
Name []HumanName `bson:"name,omitempty"`
|
||||||
|
Telecom []ContactPoint `bson:"telecom,omitempty"`
|
||||||
|
Address Address `bson:"address,omitempty"`
|
||||||
|
Organization Organization `bson:"organization,omitempty"`
|
||||||
|
Gender string `bson:"gender,omitempty"`
|
||||||
|
Period Period `bson:"period,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Communication struct {
|
||||||
|
Language CodeableConcept `bson:"language,omitempty"`
|
||||||
|
Preferred bool `bson:"preferred,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReqInsertCommunication struct {
|
||||||
|
Language Coding `bson:"language,omitempty"`
|
||||||
|
Preferred bool `bson:"preferred,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Link struct {
|
||||||
|
RelatePerson []RelatePerson `bson:"relatePerson,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RelatePerson struct {
|
||||||
|
Identifier []Identifier `bson:"identifier,omitempty"`
|
||||||
|
Active bool `bson:"active"`
|
||||||
|
Patient string `bson:"patient"`
|
||||||
|
Relationship CodeableConcept `bson:"relationship"`
|
||||||
|
Name []HumanName `bson:"name,omitempty"`
|
||||||
|
Telecom []ContactPoint `bson:"telecom,omitempty"`
|
||||||
|
Gender string `bson:"gender,omitempty"`
|
||||||
|
BirthDate string `bson:"birthDate,omitempty"`
|
||||||
|
Address []Address `bson:"address,omitempty"`
|
||||||
|
Photo string `bson:"photo,omitempty"`
|
||||||
|
Period Period `bson:"period,omitempty"`
|
||||||
|
Communication []Communication `bson:"communication,omitempty"`
|
||||||
|
Preferred bool `bson:"preferred"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Deceased struct {
|
||||||
|
DeceasedBoolean bool `bson:"deceasedBoolean,omitempty"`
|
||||||
|
DeceasedDateTime string `bson:"deceasedDateTime,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MultipleBirth struct {
|
||||||
|
MultipleBirthBoolean bool `bson:"multipleBirthBoolean,omitempty"`
|
||||||
|
MultipleBirthInteger int `bson:"multipleBirthInteger,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Patient struct {
|
||||||
|
ResourceType string `bson:"resourceType"`
|
||||||
|
ID string `bson:"_id"`
|
||||||
|
Identifier []Identifier `bson:"identifier,omitempty"`
|
||||||
|
Active bool `bson:"active"`
|
||||||
|
Name []HumanName `bson:"name,omitempty"`
|
||||||
|
Telecom []ContactPoint `bson:"telecom,omitempty"`
|
||||||
|
Gender string `bson:"gender,omitempty"`
|
||||||
|
BirthPlace string `bson:"birthPlace,omitempty"`
|
||||||
|
BirthDate string `bson:"birthDate,omitempty"`
|
||||||
|
Address []Address `bson:"address,omitempty"`
|
||||||
|
MaritalStatus CodeableConcept `bson:"maritalStatus,omitempty"`
|
||||||
|
Job CodeableConcept `bson:"job,omitempty"`
|
||||||
|
Religion CodeableConcept `bson:"religion,omitempty"`
|
||||||
|
Tribe CodeableConcept `bson:"tribe,omitempty"`
|
||||||
|
Link Link `bson:"link,omitempty"`
|
||||||
|
Communication []Communication `bson:"communication,omitempty"`
|
||||||
|
Disability bool `bson:"disability,omitempty"`
|
||||||
|
National string `bson:"national,omitempty"`
|
||||||
|
Deceased Deceased `bson:"deceased,omitempty"`
|
||||||
|
MultipleBirth MultipleBirth `bson:"multipleBirth,omitempty"`
|
||||||
|
CreatedAt string `bson:"createdAt"`
|
||||||
|
UpdatedAt string `bson:"updatedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReqInsertIdentifier struct {
|
||||||
|
Use string `bson:"use,omitempty"`
|
||||||
|
Type Coding `bson:"type,omitempty"`
|
||||||
|
System string `bson:"system,omitempty"`
|
||||||
|
Value string `bson:"value,omitempty"`
|
||||||
|
Period Period `bson:"period,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReqInsertPatient struct {
|
||||||
|
Identifier []ReqInsertIdentifier `bson:"identifier,omitempty"`
|
||||||
|
Active bool `bson:"active"`
|
||||||
|
Name []HumanName `bson:"name,omitempty"`
|
||||||
|
Telecom []ContactPoint `bson:"telecom,omitempty"`
|
||||||
|
Gender string `bson:"gender,omitempty"`
|
||||||
|
BirthPlace string `bson:"birthPlace,omitempty"`
|
||||||
|
BirthDate string `bson:"birthDate,omitempty"`
|
||||||
|
Address []Address `bson:"address,omitempty"`
|
||||||
|
MaritalStatus []CodeableConcept `bson:"maritalStatus,omitempty"`
|
||||||
|
Job []CodeableConcept `bson:"job,omitempty"`
|
||||||
|
Religion []CodeableConcept `bson:"religion,omitempty"`
|
||||||
|
Tribe []CodeableConcept `bson:"tribe,omitempty"`
|
||||||
|
Link Link `bson:"link,omitempty"`
|
||||||
|
Communication []Communication `bson:"communication,omitempty"`
|
||||||
|
Disability bool `bson:"disability,omitempty"`
|
||||||
|
National string `bson:"national,omitempty"`
|
||||||
|
Deceased Deceased `bson:"deceased,omitempty"`
|
||||||
|
MultipleBirth MultipleBirth `bson:"multipleBirth,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user