From 4c0d3c831d331966c98bd143608112d89a57e653 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Tue, 30 Aug 2022 19:35:01 -0700 Subject: [PATCH] working on Gorm Serialization of structs. --- backend/pkg/database/interface.go | 6 ++- .../hub/internal/fhir/base/fhir430_client.go | 8 ++-- backend/pkg/hub/internal/fhir/cigna/client.go | 4 +- backend/pkg/models/patient_profile.go | 46 ------------------- 4 files changed, 10 insertions(+), 54 deletions(-) delete mode 100644 backend/pkg/models/patient_profile.go diff --git a/backend/pkg/database/interface.go b/backend/pkg/database/interface.go index 81a5c8ca..efbb7c24 100644 --- a/backend/pkg/database/interface.go +++ b/backend/pkg/database/interface.go @@ -9,6 +9,8 @@ type DatabaseRepository interface { Close() error GetCurrentUser() models.User - CreateProviderCredentials(ctx context.Context, providerCreds *models.ProviderCredential) error - GetProviderCredentials(ctx context.Context) ([]models.ProviderCredential, error) + UpsertProfile(ctx context.Context, profile models.Profile) error + + CreateSource(ctx context.Context, providerCreds *models.Source) error + GetSources(ctx context.Context) ([]models.Source, error) } diff --git a/backend/pkg/hub/internal/fhir/base/fhir430_client.go b/backend/pkg/hub/internal/fhir/base/fhir430_client.go index b7650ad1..23d619f2 100644 --- a/backend/pkg/hub/internal/fhir/base/fhir430_client.go +++ b/backend/pkg/hub/internal/fhir/base/fhir430_client.go @@ -10,12 +10,12 @@ import ( ) type FHIR430Client struct { - BaseClient + *BaseClient } -func NewFHIR430Client(appConfig config.Interface, globalLogger logrus.FieldLogger, credentials models.ProviderCredential, testHttpClient ...*http.Client) (FHIR430Client, error) { - return FHIR430Client{ - NewBaseClient(appConfig, globalLogger, credentials, testHttpClient...), +func NewFHIR430Client(appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (*FHIR430Client, error) { + return &FHIR430Client{ + NewBaseClient(appConfig, globalLogger, source, testHttpClient...), }, nil } diff --git a/backend/pkg/hub/internal/fhir/cigna/client.go b/backend/pkg/hub/internal/fhir/cigna/client.go index 931b63ef..9211a543 100644 --- a/backend/pkg/hub/internal/fhir/cigna/client.go +++ b/backend/pkg/hub/internal/fhir/cigna/client.go @@ -48,8 +48,8 @@ func (c CignaClient) SyncAll(db database.DatabaseRepository) error { //patientProfile. = c.Source.ID c.Logger.Infof("CREATING PATIENT PROFILES: %v", patientProfiles) - for _, patient := range patientProfiles { - err = db.UpsertSourceResource(context.Background(), patient) + for _, profile := range patientProfiles { + err = db.UpsertProfile(context.Background(), profile) if err != nil { return err } diff --git a/backend/pkg/models/patient_profile.go b/backend/pkg/models/patient_profile.go deleted file mode 100644 index b52439e4..00000000 --- a/backend/pkg/models/patient_profile.go +++ /dev/null @@ -1,46 +0,0 @@ -package models - -import "gorm.io/gorm" - -//demographics Object (optional) (See demographics) -//alcohol Object (optional) The user’s alcohol usage. See alcohol object. -//smoking Object (optional) The user’s smoking habits. See smoking object. - -type PatientProfile struct { - gorm.Model - User User `json:"user,omitempty"` - UserID uint `json:"user_id" gorm:"uniqueIndex:idx_user_provider_patient"` - ProviderId string `json:"provider_id" gorm:"uniqueIndex:idx_user_provider_patient"` - PatientId string `json:"patient_id" gorm:"uniqueIndex:idx_user_provider_patient"` - - //embedded structs - Demographics `json:"demographics,omitempty"` -} - -type Demographics struct { - Address Address `json:"address"` // Object (See address object) - Dob string `json:"dob"` //String (optional) The user’s date of birth e.g. "04/21/1965" - Ethnicity string `json:"ethnicity"` // String (optional) The ethnicity of the user e.g. "Not Hispanic of Latino" - Gender string `json:"gender"` // String (optional) The user’s gender e.g. "male" - Language string `json:"language"` //String (optional) The user’s primary language e.g. "eng" - MaritalStatus string `json:"maritalStatus"` // String (optional) The user’s marital status (eg: “married”, “single”) - Name Name `json:"name"` // Object (optional) (See name object) - Race string `json:"race"` // String (optional) The user’s race e.g. "White" - EthnicityCodes string `json:"ethnicityCodes"` // ethnicityCodes Array[Object] (optional) CDC Race & Ethnicity and SNOMED CT Ethnicity codes: See codes - MaritalStatusCodes string `json:"maritalStatusCodes"` // String (optional) SNOMED CT Marital status codes: see codes object - GenderCodes string `json:"genderCodes"` //String (optional) SNOMED CT Gender codes: See codes -} - -type Address struct { - City string `json:"city"` // (optional) City of address e.g. "SAN FRANCISCO" - Country string `json:"country"` // (optional) Country of address e.g. "US" - State string `json:"state"` // (optional) State of address e.g. "CA" - Street []string `json:"street"` // Array[String] (optional) Street of address e.g. ["156 22ND AVE NW"] - Zip string `json:"zip"` // (optional) Zip of address e.g. "94123" -} - -type Name struct { - Prefix string `json:"prefix"` // String (optional) The title of the provider e.g. "MD" - Given []string `json:"given"` // Array[String] Name values associated with the provider e.g. ["Travis", "R"] - Family string `json:"family"` // String (optional) Family name of the provider e.g. "Liddell" -}