-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.cjs
52 lines (42 loc) · 1.5 KB
/
project.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@compiler >= 6
include "String.aes"
contract AppointmentFromDoctorNearByYou =
record state = {
doctor: address,
patients: map(int, patient) }
record patient = {
firstName: string,
lastName:string,
age: int,
gender:string,
time: string,
price: int,
ispaid: bool,
isvisited: bool,
problem_Detected:string }
entrypoint init() : state =
{ doctor = Call.caller, patients = {} }
stateful entrypoint add_patient(firstName: string,lastName:string,age:int,gender:string) : int =
let patient_id = Map.size(state.patients) + 1
let new_patient = {
firstName = firstName,
lastName = lastName,
age = age,
gender =gender,
time = "Null",
price = 0,
ispaid=false,
isvisited=false,
problem_Detected="Not diagnosed till now"}
put(state{ patients[patient_id] = new_patient })
patient_id
stateful entrypoint patient_visited(idNumber:int,price:int, problem_Detected:string) =
require(Call.caller == state.doctor ,"You are not authorized to perform this task")
let getInfo =
switch(Map.lookup(idNumber,state.patients))
None => abort("No Patient with that id")
Some(e) => e
let updateInfo = getInfo{price = price,problem_Detected=problem_Detected,isvisited=true}
put(state{patients[idNumber] = updateInfo})
entrypoint get_patient(patient_id: int) : option(patient) =
Map.lookup(patient_id, state.patients)