-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodels.py
179 lines (126 loc) · 6.06 KB
/
models.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from MasterData import models as master_data_models
import json
from decouple import config
import requests
him_icd_url = config('HIM_ICD_URL')
him_cpt_url = config('HIM_CPT_URL')
him_username = config('HIM_USERNAME')
him_password = config('HIM_PASSWORD')
# Create your models here.
class ICD10CodeCategory(models.Model):
def __str__(self):
return '%s' %self.description
identifier = models.CharField(max_length=100)
description = models.CharField(max_length=255)
class Meta:
db_table="ICD10CodeCategories"
verbose_name_plural = "ICD10 Code Categories"
class ICD10CodeSubCategory(models.Model):
def __str__(self):
return '%s' % self.description
identifier = models.CharField(max_length=100)
category = models.ForeignKey(ICD10CodeCategory,related_name='sub_category', on_delete=models.DO_NOTHING, null=True, blank=True)
description = models.CharField(max_length=255)
class Meta:
db_table = "ICD10CodeSubCategories"
verbose_name_plural = "ICD10 Code Sub Categories"
class ICD10Code(models.Model):
def __str__(self):
return '%s' %self.description
sub_category = models.ForeignKey(ICD10CodeSubCategory,related_name='code', on_delete=models.DO_NOTHING, null=True, blank=True)
code = models.CharField(max_length=255)
description = models.CharField(max_length=255)
class Meta:
db_table="ICD10Codes"
verbose_name_plural = "ICD10 Codes"
class ICD10SubCode(models.Model):
def __str__(self):
return '%s' %self.description
code = models.ForeignKey(ICD10Code,related_name='sub_code',on_delete=models.DO_NOTHING, null=True, blank=True)
sub_code = models.CharField(max_length=255)
description = models.CharField(max_length=255)
is_active = models.BooleanField(default=True)
class Meta:
db_table="ICD10SubCodes"
verbose_name_plural = "ICD10 SubCodes"
class CPTCodeCategory(models.Model):
def __str__(self):
return '%s' %self.description
description = models.CharField(max_length=255)
class Meta:
db_table="CPTCodeCategories"
verbose_name_plural = "CPT Code Categories"
class CPTCodeSubCategory(models.Model):
def __str__(self):
return '%s' % self.description
category = models.ForeignKey(CPTCodeCategory, related_name='sub_category',on_delete=models.DO_NOTHING, null=True, blank=True)
description = models.CharField(max_length=255)
class Meta:
db_table = "CPTCodeSubCategories"
verbose_name_plural = "CPT Code Sub Categories"
class CPTCode(models.Model):
def __str__(self):
return '%s' %self.description
sub_category = models.ForeignKey(CPTCodeSubCategory,related_name='code', on_delete=models.DO_NOTHING, null=True, blank=True)
code = models.CharField(max_length=255)
description = models.CharField(max_length=255)
is_active = models.BooleanField(default=True)
class Meta:
db_table = "CPTCodes"
verbose_name = "CPT Code"
class CPTCodesMapping(models.Model):
def __str__(self):
return '%d' % self.id
cpt_code = models.ForeignKey(CPTCode, on_delete=models.DO_NOTHING, null=True, blank=True)
local_code = models.CharField(max_length=255)
facility = models.ForeignKey(master_data_models.Facility, on_delete=models.DO_NOTHING, null=True,
blank=True)
class Meta:
db_table = "CPTCodesMappings"
@receiver(post_save, sender=ICD10SubCode)
def send_new_or_updated_icd10_code(sender, instance, created, **kwargs):
icd10_code_id = instance.code_id
icd10_code = ICD10Code.objects.get(id=icd10_code_id)
icd10_sub_category_id = icd10_code.sub_category_id
icd10_diagnoses_code = icd10_code.code
icd10_description = icd10_code.description
icd10_sub_category = ICD10CodeSubCategory.objects.get(id=icd10_sub_category_id)
icd10_sub_category_description = icd10_sub_category.description
icd10_sub_category_identifier = icd10_sub_category.identifier
icd10_category_id = icd10_sub_category.category_id
icd10_category = ICD10CodeCategory.objects.get(id=icd10_category_id)
icd10_category_description = icd10_category.description
icd10_category_identifier = icd10_category.identifier
item = dict()
item["icd10_category_identifier"] = icd10_category_identifier
item["icd10_category_description"] = icd10_category_description
item["icd10_sub_category_identifier"] = icd10_sub_category_identifier
item["icd10_sub_category_description"] = icd10_sub_category_description
item["icd10_code"] = icd10_diagnoses_code
item["icd10_code_description"] = icd10_description
item["icd10_sub_code"] = instance.sub_code
item["icd10_sub_code_description"] = instance.description
json_data = json.dumps(item)
requests.post(him_icd_url,auth=(him_username, him_password),data=json_data,
headers={'User-Agent': 'XY', 'Content-type': 'application/json'})
@receiver(post_save, sender=CPTCode)
def send_new_or_updated_cpt_code(sender, instance, created, **kwargs):
cpt_code_sub_category_id = instance.sub_category_id
cpt_code = instance.code
cpt_description = instance.description
cpt_code_sub_category = CPTCodeSubCategory.objects.get(id=cpt_code_sub_category_id)
cpt_code_category_id = cpt_code_sub_category.category_id
cpt_code_sub_category_description = cpt_code_sub_category.description
cpt_code_category = CPTCodeCategory.objects.get(id=cpt_code_category_id)
cpt_code_category_description = cpt_code_category.description
item = dict()
item["cpt_category_description"] = cpt_code_category_description
item["cpt_sub_category_description"] = cpt_code_sub_category_description
item["cpt_code"] = cpt_code
item["cpt_code_description"] = cpt_description
json_data = json.dumps(item)
requests.post(him_cpt_url, auth=(him_username, him_password),data=json_data,
headers={'User-Agent': 'XY', 'Content-type': 'application/json'})