-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
7,702 additions
and
22,954 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dto | ||
|
||
import "github.com/savannahghi/scalarutils" | ||
|
||
// Condition represents a FHIR condition | ||
type Condition struct { | ||
ID string `json:"id"` | ||
Status ConditionStatus `json:"status"` | ||
Name string `json:"condition"` | ||
Code string `json:"code"` | ||
System string `json:"system"` | ||
|
||
OnsetDate scalarutils.Date `json:"onsetDate"` | ||
RecordedDate scalarutils.Date `json:"recordedDate"` | ||
|
||
Note string `json:"note"` | ||
|
||
PatientID string `json:"patientID"` | ||
EncounterID string `json:"encounterID"` | ||
} | ||
|
||
// ConditionEdge is a condition edge | ||
type ConditionEdge struct { | ||
Node Condition | ||
Cursor string | ||
} | ||
|
||
// ConditionConnection is a Condition Connection Type | ||
type ConditionConnection struct { | ||
TotalCount int | ||
Edges []ConditionEdge | ||
PageInfo PageInfo | ||
} | ||
|
||
// CreateConditionConnection creates a connection that follows the GraphQl Cursor Connection Specification | ||
func CreateConditionConnection(conditions []Condition, pageInfo PageInfo, total int) ConditionConnection { | ||
connection := ConditionConnection{ | ||
TotalCount: total, | ||
Edges: []ConditionEdge{}, | ||
PageInfo: pageInfo, | ||
} | ||
|
||
for _, condition := range conditions { | ||
edge := ConditionEdge{ | ||
Node: condition, | ||
Cursor: condition.ID, | ||
} | ||
|
||
connection.Edges = append(connection.Edges, edge) | ||
} | ||
|
||
return connection | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package dto | ||
|
||
import "fmt" | ||
|
||
const defaultPageCount = 10 | ||
|
||
// PageInfo is used to add pagination information to Relay edges. | ||
type PageInfo struct { | ||
// Forward pagination | ||
HasNextPage bool | ||
EndCursor *string | ||
|
||
// Backward pagination | ||
HasPreviousPage bool | ||
StartCursor *string | ||
} | ||
|
||
// Pagination represents paging parameters | ||
type Pagination struct { | ||
// Forward pagination arguments | ||
First *int `json:"first"` | ||
After string `json:"after"` | ||
|
||
// Backward pagination arguments | ||
Last *int `json:"last"` | ||
Before string `json:"before"` | ||
} | ||
|
||
func (p *Pagination) Validate() error { | ||
if p.First != nil && p.Last != nil { | ||
return fmt.Errorf("cannot provide both first and last") | ||
} | ||
|
||
if p.First != nil { | ||
first := *p.First | ||
if first <= 0 { | ||
return fmt.Errorf("first cannot be less than 0") | ||
} | ||
} | ||
|
||
if p.Last != nil { | ||
last := *p.Last | ||
if last <= 0 { | ||
return fmt.Errorf("last cannot be less than 0") | ||
} | ||
} | ||
|
||
if p.First == nil && p.Last == nil { | ||
limit := defaultPageCount | ||
p.First = &limit | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.