ref: bf418d79ab6e22d1134882dfa7b938f4e5a941ba
parent: a086faa000343f005b17d4fdcb1886bc7135cee4
author: halfwit <michaelmisch1985@gmail.com>
date: Fri Nov 8 08:27:39 PST 2019
Swap countries and services to proper plugins
--- a/pages/doctor/application.go
+++ b/pages/doctor/application.go
@@ -1,6 +1,7 @@
package doctor
import (
+ "github.com/olmaxmedical/olmax_go/plugins"
"github.com/olmaxmedical/olmax_go/router"
"golang.org/x/text/message"
)
@@ -11,7 +12,7 @@
CSS: "",
Path: "doctor/application",
Data: Application,
- Extra: router.ListCountries | router.ListServices | router.FormErrors | router.FormToken,
+ Extra: router.ListCountries | plugins.ListServices | router.FormErrors | router.FormToken,
}
router.AddPage(b)
}
--- a/pages/help/provider.go
+++ b/pages/help/provider.go
@@ -1,7 +1,9 @@
package help
import (
+ "github.com/olmaxmedical/olmax_go/plugins"
"github.com/olmaxmedical/olmax_go/router"
+
"golang.org/x/text/message"
)
@@ -11,7 +13,7 @@
CSS: "",
Path: "help/provider",
Data: Provider,
- Extra: router.ListServices,
+ Extra: plugins.ListServices,
}
router.AddPage(b)
}
--- a/pages/index.go
+++ b/pages/index.go
@@ -1,6 +1,7 @@
package pages
import (
+ "github.com/olmaxmedical/olmax_go/plugins"
"github.com/olmaxmedical/olmax_go/router"
"golang.org/x/text/message"
)
@@ -11,7 +12,7 @@
CSS: "index.css",
Path: "index",
Data: Index,
- Extra: router.ListDoctors | router.FormErrors,
+ Extra: plugins.ListDoctors | router.FormErrors,
}
router.AddPage(b)
}
--- a/pages/patient/offer.go
+++ b/pages/patient/offer.go
@@ -1,6 +1,7 @@
package patient
import (
+ "github.com/olmaxmedical/olmax_go/plugins"
"github.com/olmaxmedical/olmax_go/router"
"golang.org/x/text/message"
)
@@ -11,7 +12,7 @@
CSS: "",
Path: "patient/offer",
Data: Createoffer,
- Extra: router.ListServices | router.FormErrors,
+ Extra: plugins.ListServices | router.FormErrors,
}
router.AddPage(b)
}
--- a/plugins/doctor.go
+++ b/plugins/doctor.go
@@ -5,6 +5,9 @@
"golang.org/x/text/message"
)
+// ListDoctors - Bitmask to list doctors of in client country
+const ListDoctors router.IncludeExtra = 2
+
type doctor struct {
Image string
AlmaMater string
@@ -19,18 +22,21 @@
func init() {
b := &router.Plugin{
Name: "List doctors",
- Run: ListDoctors,
- Validate: ValidateListDoctors,
+ Run: ListDocs,
+ Validate: ValidateListDocs,
}
+ router.AddPlugin(b, ListDoctors)
}
-func ValidateListDoctors() error {
+// ValidateListDocs - Check that db entries exist
+func ValidateListDocs() error {
return nil
}
-func ListDoctors(p *message.Printer) []doctor {
- return []doctor{
- {
+// ListDocs - Query db and return list of doctors in country
+func ListDocs(p *message.Printer) map[string]interface{} {
+ return map[string]interface{}{
+ "Mark Abuzamzam, MD": &doctor{
Image: "AbuzamzamMD.jpg",
AlmaMater: "University of Southern California School of Medicine",
Residency: "University of Southern California, San Diego. Internal Medicine Residency",
@@ -40,7 +46,7 @@
Specialty: "Internal Medicine and Addictions Medicine",
Rate: "0.0013 BTC",
},
- {
+ "Martha Woodfin, MD": &doctor{
Image: "WoodfinMD.jpg",
Name: "Martha Woodfin, MD",
AlmaMater: "University Seoul School of Medicine",
--- a/plugins/specialties.go
+++ b/plugins/specialties.go
@@ -1,70 +1,64 @@
package plugins
import (
+ "github.com/olmaxmedical/olmax_go/router"
"golang.org/x/text/message"
)
-// TODO: inverse function to get the actual specialty back from a whitelist
+// ListServices - Bitmask to list services in native language
+const ListServices router.IncludeExtra = 3
-// Specialty - mapping our token to internationalized string
-type Specialty struct {
- ID string
- Name string
-}
-
-func specialties(p *message.Printer) []Specialty {
- return []Specialty{
- {"acutepain", p.Sprintf("Acute Pain Medicine")},
- {"anesthesiology", p.Sprintf("Anesthesiology")},
- {"bariatric", p.Sprintf("Bariatric Surgery")},
- {"cardiology", p.Sprintf("Cardiology")},
- {"chiropractic", p.Sprintf("Chiropractics")},
- {"chronic", p.Sprintf("Chronic Pain")},
- {"critcare", p.Sprintf("Critical Care")},
- {"dermatology", p.Sprintf("Dermatology")},
- {"emergency", p.Sprintf("Emergency Medicine")},
- {"endocrinology", p.Sprintf("Endocrinology")},
- {"otolaringology", p.Sprintf("Ear Nose and Throat")},
- {"familymedicine", p.Sprintf("Family Medicine")},
- {"gastro", p.Sprintf("Gastrointestinology")},
- {"headneck", p.Sprintf("Head and Neck")},
- {"hematology", p.Sprintf("Hematology and Oncology")},
- {"hepatology", p.Sprintf("Hepatology")},
- {"hyperbaric", p.Sprintf("Hyperbaric")},
- {"immunology", p.Sprintf("Immunology")},
- {"diseases", p.Sprintf("Infectious Diseases")},
- {"internal", p.Sprintf("Internal Medicine")},
- {"neonatal", p.Sprintf("Neonatology")},
- {"nephrology", p.Sprintf("Nephrology")},
- {"neurology", p.Sprintf("Neurology")},
- {"neurosurgery", p.Sprintf("Neurosurgery")},
- {"obstetrics", p.Sprintf("Obstetrics and Gynecology")},
- {"occupational", p.Sprintf("Occupational Medicine")},
- {"opthamology", p.Sprintf("Opthamology")},
- {"orthopedics", p.Sprintf("Orthopedic Surgery")},
- {"palliative", p.Sprintf("Palliative Care")},
- {"pediatrics", p.Sprintf("Pediatrics")},
- {"podiatry", p.Sprintf("Podiatry")},
- {"pulmonology", p.Sprintf("Pulmonology")},
- {"radiology", p.Sprintf("Radiology")},
- {"radiation", p.Sprintf("Radiaton Oncology")},
- {"transplants", p.Sprintf("Transplant Surgery")},
+func init() {
+ b := &router.Plugin{
+ Name: "List specialties",
+ Run: Specialties,
+ Validate: ValidateSpecialties,
}
+ router.AddPlugin(b, ListServices)
}
-func validateSpecialties(p *message.Printer, specialties []string) string {
- for _, s := range specialties {
- if msg := validateSpecialty(p, s); msg != "" {
- return msg
- }
- }
- return ""
+// ValidateSpecialties - No-op
+func ValidateSpecialties() error {
+ return nil
}
-func validateSpecialty(p *message.Printer, specialty string) string {
- switch specialty {
- case "acutepain", "anesthesiology", "bariatric", "cardiology", "chiropractic", "chronic", "critcare", "dermatology", "emergency", "endocrinology", "otolaringology", "familymedicine", "gastro", "headneck", "hematology", "hepatology", "hyperbaric", "immunology", "diseases", "internal", "neonatal", "nephrology", "neurology", "neurosurgery", "obstetrics", "occupational", "opthamology", "orthopedics", "palliative", "pediatrics", "podiatry", "pulmonology", "radiology", "radiation", "transplants":
- return ""
+// Specialties - return a list of native language representations of our medical fields
+func Specialties(p *message.Printer) map[string]interface{} {
+ return map[string]interface{}{
+ "acutepain": p.Sprintf("Acute Pain Medicine"),
+ "anesthesiology": p.Sprintf("Anesthesiology"),
+ "bariatric": p.Sprintf("Bariatric Surgery"),
+ "cardiology": p.Sprintf("Cardiology"),
+ "chiropractic": p.Sprintf("Chiropractics"),
+ "chronic": p.Sprintf("Chronic Pain"),
+ "critcare": p.Sprintf("Critical Care"),
+ "dermatology": p.Sprintf("Dermatology"),
+ "emergency": p.Sprintf("Emergency Medicine"),
+ "endocrinology": p.Sprintf("Endocrinology"),
+ "otolaringology": p.Sprintf("Ear Nose and Throat"),
+ "familymedicine": p.Sprintf("Family Medicine"),
+ "gastro": p.Sprintf("Gastrointestinology"),
+ "headneck": p.Sprintf("Head and Neck"),
+ "hematology": p.Sprintf("Hematology and Oncology"),
+ "hepatology": p.Sprintf("Hepatology"),
+ "hyperbaric": p.Sprintf("Hyperbaric"),
+ "immunology": p.Sprintf("Immunology"),
+ "diseases": p.Sprintf("Infectious Diseases"),
+ "internal": p.Sprintf("Internal Medicine"),
+ "neonatal": p.Sprintf("Neonatology"),
+ "nephrology": p.Sprintf("Nephrology"),
+ "neurology": p.Sprintf("Neurology"),
+ "neurosurgery": p.Sprintf("Neurosurgery"),
+ "obstetrics": p.Sprintf("Obstetrics and Gynecology"),
+ "occupational": p.Sprintf("Occupational Medicine"),
+ "opthamology": p.Sprintf("Opthamology"),
+ "orthopedics": p.Sprintf("Orthopedic Surgery"),
+ "palliative": p.Sprintf("Palliative Care"),
+ "pediatrics": p.Sprintf("Pediatrics"),
+ "podiatry": p.Sprintf("Podiatry"),
+ "pulmonology": p.Sprintf("Pulmonology"),
+ "radiology": p.Sprintf("Radiology"),
+ "radiation": p.Sprintf("Radiaton Oncology"),
+ "transplants": p.Sprintf("Transplant Surgery"),
}
- return p.Sprint("Unknown or nil specialty entered")
}
--- a/router/pages.go
+++ b/router/pages.go
@@ -31,12 +31,10 @@
)
// IncludeExtra - helper bitmasks to populate common elements across the site
-type IncludeExtra uint8
+type IncludeExtra uint32
const (
- ListDoctors IncludeExtra = 1 << iota
- ListServices
- ListCountries
+ ListCountries IncludeExtra = 1 << iota
FormToken
FormErrors
SessionToken
--- a/router/plugins.go
+++ b/router/plugins.go
@@ -7,9 +7,9 @@
)
// DEAD is a magic string to indicate a non-unique plugin key
-const DEAD = 666
+const DEAD IncludeExtra = 0x0666000
-var pluginCache map[int]*Plugin
+var pluginCache map[IncludeExtra]*Plugin
// Plugin - Provide extra data or functionality from GET/POST pages
type Plugin struct {
@@ -19,7 +19,7 @@
}
func init() {
- pluginCache = make(map[int]*Plugin)
+ pluginCache = make(map[IncludeExtra]*Plugin)
}
// ValidatePlugins - Run through each plugin
@@ -32,8 +32,8 @@
if err != nil {
errs = append(errs, err)
}
- if (key & DEAD) != 0 {
- errs = append(errs, fmt.Errorf("Key requested already in use for plugin %s: %d", item.Name, key|DEAD))
+ if (DEAD & key) != 0 {
+ errs = append(errs, fmt.Errorf("Error registering %s: Key requested already in use (%d)", item.Name, key^DEAD))
}
}
return errs
@@ -40,9 +40,9 @@
}
// AddPlugin - Add Plugin to map by key
-func AddPlugin(p *Plugin, key int) {
+func AddPlugin(p *Plugin, key IncludeExtra) {
if pluginCache[key] != nil {
- key &= DEAD
+ key |= DEAD
}
pluginCache[key] = p
}