-
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.
chore: port patient anf fhir implementation into single usecase (#34)
Signed-off-by: Otieno Calvine <nyarangaotieno@gmail.com>
- Loading branch information
Showing
31 changed files
with
7,428 additions
and
7,138 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
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 |
---|---|---|
@@ -1 +1,39 @@ | ||
package common | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
"log" | ||
|
||
"github.com/savannahghi/clinical/pkg/clinical/application/extensions" | ||
"github.com/savannahghi/clinical/pkg/clinical/application/utils" | ||
"github.com/savannahghi/interserviceclient" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// NewInterServiceClient initializes an external service in the correct environment given its name | ||
func NewInterServiceClient(serviceName string, baseExt extensions.BaseExtension) *interserviceclient.InterServiceClient { | ||
config, err := baseExt.LoadDepsFromYAML() | ||
if err != nil { | ||
logrus.Panicf("occurred while opening deps file %v", err) | ||
return nil | ||
} | ||
|
||
client, err := baseExt.SetupISCclient(*config, serviceName) | ||
if err != nil { | ||
logrus.Panicf("unable to initialize inter service client for %v service: %s", err, serviceName) | ||
return nil | ||
} | ||
return client | ||
} | ||
|
||
// GeneratePatientWelcomeEmailTemplate generates a welcome email | ||
func GeneratePatientWelcomeEmailTemplate() string { | ||
t := template.Must(template.New("welcomeEmail").Parse(utils.PatientWelcomeEmail)) | ||
buf := new(bytes.Buffer) | ||
err := t.Execute(buf, "") | ||
if err != nil { | ||
log.Fatalf("Error while generating patient welcome email template: %s", err) | ||
} | ||
return buf.String() | ||
} |
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,66 @@ | ||
package common | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/rs/xid" | ||
"github.com/savannahghi/clinical/pkg/clinical/domain" | ||
"github.com/savannahghi/scalarutils" | ||
) | ||
|
||
// constants and defaults | ||
const ( | ||
|
||
// CenturyHours is the number of hours in a (fictional) century of leap years | ||
CenturyHours = 878400 | ||
timeFormatStr = "2006-01-02T15:04:05+03:00" | ||
healthCloudIdentifiers = "healthcloud.identifiers" | ||
healthCloudIdentifiersVersion = "0.0.1" | ||
) | ||
|
||
// DefaultIdentifier assigns a patient a code to function as their | ||
// medical record number. | ||
func DefaultIdentifier() *domain.FHIRIdentifierInput { | ||
xid := xid.New().String() | ||
system := scalarutils.URI(healthCloudIdentifiers) | ||
version := healthCloudIdentifiersVersion | ||
userSelected := false | ||
return &domain.FHIRIdentifierInput{ | ||
Use: domain.IdentifierUseEnumOfficial, | ||
Value: xid, | ||
Type: domain.FHIRCodeableConceptInput{ | ||
Text: "MR", | ||
Coding: []*domain.FHIRCodingInput{ | ||
{ | ||
System: &system, | ||
Version: &version, | ||
Code: scalarutils.Code(xid), | ||
Display: xid, | ||
UserSelected: &userSelected, | ||
}, | ||
}, | ||
}, | ||
System: &system, | ||
Period: DefaultPeriodInput(), | ||
} | ||
} | ||
|
||
// DefaultPeriodInput sets up a period input covering roughly a century from when it's run | ||
func DefaultPeriodInput() *domain.FHIRPeriodInput { | ||
now := time.Now() | ||
farFuture := time.Now().Add(time.Hour * CenturyHours) | ||
return &domain.FHIRPeriodInput{ | ||
Start: scalarutils.DateTime(now.Format(timeFormatStr)), | ||
End: scalarutils.DateTime(farFuture.Format(timeFormatStr)), | ||
} | ||
} | ||
|
||
// DefaultPeriod sets up a period input covering roughly a century from when it's run | ||
func DefaultPeriod() *domain.FHIRPeriod { | ||
now := time.Now() | ||
farFuture := time.Now().Add(time.Hour * CenturyHours) | ||
return &domain.FHIRPeriod{ | ||
Start: scalarutils.DateTime(now.Format(timeFormatStr)), | ||
End: scalarutils.DateTime(farFuture.Format(timeFormatStr)), | ||
} | ||
} |
Oops, something went wrong.