Skip to content

Instantly share code, notes, and snippets.

@gyorgybalazsi
Last active September 2, 2021 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyorgybalazsi/d54252e509c33e4aefe0c6c7500590c6 to your computer and use it in GitHub Desktop.
Save gyorgybalazsi/d54252e509c33e4aefe0c6c7500590c6 to your computer and use it in GitHub Desktop.
Surgical event update with flexible controller
module Main where
import Types
import Utils
import DA.Text
import DA.Optional
import DA.Date as D
import DA.Time
import Daml.Script
type SEKey = (Party, Optional Text)
type SECKey = (Party, Party, Optional Text, RuleType)
getSEID : Optional Text -> Optional Text
getSEID id = Some (toUpper((substring 1 10 (fromOptional "" id))))
-- Technical contract for creating Surgical Event
template SurgicalEvent_Offer
with
surgicalEvent: SurgicalEvent
operator : Party
hospital : Party
where
signatory operator
controller hospital can
Accept_SurgicalEvent : ContractId SurgicalEvent
do
create surgicalEvent
-- The Surgical Evenet you want to make available for Hospital Manager
template SurgicalEvent
with
operator : Party
hospital : Party
surgicaleventdata: SurgicalEventdata
surgicaleventproductdata : [SurgicalEventProductdata]
created_at : Time
partiesAllowedToUpdate : [Party]
where
signatory hospital, operator
observer hospital, partiesAllowedToUpdate
key (hospital, surgicaleventdata.seid) : SEKey
maintainer key._1
nonconsuming choice UpdateSurgicalEvent : ContractId SurgicalEvent
with
newsurgicaleventdata: SurgicalEventdata
whoAmI : Party
controller whoAmI
do
assertMsg "Surgical Event Status should be Scheduled" $ this.surgicaleventdata.status == Scheduled
assertMsg "You need to be an authorized updater" $ whoAmI `elem` partiesAllowedToUpdate
currentTime <- getTime
archive self
create this with surgicaleventdata = newsurgicaleventdata
with id = getID (this.surgicaleventdata.id, (show currentTime), Some "SE", Prelude.None),
seid = getSEID(this.surgicaleventdata.id),
status = this.surgicaleventdata.status,
price = this.surgicaleventdata.price
test : Script ()
test = do
setTime $ time (D.date 2021 Jan 1) 0 0 0
operator <- allocateParty "Operator"
hospital <- allocateParty "FirstHealth"
biomed <- allocateParty "Biomed"
manager <- allocateParty "FirstHealthManager"
let surgicaleventdata = SurgicalEventdata
with
id = Prelude.None
seid = Prelude.None
mrn = Some "mmm"
patientfirstname = Some "First name of Patient"
patientlastname = Some "Last name of Patient"
patientgender = Some Male
patientdob = Some (D.date 2021 Jun 18)
eventdate = D.date 2021 Jul 05
surgicalprocedure = ""
surgicalside = Types.Left
physiciansalutation = Some MD
physicianfirstname = "John"
physicianlastname = "Smith"
status = Scheduled
price = 0.0
let surgicaleventdata1 = SurgicalEventdata
with
id = Prelude.None
seid = Prelude.None
mrn = Some "123456"
patientfirstname = Some "John"
patientlastname = Some "Smith"
patientgender = Some Female
patientdob = Some (D.date 2021 Apr 30)
eventdate = D.date 2021 May 01
surgicalprocedure = "Hart"
surgicalside = Types.Right
physiciansalutation = Some DPM
physicianfirstname = "Eric"
physicianlastname = "s"
status = Scheduled
price = 0.0
let surgical_event_product = SurgicalEventProductdata
with
id = Prelude.None
sepproductkey = Prelude.None
sepproductid = Some "01"
sepreferencenumber = Some "referencenumber"
sepproductmanufacturer = biomed
sepproductname = Some "Product"
sepproductdescription = Some "desc..."
sepproductexpiration = D.date 2021 Feb 20
sepproductprice = 300.0
seplotcode = Some "123456789"
sepproducttype = Some Implant
sepownership = Owned
sepudi = Some "UDI_123456"
sepproductside = Types.Right
let admindetails = AdminDetail
with
auto_po = True
auto_po_vendor = False
approval_level = Two
approval_amount_levelone = Some 100.0
approval_amount_leveltwo = Some 200.0
let physicaladdr = AddressDetail
with
address1 = "111"
address2 = "222"
city = ""
state = NC
zipcode = ""
country = "US"
location = Prelude.None
let shippingaddr = AddressDetail
with
address1 = "111"
address2 = "222"
city = ""
state = NC
zipcode = ""
country = "US"
location = Some "Charlotte"
let billingaddr = AddressDetail
with
address1 = "111"
address2 = "222"
city = ""
state = NC
zipcode = ""
country = "US"
location = Prelude.None
let point_contract = ContactDetail
with
lastname = Some "Med"
firstname = Some "Bio"
gender = Some Male
phone = "+1234567890"
email = "test@email.com"
fax = ""
jobtitle = ""
customerservicename = Prelude.None
let ach_info = ACHDetail
with
accountnumber = Some 1000
routingnumber = Some 1000
bankname = Some "BANK 1"
typeaccount = Some "test account"
let billinfoctr = ContactDetail
with
lastname = Some "Med"
firstname = Some "Bio"
gender = Some Female
phone = "+1234567890"
email = "test@email.com"
fax = ""
jobtitle = ""
customerservicename = Prelude.None
let purchinfoctr = ContactDetail
with
lastname = Some "Med"
firstname = Some "Bio"
gender = Some Male
phone = "+1234567890"
email = "test@email.com"
fax = ""
jobtitle = ""
customerservicename = Prelude.None
let hospitaldetails = HospitalDetail
with
facilityname = "First Health"
physicaladdress = physicaladdr
shippingaddress = [shippingaddr]
billingaddress = billingaddr
point_contact = [point_contract]
ach_info = Some ach_info
billinfocontact = [billinfoctr]
purchinfocontact = [purchinfoctr]
taxid = "Hospital TAX"
let surgicaleventproductdata = [surgical_event_product]
created_at <- getTime
let surgicalEvent = SurgicalEvent with partiesAllowedToUpdate = [manager], ..
seOffer <- submit operator $ createCmd SurgicalEvent_Offer with ..
se <- submit hospital $ exerciseCmd seOffer Accept_SurgicalEvent
submit manager $ exerciseCmd se UpdateSurgicalEvent with
newsurgicaleventdata = surgicaleventdata1
whoAmI = manager
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment