diff --git a/netforce_clinic/actions/clinic_data_sc.xml b/netforce_clinic/actions/clinic_data_sc.xml
index bd2364f..ea766c8 100644
--- a/netforce_clinic/actions/clinic_data_sc.xml
+++ b/netforce_clinic/actions/clinic_data_sc.xml
@@ -1,7 +1,7 @@
Social Security
multi_view
- [["All",[]],["Success",[["type","=","success"]]],["Fail",[["type","=","fail"]]]]
+ [["All",[]],["Match",[["type","=","match"]]],["Not Match",[["type","=","not_match"]]]]
clinic.data.sc
account_menu
diff --git a/netforce_clinic/layouts/clinic_data_sc_form.xml b/netforce_clinic/layouts/clinic_data_sc_form.xml
index 62b6553..fc67863 100644
--- a/netforce_clinic/layouts/clinic_data_sc_form.xml
+++ b/netforce_clinic/layouts/clinic_data_sc_form.xml
@@ -11,4 +11,5 @@
+
diff --git a/netforce_clinic/layouts/clinic_data_sc_list.xml b/netforce_clinic/layouts/clinic_data_sc_list.xml
index a4e40ca..6eb8467 100644
--- a/netforce_clinic/layouts/clinic_data_sc_list.xml
+++ b/netforce_clinic/layouts/clinic_data_sc_list.xml
@@ -1,4 +1,4 @@
-
+
@@ -11,4 +11,5 @@
+
diff --git a/netforce_clinic/layouts/clinic_input_data_form.xml b/netforce_clinic/layouts/clinic_input_data_form.xml
deleted file mode 100644
index 89d5e99..0000000
--- a/netforce_clinic/layouts/clinic_input_data_form.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml
index a8a10b1..dbc144c 100644
--- a/netforce_clinic/layouts/clinic_patient_form.xml
+++ b/netforce_clinic/layouts/clinic_patient_form.xml
@@ -3,7 +3,8 @@
diff --git a/netforce_clinic/layouts/clinic_setting.xml b/netforce_clinic/layouts/clinic_setting.xml
index fcc4564..d97ef89 100644
--- a/netforce_clinic/layouts/clinic_setting.xml
+++ b/netforce_clinic/layouts/clinic_setting.xml
@@ -3,12 +3,15 @@
-
-
+
+
+
+
+
diff --git a/netforce_clinic/layouts/import_clinic_sc.xml b/netforce_clinic/layouts/import_clinic_sc.xml
index 439279e..8d3f2fe 100644
--- a/netforce_clinic/layouts/import_clinic_sc.xml
+++ b/netforce_clinic/layouts/import_clinic_sc.xml
@@ -12,5 +12,8 @@
+
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index e90dbd6..ab59ba4 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -25,7 +25,6 @@ from . import hd_case_payment
from . import dialyzer
from . import dialyzer_line
from . import import_payment
-from . import file_sheet
from . import cycle
from . import cycle_item
from . import cycle_item_line
@@ -34,7 +33,7 @@ from . import gen_visit_line
from . import report_hd_detail
from . import report_hd_summary
from . import report_hd_medical
-from . import input_data
+from . import report_hd_payment
from . import fin_setting
from . import import_data_mg
from . import import_data_nhso
@@ -43,5 +42,4 @@ from . import translate
from . import payment
from . import account_payment
from . import account_invoice
-from . import report_hd_payment
from . import personal_categ
diff --git a/netforce_clinic/models/cycle_item.py b/netforce_clinic/models/cycle_item.py
index 903bf87..b38bfe1 100644
--- a/netforce_clinic/models/cycle_item.py
+++ b/netforce_clinic/models/cycle_item.py
@@ -126,6 +126,7 @@ class CycleItem(Model):
'amount': qty*rate,
}))
print("qty * rate ", qty, ' ', rate)
+ # x=(pt*k+n2*100+n3*250-n4*25-n5*25+n6*75)/(n1+n2+n3+0.5*(n4+n5+n6))
obj.write(vals)
@@ -197,7 +198,7 @@ class CycleItem(Model):
'amount': line.amount,
}))
- payment_id=get_model("account.payment").create(vals,context={"type":"in"})
+ payment_id=get_model("account.payment").create(vals,context={"type":"out"})
#get_model("account.payment").browse(payment_id).post()
obj.write({
'state': 'done',
diff --git a/netforce_clinic/models/file_sheet.py b/netforce_clinic/models/file_sheet.py
deleted file mode 100644
index c334019..0000000
--- a/netforce_clinic/models/file_sheet.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from netforce.model import Model, fields
-
-class FileSheet(Model):
- _name="clinic.file.sheet"
- _string="File Sheet"
-
- _fields={
- 'name': fields.Char("Name"),
- 'index': fields.Integer("Index"),
- "select": fields.Selection([("yes","Yes"),("no","No")],"Select"),
- 'imp_id': fields.Many2One("clinic.import.payment","Import Payment"),
- }
-
-FileSheet.register()
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 702790c..c9e134a 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -465,7 +465,7 @@ class HDCase(Model):
def create_cycle_item(self,ids,context={}):
for obj in self.browse(ids):
cycle_item=get_model("clinic.cycle.item")
- datenow=obj.start_time[0:10]
+ datenow=obj.time_start[0:10]
if not datenow:
datenow=time.strftime('%Y-%m-%d')
cycle_id=obj.cycle_id.id
@@ -491,6 +491,8 @@ class HDCase(Model):
obj.write({
"state":"completed",
})
+ if context.get("called"):
+ return obj.id
return {
'next': {
'name': 'clinic_hd_case',
@@ -651,7 +653,6 @@ class HDCase(Model):
dlz_vals['company_id']=dlz_vals['company_id'][0]
product_name=dlz_vals['product_id'][1]
dlz_vals['product_id']=dlz_vals['product_id'][0]
-
dlz_id=get_model('clinic.dialyzer').create(dlz_vals)
dialyzer=get_model("clinic.dialyzer").browse(dlz_id)
dialyzer.confirm()
@@ -671,6 +672,8 @@ class HDCase(Model):
'state': dialyzer.state,
}))
obj.write(vals)
+ if context.get('called'):
+ return obj.id
return {
'next': {
'name': 'clinic_hd_case',
diff --git a/netforce_clinic/models/import_data_sc.py b/netforce_clinic/models/import_data_sc.py
index 197851a..982532d 100644
--- a/netforce_clinic/models/import_data_sc.py
+++ b/netforce_clinic/models/import_data_sc.py
@@ -15,8 +15,11 @@ class ImportDataSC(Model):
'st': fields.Char('st'),
'allow37': fields.Char('allow37'),
'dttran': fields.Date("dttran"),
- 'type': fields.Selection([['success','Succes'],['fail','Fail']],'Type', search=True),
+ 'type': fields.Selection([['match','Match'],['not_match','Not Match']],'Type', search=True),
+ 'hd_case_id': fields.Many2One("clinic.hd.case","HD Case"),
+ #'invoice_id': fields.Many2One("clinic.hd.case","HD Case"),
}
+ _order="type"
ImportDataSC.register()
diff --git a/netforce_clinic/models/import_payment.py b/netforce_clinic/models/import_payment.py
index c2c76ac..aadbe05 100644
--- a/netforce_clinic/models/import_payment.py
+++ b/netforce_clinic/models/import_payment.py
@@ -129,6 +129,15 @@ class ImportPayment(Model):
old_patient=[x['hn'] for x in patient.search_read([],['hn']) if x['hn']]
fail_qty=0
success_qty=0
+
+ hd_cases=get_model("clinic.hd.case").search_browse([['state','=','completed']])
+
+ def get_hdcase(hn,date):
+ for hd_case in hd_cases:
+ hd_date=hd_case.time_start[0:10]
+ if hn==hd_case.patient_id.hn and date==hd_date: #XXX
+ return hd_case.id
+
for line in lines:
hn=line.get('hn')
if not hn:
@@ -144,11 +153,18 @@ class ImportPayment(Model):
st.update({hn: line.get('name14')})
print("create %s ok"%hn)
hcode=int((line.get('hcode18') or "0")) # XXX
- type=hcode==23869 and 'success' or 'fail'
- if type=='success':
+ type='match'
+ if hcode!=(int(obj.hcode)):
+ continue
+
+ dttran=line.get("dttran","")
+ hd_case_id=get_hdcase(hn,dttran)
+ if hd_case_id:
success_qty+=1
else:
fail_qty+=1
+ type='not_match'
+
vals={
'hn': hn,
'name14': line.get('name14'),
@@ -162,6 +178,7 @@ class ImportPayment(Model):
'allow37': line.get('allow37'),
'dttran': line.get("dttran"),
'type': type,
+ 'hd_case_id': hd_case_id,
}
data_sc.create(vals)
msg=''
@@ -182,5 +199,63 @@ class ImportPayment(Model):
def test_sc(self,ids,context={}):
pass
+
+ def clear_sc(self,ids,context={}):
+ sc_ids=get_model("clinic.data.sc").search([])
+ get_model("clinic.data.sc").delete(sc_ids)
+ obj=self.browse(ids)[0]
+ obj.write({
+ 'result': 'Clear OK',
+ })
+
+ def match_invoice_sc(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
+ for invoice in sc.hd_case_id.invoices:
+ print(invoice.number)
+
+ obj.write({
+ 'result': 'Match OK',
+ })
+
+ def post_sc(self,ids,context={}):
+ settings=get_model("settings").browse(1)
+ account_id=settings.ap_sc_id.id
+ if not account_id:
+ raise Exception("No Account payment for Social Security")
+ obj=self.browse(ids)[0]
+ vals={
+ 'partner_id': '',
+ "company_id": get_active_company(),
+ "type": "in",
+ "pay_type": "invoice",
+ "date": obj.date or time.strftime("%Y-%m-%d"),
+ "account_id": account_id,
+ 'invoice_lines': [],
+ }
+ invoice_ids=[]
+ partner_id=None
+ for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
+ if not partner_id:
+ partner_id=sc.hd_case_id.fee_partner_id.id
+ for invoice in sc.hd_case_id.invoices:
+ invoice_ids.append(invoice.id)
+ vals['invoice_lines'].append(('create',{
+ 'invoice_id': invoice.id,
+ 'amount': invoice.amount_due or 0.0,
+ }))
+ sc.delete() #XXX
+ vals['partner_id']=partner_id
+ payment_id=get_model("account.payment").create(vals,context={"type":"in"})
+ #get_model("account.payment").browse(payment_id).post()
+ return {
+ 'next': {
+ 'name': 'payment',
+ 'mode': 'form',
+ 'active_id': payment_id,
+ },
+ 'flash': 'Paid',
+ }
+
ImportPayment.register()
diff --git a/netforce_clinic/models/input_data.py b/netforce_clinic/models/input_data.py
deleted file mode 100644
index 4839332..0000000
--- a/netforce_clinic/models/input_data.py
+++ /dev/null
@@ -1,18 +0,0 @@
-from netforce.model import Model, fields, get_model
-
-class InputData(Model):
- _name="clinic.input.data"
- _transient=True
-
- _fields={
- 'date': fields.Date("Date"),
- 'name': fields.Char("Patient Name"),
- 'hn': fields.Char("HN"),
- 'amount': fields.Char("Amount"),
- 'hct': fields.Char("HCT"),
- 'medical_type': fields.Char("Medical Type"),
- 'medical_cost': fields.Char("Medical Cost"),
- 'other_cost': fields.Char("Other Cost"),
- }
-
-InputData.register()
diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py
index fb7c1d4..d70727f 100644
--- a/netforce_clinic/models/patient.py
+++ b/netforce_clinic/models/patient.py
@@ -247,5 +247,49 @@ class Patient(Model):
ids3=self.search(dom)
ids=list(set(ids1+ids2+ids3))
return self.name_get(ids,context=context)
+
+ def simple_address(self,ids,context={}):
+ print("call simple address ")
+ for obj in self.browse(ids):
+ if not obj.addresses:
+ addr_id=get_model("address").create({
+ 'patient_id': obj.id,
+ 'partner_id': obj.partner_id.id,
+ 'type': 'shipping',
+ 'address': 'xxxx',
+ 'address2': 'xxxx',
+ 'city': 'BKK',
+ 'country_id': 1,
+ 'postal_code': '12000',
+ })
+ if context.get('called'):
+ return obj.id
+ return {
+ 'next': {
+ 'name': 'clinic_patient',
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },'flash': 'Simple Address OK',
+ }
+
+ def new_dialyzer(self,ids,context={}):
+ dlz_id=None
+ for obj in self.browse(ids):
+ dlz_vals=get_model("clinic.dialyzer").default_get()
+ dlz_vals['patient_id']=obj.id
+ dlz_vals['company_id']=dlz_vals['company_id'][0]
+ dlz_vals['product_id']=dlz_vals['product_id'][0]
+ dlz_id=get_model('clinic.dialyzer').create(dlz_vals)
+ dialyzer=get_model("clinic.dialyzer").browse(dlz_id)
+ dialyzer.confirm()
+ if context.get('called'):
+ return dlz_id
+ return {
+ 'next': {
+ 'name': 'clinic_patient',
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },'flash': 'New Dialyzer successfully',
+ }
Patient.register()
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index 4cd17cc..543260a 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -15,6 +15,7 @@ class ClinicSetting(Model):
"var_k": fields.Float("K"),
'file': fields.File("File"),
}
+
def read_excel(self,fpath=None):
data={}
if fpath:
@@ -42,7 +43,7 @@ class ClinicSetting(Model):
data.append(d)
return data
- def read_cash(self,ids,context={}):
+ def make_visit(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
@@ -52,32 +53,18 @@ class ClinicSetting(Model):
medicals=[]
patients=[]
for line in lines:
- medical=line['medical'] or ""
+ medical=line.get('medical') or line.get('eponame') or ""
if not medical in medicals:
medicals.append(medical)
- patient=line['hn'] or ""
- name14=line['name14'] or ""
+ patient=line.get('hn','')
+ name14=line.get('name14') or ""
value=(patient,name14)
if not value in patients:
patients.append(value)
- #vals={
- #'hn': hn,
- #'name14': line.get('name14'),
- #'hcode18': hcode,
- #'amount23': line.get('amount23'),
- #"cur": line.get('cur'),
- #'epoadm29': line.get('epoadm29'),
- #'eponame': line.get('eponame'),
- #'ln': line.get('ln'),
- #'st': line.get('st'),
- #'allow37': line.get('allow37'),
- #'dttran': line.get("dttran"),
- #'type': type,
- #}
products=[p['name'] for p in get_model("product").search_read([],['name'])]
print('generate product')
print("="*50)
- seq=1
+ seq=6
for md in medicals:
md=md.replace(" ","")
if not md:
@@ -122,20 +109,13 @@ class ClinicSetting(Model):
return pt
return None
- def get_visit(date,cycle_name=None,state=None):
+ def get_visit(date,state=None):
for visit in visits:
if date==visit['time_start'][0:10]:
if state:
- print(state, " ", visit['state'])
if visit['state']==state:
- if cycle_name:
- if cycle_name==visit['cycle_id'][1]:
- return visit
- else:
- return None
return visit
else:
- print("else ")
return None
return visit
print("="*50)
@@ -165,22 +145,25 @@ class ClinicSetting(Model):
print("create visit %s ", visit_id)
print("="*50)
print("visit with state is draft")
+ return #XXXX
count=0
for line in lines:
date=line['dttran']
# prevent timeout
if count > 10:
break
+ #print(date)
visit=get_visit(date=date,state='draft')
+ print(date, ' ', visit)
if visit:
visit_id=visit['id']
context['called']=True
hd_case_id=get_model("clinic.visit").browse(visit_id).confirm(context=context)
#allow37=line['allow37']
- hct=line['hct']
- medical=line['medical']
- medical_cost=line['medical_cost']
- inject_service=line['inject_service']
+ hct=line.get('hct')
+ medical=line.get('medical') or line.get("eponame") or ""
+ medical_cost=line.get('medical_cost') or line.get('allow37') or 0.0
+ inject_service=line.get('inject_service') or line.get("epoadm29") or ""
vals={
'hct': hct and hct or 0,
'lines': [],
@@ -215,5 +198,78 @@ class ClinicSetting(Model):
print("="*50)
print("Done")
return
+
+ def make_done(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ fname=obj.file
+ fpath=get_file_path(fname)
+ lines=self.read_excel(fpath)
+ if not lines:
+ raise Exception("Wrong File")
+ def get_line(hn,date):
+ for line in lines:
+ if hn==line['hn'] and date==line['dttran']:
+ return line
+ count=0
+ for visit in get_model("clinic.visit").search_browse([['state','=','draft']]):
+ if count > 200:
+ break
+ count+=1
+ context['called']=True
+ hd_case_id=visit.confirm(context=context)
+ hn=visit.patient_id.hn
+ date_visit=visit.time_start[0:10]
+ line=get_line(hn,date_visit)
+ if line:
+ hct=line.get('hct')
+ medical=line.get('medical') or line.get('eponame') or ""
+ medical_cost=line.get('medical_cost') or line.get("allow37") or ""
+ inject_service=line.get('inject_service') or line.get("EPOadm29") or ""
+ vals={
+ 'hct': hct and hct or 0,
+ 'lines': [],
+ }
+ if medical:
+ prods=get_model("product").search_browse([['name','=',medical]])
+ if prods:
+ prod=prods[0]
+ vals['lines'].append(('create',{
+ 'type': 'fee',
+ 'product_id': prod.id,
+ 'description': prod.name,
+ 'uom_id': prod.uom_id.id,
+ 'qty': 1,
+ 'price': medical_cost,
+ 'amount': medical_cost,
+ }))
+ if inject_service:
+ prod=get_model("product").browse(55)
+ vals['lines'].append(('create',{
+ 'type': 'other',
+ 'product_id': 55, #XXX
+ 'description': prod.name,
+ 'uom_id': prod.uom_id.id,
+ 'qty': 1,
+ 'price': medical_cost,
+ 'amount': medical_cost,
+ }))
+ hd_case=get_model("clinic.hd.case").browse(hd_case_id)
+ hd_case.write(vals)
+ print("#%s make hd_case %s ok "%(count,hd_case.number))
+
+ def make_complete(self,ids,context={}):
+ context['called']=True
+ count=0
+ for hd_case in get_model('clinic.hd.case').search_browse(['state','=','draft']):
+ if count > 100:
+ break
+ if not hd_case.dialyzers:
+ patient=hd_case.patient_id
+ if not patient.addresses:
+ patient.simple_address()
+ hd_case.new_dialyzer(context=context)
+ hd_case.complete()
+ print("%s is completed"%hd_case.number)
+ count+=1
ClinicSetting.register()
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index 5f13d1c..c6c47d1 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -130,6 +130,19 @@ class Visit(Model):
'amount': product.sale_price or 0.0,
'uom_id': product.uom_id.id,
}))
+ if obj.patient_id.type=='sc':
+ products=get_model("product").search_browse([['code','=','S0001']]) #XXX
+ for product in products:
+ vals['lines'].append(('create',{
+ 'type': 'fee',
+ 'product_id': product.id,
+ 'description': product.name or "",
+ 'qty': 1,
+ 'price': product.sale_price or 0.0,
+ 'amount': product.sale_price or 0.0,
+ 'uom_id': product.uom_id.id,
+ }))
+
patient_type={
"mg":"Medical Government",