forked from iwtsolutions/adt-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patient.rb
executable file
·118 lines (98 loc) · 2.69 KB
/
patient.rb
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require './segments/msh'
require './segments/pid'
require './segments/pv1'
require './segments/mrg'
require './test'
class Patient
def initialize(test)
@test = test
# New patient segments per case set
@msh = MshSegment.new
@pid = PidSegment.new
@pv1 = Pv1Segment.new
sex = rand(0..1) == 0 ? "m" : "f"
first_name = @test.get_random_first_name(sex)
last_name = @test.get_random_last_name
dob = @test.time_rand
dob_formatted = dob.strftime("%Y%m%d")
@pid.set_mrn(generate_mrn)
@pid.set_acct(generate_acct)
@pid.set_sex(sex)
@pid.set_name(last_name, first_name)
@pid.set_dob(dob_formatted)
end
def generate_mrn
Random.new.rand(542000..542999)
end
def generate_acct
Random.new.rand(1240000..1249999)
end
def get_mrn
@pid.get_mrn
end
def get_acct
@pid.get_acct
end
def get_message(msg_type='')
case msg_type.downcase
when "a01"
set_a01
when "a08"
set_a08
when "a03"
set_a03
when "a05"
set_a05
when "a06"
set_a06
when "a02"
set_a02
end
header = @msh.create_msh_evn msg_type
message = header + @pid.to_s + @pv1.to_s
if @mrg
message += @mrg.to_s
end
return message
end
# TODO: Create more message type related changes
def set_a01
loc = @test.get_random_location
@pv1.set_location(loc)
@pv1.set_pt_type('Inpatient')
admit_date = Time.now.strftime("%Y%M%d%H%M%S")
@pv1.set_admit_date(admit_date)
end
def set_a08
dob = @test.time_rand
dob_formatted = dob.strftime("%Y%m%d")
@pid.set_dob(dob_formatted)
loc = @test.get_random_location
@pv1.set_location(loc)
end
def set_a03
discharge_date = Time.now.strftime("%Y%m%d%H%M%S")
@pv1.set_discharge_date(discharge_date)
end
def set_a05
@pv1.set_pt_type('Outpatient')
admit_date = Time.now.strftime("%Y%m%d%H%M%S")
@pv1.set_admit_date(admit_date)
end
def set_a06
@pv1.set_pt_type('Inpatient')
loc = @test.get_random_location
@pv1.set_location(loc)
end
def set_a02
loc = @test.get_random_location
@pv1.set_location(loc)
end
def add_mrg(mrn, acct)
@mrg = MrgSegment.new
puts mrn
puts acct
@mrg.set_old_mrn mrn
@mrg.set_old_account acct
end
end