forked from IBMStreams/streamsx.health
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloinc_generate.py
executable file
·59 lines (43 loc) · 1.21 KB
/
loinc_generate.py
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
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--start", type=int)
parser.add_argument("--num", type=int)
parser.add_argument("--noX", action="count")
args = parser.parse_args()
start = args.start
num = args.num
noX = args.noX
def nextTen(n):
if (n % 10):
n = n + (10 - n % 10)
return n
def addChecksum(code):
codeStr = str(code)
# 1. convert code to character array and reverse to assign positions
codeArr = list(codeStr)[::-1]
# 2. get the odd numbered values and convert to integer
odd = int("".join(codeArr[0::2]))
# 3. multiply by 2
mult = odd*2
# 4. Take the even digit positions
even = int("".join(codeArr[1::2]))
# 5. Append the even value to the front of the value in #3
app = str(even) + str(mult)
# 6. Add the digits together
appArr = list(str(app))
sum = 0
for x in appArr:
sum += int(x)
# 7. Find next multiple of 10
multTen = nextTen(sum)
cksum = multTen - sum
return str(code) + "-" + str(cksum)
# main program
codes = []
for i in range(start, start+num):
code = addChecksum(i)
if noX == None:
code = "X" + code
codes.append(code)
for c in codes:
print(c)