Skip to content

Commit

Permalink
Merge pull request #66 from tidepool-org/tk-visit-accountnumber
Browse files Browse the repository at this point in the history
[BACK-3126] Set visit account number
  • Loading branch information
toddkazakov authored Sep 11, 2024
2 parents 45185d1 + 1cd0a5b commit ba27541
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 752 deletions.
6 changes: 6 additions & 0 deletions redox/processor_neworder.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func (o *newOrderProcessor) createSummaryStatisticsFlowsheet(params SummaryAndRe
flowsheet.Patient.Demographics = params.Order.Patient.Demographics

SetVisitNumberInFlowsheet(params.Order, &flowsheet)
SetAccountNumberInFlowsheet(params.Order, &flowsheet)
PopulateSummaryStatistics(patient, params.Match.Clinic, &flowsheet)

return flowsheet, nil
Expand Down Expand Up @@ -355,6 +356,7 @@ func (o *newOrderProcessor) createReportNote(ctx context.Context, params Summary

notes.SetOrderId(params.Order)
notes.SetVisitNumberFromOrder(params.Order)
notes.SetAccountNumberFromOrder(params.Order)

documentId := params.DocumentId
if documentId == "" {
Expand Down Expand Up @@ -481,6 +483,8 @@ func (o *newOrderProcessor) sendMatchingResultsNotification(ctx context.Context,
results.Meta.Destinations = &destinations
SetResultsPatientFromOrder(params.Order, &results)
SetMatchingResult(notification, params.Order, &results)
SetAccountNumberInResult(params.Order, &results)
SetVisitNumberInResult(params.Order, &results)

if err := o.client.Send(ctx, results); err != nil {
// Return an error so we can retry the request
Expand All @@ -506,6 +510,8 @@ func (o *newOrderProcessor) sendAccountCreationResultsNotification(ctx context.C
results.Meta.Destinations = &destinations
SetResultsPatientFromOrder(order, &results)
SetAccountCreationResults(notification, order, &results)
SetAccountNumberInResult(order, &results)
SetVisitNumberInResult(order, &results)

if err := o.client.Send(ctx, results); err != nil {
// Return an error so we can retry the request
Expand Down
120 changes: 43 additions & 77 deletions redox/response_flowsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redox

import (
"fmt"
"github.com/tidepool-org/clinic-worker/types"
clinics "github.com/tidepool-org/clinic/client"
models "github.com/tidepool-org/clinic/redox_models"
"strings"
Expand Down Expand Up @@ -103,21 +104,19 @@ func PopulateCGMObservations(stats *clinics.PatientCGMStats, preferredBgUnits cl
timeInVeryHigh = period.TimeInVeryHighPercent
}

f.Observations = append(f.Observations,
CreateObservation("REPORTING_PERIOD_START_CGM", formatTime(periodStart), "DateTime", nil, "CGM Reporting Period Start", reportingTime),
CreateObservation("REPORTING_PERIOD_END_CGM", formatTime(periodEnd), "DateTime", nil, "CGM Reporting Period End", reportingTime),
CreateObservation("REPORTING_PERIOD_START_CGM_DATA", formatTime(firstData), "DateTime", nil, "CGM Reporting Period Start Date of actual Data", reportingTime),

CreateObservation("ACTIVE_WEAR_TIME_CGM", formatFloat(unitIntervalToPercent(cgmUsePercent)), "Numeric", &unitsPercentage, "Percentage of time CGM worn during reporting period", reportingTime),
CreateObservation("AVERAGE_CGM", formatFloat(averageGlucose), "Numeric", averageGlucoseUnits, "CGM Average Glucose during reporting period", reportingTime),
CreateObservation("GLUCOSE_MANAGEMENT_INDICATOR", formatFloat(gmi), "Numeric", nil, "CGM Glucose Management Indicator during reporting period", reportingTime),

CreateObservation("TIME_BELOW_RANGE_VERY_LOW_CGM", formatFloat(unitIntervalToPercent(timeInVeryLow)), "Numeric", &unitsPercentage, "CGM Time in Level 2 Hypoglycemia: <Time below range (TBR-VL): % of readings and time <54 mg/dL (<3.0 mmol/L)", reportingTime),
CreateObservation("TIME_BELOW_RANGE_LOW_CGM", formatFloat(unitIntervalToPercent(timeInLow)), "Numeric", &unitsPercentage, "CGM Time in Level 1 Hypoglycemia: Time below range (TBR-L): % of readings and time 54–69 mg/dL (3.0–3.8 mmol/L)", reportingTime),
CreateObservation("TIME_IN_RANGE_CGM", formatFloat(unitIntervalToPercent(timeInTarget)), "Numeric", &unitsPercentage, "CGM Time in Range: Time in range (TIR): % of readings and time 70–180 mg/dL (3.9–10.0 mmol/L)", reportingTime),
CreateObservation("TIME_ABOVE_RANGE_HIGH_CGM", formatFloat(unitIntervalToPercent(timeInHigh)), "Numeric", &unitsPercentage, "CGM Time in Level 1 Hyperglycemia: Time above range (TAR-H): % of readings and time 181–250 mg/dL (10.1–13.9 mmol/L)", reportingTime),
CreateObservation("TIME_ABOVE_RANGE_VERY_HIGH_CGM", formatFloat(unitIntervalToPercent(timeInVeryHigh)), "Numeric", &unitsPercentage, "CGM Level 2 Hyperglycemia: Time above range (TAR-VH): % of readings and time >250 mg/dL (>13.9 mmol/L)", reportingTime),
)
AppendObservation(f, "REPORTING_PERIOD_START_CGM", formatTime(periodStart), "DateTime", nil, "CGM Reporting Period Start", reportingTime)
AppendObservation(f, "REPORTING_PERIOD_END_CGM", formatTime(periodEnd), "DateTime", nil, "CGM Reporting Period End", reportingTime)
AppendObservation(f, "REPORTING_PERIOD_START_CGM_DATA", formatTime(firstData), "DateTime", nil, "CGM Reporting Period Start Date of actual Data", reportingTime)

AppendObservation(f, "ACTIVE_WEAR_TIME_CGM", formatFloat(unitIntervalToPercent(cgmUsePercent)), "Numeric", &unitsPercentage, "Percentage of time CGM worn during reporting period", reportingTime)
AppendObservation(f, "AVERAGE_CGM", formatFloat(averageGlucose), "Numeric", averageGlucoseUnits, "CGM Average Glucose during reporting period", reportingTime)
AppendObservation(f, "GLUCOSE_MANAGEMENT_INDICATOR", formatFloat(gmi), "Numeric", nil, "CGM Glucose Management Indicator during reporting period", reportingTime)

AppendObservation(f, "TIME_BELOW_RANGE_VERY_LOW_CGM", formatFloat(unitIntervalToPercent(timeInVeryLow)), "Numeric", &unitsPercentage, "CGM Time in Level 2 Hypoglycemia: <Time below range (TBR-VL): % of readings and time <54 mg/dL (<3.0 mmol/L)", reportingTime)
AppendObservation(f, "TIME_BELOW_RANGE_LOW_CGM", formatFloat(unitIntervalToPercent(timeInLow)), "Numeric", &unitsPercentage, "CGM Time in Level 1 Hypoglycemia: Time below range (TBR-L): % of readings and time 54–69 mg/dL (3.0–3.8 mmol/L)", reportingTime)
AppendObservation(f, "TIME_IN_RANGE_CGM", formatFloat(unitIntervalToPercent(timeInTarget)), "Numeric", &unitsPercentage, "CGM Time in Range: Time in range (TIR): % of readings and time 70–180 mg/dL (3.9–10.0 mmol/L)", reportingTime)
AppendObservation(f, "TIME_ABOVE_RANGE_HIGH_CGM", formatFloat(unitIntervalToPercent(timeInHigh)), "Numeric", &unitsPercentage, "CGM Time in Level 1 Hyperglycemia: Time above range (TAR-H): % of readings and time 181–250 mg/dL (10.1–13.9 mmol/L)", reportingTime)
AppendObservation(f, "TIME_ABOVE_RANGE_VERY_HIGH_CGM", formatFloat(unitIntervalToPercent(timeInVeryHigh)), "Numeric", &unitsPercentage, "CGM Level 2 Hyperglycemia: Time above range (TAR-VH): % of readings and time >250 mg/dL (>13.9 mmol/L)", reportingTime)
}

func PopulateBGMObservations(stats *clinics.PatientBGMStats, preferredBgUnits clinics.ClinicPreferredBgUnits, f *models.NewFlowsheet) {
Expand Down Expand Up @@ -170,76 +169,43 @@ func PopulateBGMObservations(stats *clinics.PatientBGMStats, preferredBgUnits cl
timeInVeryHighRecords = period.TimeInVeryHighRecords
}

f.Observations = append(f.Observations,
CreateObservation("REPORTING_PERIOD_START_SMBG", formatTime(periodStart), "DateTime", nil, "SMBG Reporting Period Start", reportingTime),
CreateObservation("REPORTING_PERIOD_END_SMBG", formatTime(periodEnd), "DateTime", nil, "SMBG Reporting Period End", reportingTime),
CreateObservation("REPORTING_PERIOD_START_SMBG_DATA", formatTime(firstData), "DateTime", nil, "SMBG Reporting Period Start Date of actual Data", reportingTime),
AppendObservation(f, "REPORTING_PERIOD_START_SMBG", formatTime(periodStart), "DateTime", nil, "SMBG Reporting Period Start", reportingTime)
AppendObservation(f, "REPORTING_PERIOD_END_SMBG", formatTime(periodEnd), "DateTime", nil, "SMBG Reporting Period End", reportingTime)
AppendObservation(f, "REPORTING_PERIOD_START_SMBG_DATA", formatTime(firstData), "DateTime", nil, "SMBG Reporting Period Start Date of actual Data", reportingTime)

CreateObservation("CHECK_RATE_READINGS_DAY_SMBG", formatFloat(averageDailyRecords), "Numeric", nil, "Average Numeric of SMBG readings per day during reporting period", reportingTime),
CreateObservation("AVERAGE_SMBG", formatFloat(averageGlucose), "Numeric", averageGlucoseUnits, "SMBG Average Glucose during reporting period", reportingTime),
AppendObservation(f, "CHECK_RATE_READINGS_DAY_SMBG", formatFloat(averageDailyRecords), "Numeric", nil, "Average Numeric of SMBG readings per day during reporting period", reportingTime)
AppendObservation(f, "AVERAGE_SMBG", formatFloat(averageGlucose), "Numeric", averageGlucoseUnits, "SMBG Average Glucose during reporting period", reportingTime)

CreateObservation("READINGS_BELOW_RANGE_VERY_LOW_SMBG", formatInt(timeInVeryLowRecords), "Numeric", nil, "SMBG Level 2 Hypoglycemia Events: Number of readings <54 mg/dL (<3.0 mmol/L) during reporting period", reportingTime),
CreateObservation("READINGS_ABOVE_RANGE_VERY_HIGH_SMBG", formatInt(timeInVeryHighRecords), "Numeric", nil, "SMBG Level 2 Hyperglycemia: Number of readings above range (TAR-VH) time >250 mg/dL (>13.9 mmol/L) during reporting period", reportingTime),
)
AppendObservation(f, "READINGS_BELOW_RANGE_VERY_LOW_SMBG", formatInt(timeInVeryLowRecords), "Numeric", nil, "SMBG Level 2 Hypoglycemia Events: Number of readings <54 mg/dL (<3.0 mmol/L) during reporting period", reportingTime)
AppendObservation(f, "READINGS_ABOVE_RANGE_VERY_HIGH_SMBG", formatInt(timeInVeryHighRecords), "Numeric", nil, "SMBG Level 2 Hyperglycemia: Number of readings above range (TAR-VH) time >250 mg/dL (>13.9 mmol/L) during reporting period", reportingTime)
}

func CreateObservation(code, value, valueType string, units *string, description, dateTime string) (res struct {
AbnormalFlag *string `json:"AbnormalFlag"`
Code string `json:"Code"`
Codeset *string `json:"Codeset"`
DateTime string `json:"DateTime"`
Description *string `json:"Description"`
Notes *[]interface{} `json:"Notes,omitempty"`
Observer *struct {
FirstName *string `json:"FirstName"`
ID *string `json:"ID"`
IDType *string `json:"IDType"`
LastName *string `json:"LastName"`
} `json:"Observer,omitempty"`
ReferenceRange *struct {
High *float32 `json:"High"`
Low *float32 `json:"Low"`
Text *string `json:"Text"`
} `json:"ReferenceRange,omitempty"`
Status *string `json:"Status"`
Units *string `json:"Units"`
Value string `json:"Value"`
ValueType string `json:"ValueType"`
}) {
res.Code = code
res.Value = value
res.ValueType = valueType
res.Units = units
res.Description = &description
res.DateTime = dateTime
return
func AppendObservation(f *models.NewFlowsheet, code, value, valueType string, units *string, description, dateTime string) {
observation := types.NewItemForSlice(f.Observations)
observation.Code = code
observation.Value = value
observation.ValueType = valueType
observation.Units = units
observation.Description = &description
observation.DateTime = dateTime
f.Observations = append(f.Observations, observation)
}

func SetVisitNumberInFlowsheet(order models.NewOrder, flowsheet *models.NewFlowsheet) {
if order.Visit != nil && order.Visit.VisitNumber != nil && *order.Visit.VisitNumber != "" {
visit := struct {
AccountNumber *string `json:"AccountNumber"`
Location *struct {
Bed *string `json:"Bed"`
Department *string `json:"Department"`
DepartmentIdentifiers *[]struct {
ID *string `json:"ID"`
IDType *string `json:"IDType"`
} `json:"DepartmentIdentifiers,omitempty"`
Facility *string `json:"Facility"`
FacilityIdentifiers *[]struct {
ID *string `json:"ID"`
IDType *string `json:"IDType"`
} `json:"FacilityIdentifiers,omitempty"`
Room *string `json:"Room"`
Type *string `json:"Type"`
} `json:"Location,omitempty"`
VisitDateTime *string `json:"VisitDateTime"`
VisitNumber *string `json:"VisitNumber"`
}{
VisitNumber: order.Visit.VisitNumber,
if order.Visit != nil && order.Visit.VisitNumber != nil {
if flowsheet.Visit == nil {
flowsheet.Visit = types.NewStructPtr(flowsheet.Visit)
}
flowsheet.Visit.VisitNumber = order.Visit.VisitNumber
}
}

func SetAccountNumberInFlowsheet(order models.NewOrder, flowsheet *models.NewFlowsheet) {
if order.Visit != nil && order.Visit.AccountNumber != nil {
if flowsheet.Visit == nil {
flowsheet.Visit = types.NewStructPtr(flowsheet.Visit)
}
flowsheet.Visit = &visit
flowsheet.Visit.AccountNumber = order.Visit.AccountNumber
}
}

Expand Down
Loading

0 comments on commit ba27541

Please sign in to comment.