2022-08-28 11:51:58 -06:00
|
|
|
package cigna
|
|
|
|
|
|
|
|
import (
|
2022-08-30 20:03:24 -06:00
|
|
|
"context"
|
2022-08-28 11:51:58 -06:00
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config"
|
2022-08-30 20:03:24 -06:00
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
|
2022-08-28 11:51:58 -06:00
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/hub/internal/fhir/base"
|
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CignaClient struct {
|
2022-08-30 20:03:24 -06:00
|
|
|
*base.FHIR401Client
|
2022-08-28 11:51:58 -06:00
|
|
|
}
|
|
|
|
|
2022-09-13 19:02:26 -06:00
|
|
|
func NewClient(ctx context.Context, appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (base.Client, *models.Source, error) {
|
|
|
|
baseClient, updatedSource, err := base.NewFHIR401Client(ctx, appConfig, globalLogger, source, testHttpClient...)
|
2022-08-28 11:51:58 -06:00
|
|
|
return CignaClient{
|
|
|
|
baseClient,
|
2022-09-09 00:51:46 -06:00
|
|
|
}, updatedSource, err
|
2022-08-28 11:51:58 -06:00
|
|
|
}
|
|
|
|
|
2022-08-30 20:03:24 -06:00
|
|
|
func (c CignaClient) SyncAll(db database.DatabaseRepository) error {
|
2022-08-28 11:51:58 -06:00
|
|
|
|
2022-09-01 19:54:01 -06:00
|
|
|
bundle, err := c.GetPatientBundle(c.Source.PatientId)
|
2022-08-28 20:09:39 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-08 22:14:03 -06:00
|
|
|
wrappedResourceModels, err := c.ProcessBundle(bundle)
|
2022-09-19 21:21:22 -06:00
|
|
|
if err != nil {
|
|
|
|
c.Logger.Infof("An error occurred while processing patient bundle %s", c.Source.PatientId)
|
|
|
|
return err
|
|
|
|
}
|
2022-09-01 19:54:01 -06:00
|
|
|
//todo, create the resources in dependency order
|
2022-08-30 21:24:37 -06:00
|
|
|
|
2022-09-08 22:14:03 -06:00
|
|
|
for _, apiModel := range wrappedResourceModels {
|
2022-09-01 19:54:01 -06:00
|
|
|
err = db.UpsertResource(context.Background(), apiModel)
|
2022-08-30 22:36:40 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2022-08-28 11:51:58 -06:00
|
|
|
return nil
|
|
|
|
}
|