treatment

conv_bal
watcha.h 2014-10-05 01:33:18 +07:00
parent a27ef19307
commit 53670f8f8d
10 changed files with 127 additions and 141 deletions

View File

@ -2,7 +2,7 @@
<field name="string">Treatments</field> <field name="string">Treatments</field>
<field name="view_cls">multi_view</field> <field name="view_cls">multi_view</field>
<field name="model">clinic.hd.case</field> <field name="model">clinic.hd.case</field>
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]],["Approved",[["state","=","approved"]]],["Paid",[["state","=","paid"]]],["Cancelled",[["state","=","cancelled"]]]]</field> <field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["In Progress",[["state","=","in_progress"]]],["Completed",[["state","=","completed"]]],["Incomplete",[["state","=","fail"]]],["Cancelled",[["state","=","cancelled"]]]]</field>
<field name="modes">list,form</field> <field name="modes">list,form</field>
<field name="menu">clinic_menu</field> <field name="menu">clinic_menu</field>
</action> </action>

View File

@ -22,17 +22,19 @@
<tab string="Dialyzer"> <tab string="Dialyzer">
<field name="dialyzers" nolabel="1"> <field name="dialyzers" nolabel="1">
<list> <list>
<field name="dialyzer_id"/> <field name="dialyzer_id" domain="[['patient_id','=',parent.patient_id]]" onchange="onchange_dialyzer"/>
<field name="description"/>
<field name="use_time"/> <field name="use_time"/>
<field name="max_use_time"/> <field name="max_use_time"/>
<field name="member_type"/> <field name="member_type"/>
<field name="dialyzer_type"/> <field name="dialyzer_type"/>
<field name="bid_flow_rate"/> <field name="bid_flow_rate"/>
<field name="ultrafittration"/> <field name="ultrafittration"/>
<field name="state"/>
</list> </list>
</field> </field>
</tab> </tab>
<tab string="Healthy History"> <tab string="Healthy Notes">
<field name="wh_start"/> <field name="wh_start"/>
<field name="wh_stop"/> <field name="wh_stop"/>
<field name="bp_start"/> <field name="bp_start"/>
@ -41,6 +43,10 @@
<field name="per_bp_stop"/> <field name="per_bp_stop"/>
<field name="hct"/> <field name="hct"/>
</tab> </tab>
<tab string="Others">
<separator string="Accounting"/>
<field name="paid" readonly="1"/>
</tab>
</tabs> </tabs>
<separator string="Others Payment"/> <separator string="Others Payment"/>
<field name="lines" count="4" nolabel="1"> <field name="lines" count="4" nolabel="1">
@ -65,10 +71,9 @@
<field name="amount"/> <field name="amount"/>
</group> </group>
<foot> <foot>
<button string="Confirm" type="success" method="confirm" states="draft" /> <button string="Confirm" type="success" method="confirm" states="draft"/>
<button string="Validate" type="success" method="approve" states="confirmed"/> <button string="Complete" type="success" method="complete" states="in_progress"/>
<!--<button string="Validate" type="success" method="validate" states="confirmed" />--> <button string="Reject" type="danger" method="reject" states="in_progress"/>
<button string="Pay" type="success" method="paid" states="approved" />
</foot> </foot>
<related> <related>
<field name="invoices" click_action="view_invoice"/> <field name="invoices" click_action="view_invoice"/>

View File

@ -8,18 +8,21 @@
<field name="mg_file"/> <field name="mg_file"/>
<group span="6"> <group span="6">
<field name="mg_payment_id" readonly="1"/> <field name="mg_payment_id" readonly="1"/>
<button string="Post" type="success" method="post_mg"/>
<button string="Undo" type="danger" method="undo_mg" attrs='{"invisible":[["state","in",["success"]]]}'/> <button string="Undo" type="danger" method="undo_mg" attrs='{"invisible":[["state","in",["success"]]]}'/>
</group> </group>
<separator string="Social Security"/> <separator string="Social Security"/>
<field name="sc_file"/> <field name="sc_file"/>
<group span="6"> <group span="6">
<field name="sc_payment_id" readonly="1"/> <field name="sc_payment_id" readonly="1"/>
<button string="Post" type="success" method="post_sc"/>
<button string="Undo" type="danger" method="undo_sc" attrs='{"invisible":[["state","in",["success"]]]}'/> <button string="Undo" type="danger" method="undo_sc" attrs='{"invisible":[["state","in",["success"]]]}'/>
</group> </group>
<separator string="NHSO (30฿)"/> <separator string="NHSO (30฿)"/>
<field name="nhso_file"/> <field name="nhso_file"/>
<group span="6"> <group span="6">
<field name="nhso_payment_id" readonly="1"/> <field name="nhso_payment_id" readonly="1"/>
<button string="Post" type="success" method="post_nhso"/>
<button string="Undo" type="danger" method="undo_nhso" attrs='{"invisible":[["state","in",["success"]]]}'/> <button string="Undo" type="danger" method="undo_nhso" attrs='{"invisible":[["state","in",["success"]]]}'/>
</group> </group>
<foot> <foot>

View File

@ -15,13 +15,29 @@
<field name="time_use"/> <field name="time_use"/>
</group> </group>
<group span="6" columns="1"> <group span="6" columns="1">
<field name="department_id"/>
<field name="patient_id" onchange="onchange_patient"/> <field name="patient_id" onchange="onchange_patient"/>
<field name="doctor_id"/> <field name="doctor_id"/>
<field name="nurse_id"/> <field name="nurse_id"/>
<field name="department_id"/>
</group> </group>
</tab> </tab>
</tabs> </tabs>
<group attrs='{"invisible": [["state","not in",["waiting_treatment"]]]}'>
<separator string="Select Dialyzer -> Click Do Treatment"/>
<field name="dialyzers" nolabel="1" count="3">
<list>
<field name="dialyzer_id" domain="[['state','=','active'],['patient_id','=',parent.patient_id]]" onchange="onchange_dialyzer"/>
<field name="description"/>
<field name="use_time"/>
<field name="max_use_time"/>
<field name="member_type"/>
<field name="dialyzer_type"/>
<field name="bid_flow_rate"/>
<field name="ultrafittration"/>
<field name="state"/>
</list>
</field>
</group>
<foot> <foot>
<button string="Confirm" type="success" method="confirm" states="draft" /> <button string="Confirm" type="success" method="confirm" states="draft" />
<button string="Do Treatment" type="success" method="do_treatment" icon="arrow-right" states="waiting_treatment" /> <button string="Do Treatment" type="success" method="do_treatment" icon="arrow-right" states="waiting_treatment" />

View File

@ -8,9 +8,10 @@ from . import doctor
from . import nurse from . import nurse
from . import visit from . import visit
from . import hd_case from . import hd_case
from . import hd_case_dialyzer #from . import hd_case_dialyzer
from . import hd_case_line from . import hd_case_line
from . import dialyzer from . import dialyzer
from . import dialyzer_line
from . import department from . import department
from . import education from . import education
from . import setting from . import setting

View File

@ -16,7 +16,6 @@ class Dialyzer(Model):
"use_time": fields.Integer("Use Time"), "use_time": fields.Integer("Use Time"),
"max_use_time": fields.Integer("Max Use Time"), "max_use_time": fields.Integer("Max Use Time"),
"exp_date": fields.Date("Expiry Date",search=True), "exp_date": fields.Date("Expiry Date",search=True),
"patient_id": fields.Many2One("clinic.patient","Patient"),
"member_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"), "member_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"),
"dialyzer_type": fields.Selection([("low","low flux"),("high","high flux"),("dbl","dbl hifulx")],"Dialyzer Type"), "dialyzer_type": fields.Selection([("low","low flux"),("high","high flux"),("dbl","dbl hifulx")],"Dialyzer Type"),
"bid_flow_rate": fields.Integer("Bid Flow Rate (ml/min)",search=True), "bid_flow_rate": fields.Integer("Bid Flow Rate (ml/min)",search=True),
@ -26,6 +25,9 @@ class Dialyzer(Model):
"company_id": fields.Many2One("company","Company"), "company_id": fields.Many2One("company","Company"),
'product_id': fields.Many2One("product", "Product",required=True), 'product_id': fields.Many2One("product", "Product",required=True),
"pickings": fields.One2Many("stock.picking","related_id","Pickings"), "pickings": fields.One2Many("stock.picking","related_id","Pickings"),
"patient_id": fields.Many2One("clinic.patient","Patient"),
"visit_id": fields.Many2One("clinic.visit","Visit"),
"hd_case_id": fields.Many2One("clinic.hd.case","HD Case"),
} }
def _get_number(self,context={}): def _get_number(self,context={}):

View File

@ -0,0 +1,20 @@
from netforce.model import Model, fields
class DialyzerLine(Model):
_name="clinic.dialyzer.line"
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",on_delete="cascade"),
"visit_id": fields.Many2One("clinic.visit","Visit",on_delete="cascade"),
"dialyzer_id": fields.Many2One("clinic.dialyzer","Dialzer",search=True),
"description": fields.Char("Description",search=True),
"use_time":fields.Integer("Use time"),
"max_use_time":fields.Integer("Max use time"),
"member_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Member Type"),
"dialyzer_type": fields.Selection([("low","low flux"),("high","high flux"),("dbl","dbl hifulx")],"Member Type"),
"bid_flow_rate": fields.Integer("Bid Flow Rate (ml/min)"),
"ultrafittration": fields.Float("Ultrafittration Kg."),
"state":fields.Selection([("draft","New"),("active","Active"),("drop","Drop")],"Status"),
}
DialyzerLine.register()

View File

@ -37,8 +37,8 @@ class HDcase(Model):
"bp_stop": fields.Integer("BP mmHG stop"), "bp_stop": fields.Integer("BP mmHG stop"),
"per_bp_stop": fields.Integer("/Per stop"), "per_bp_stop": fields.Integer("/Per stop"),
"hct": fields.Integer("HCT %"), "hct": fields.Integer("HCT %"),
"state": fields.Selection([("draft","Draft"),("confirmed","Confirmed"),("approved","Approved"),("cancelled","Cancelled"),("paid","Paid")],"Status",required=True), "state": fields.Selection([("draft","Draft"),("in_progress","In Progress"),("completed","Completed"),("cancelled","Cancelled"),("incomplete","Incomplete")],"Status",required=True),
"dialyzers": fields.One2Many("clinic.hd.case.dialyzer","hd_case_id","Dializers"), "dialyzers": fields.One2Many("clinic.dialyzer.line","hd_case_id","Dializers"),
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"), "lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"),
"comments": fields.One2Many("message","related_id","Comments"), "comments": fields.One2Many("message","related_id","Comments"),
"company_id": fields.Many2One("company","Company"), "company_id": fields.Many2One("company","Company"),
@ -53,6 +53,7 @@ class HDcase(Model):
'total_time': fields.Integer("Total Time(Hrs)",function="get_hrs"), 'total_time': fields.Integer("Total Time(Hrs)",function="get_hrs"),
"fee_type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("others","Others")],"Fee Type"), "fee_type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("others","Others")],"Fee Type"),
'fee_partner_id': fields.Many2One("partner","Fee Contact"), 'fee_partner_id': fields.Many2One("partner","Fee Contact"),
'paid': fields.Boolean("Paid"),
} }
def _get_number(self,context={}): def _get_number(self,context={}):
@ -92,11 +93,11 @@ class HDcase(Model):
data=context["data"] data=context["data"]
path=context["path"] path=context["path"]
line=get_data_path(data,path,parent=True) line=get_data_path(data,path,parent=True)
dialyzer_id=line.get("dialzer_id") dialyzer_id=line.get("dialyzer_id")
if not dialyzer_id: if not dialyzer_id:
return {} return {}
dialyzer=get_model("clinic.dialyzer").browse(dialyzer_id) dialyzer=get_model("clinic.dialyzer").browse(dialyzer_id)
line["detail"]=dialyzer.detail line["description"]=dialyzer.description or ""
line["use_time"]=dialyzer.use_time line["use_time"]=dialyzer.use_time
line["max_use_time"]=dialyzer.max_use_time line["max_use_time"]=dialyzer.max_use_time
line["member_type"]=dialyzer.member_type line["member_type"]=dialyzer.member_type
@ -167,7 +168,7 @@ class HDcase(Model):
# XXX # XXX
context['type']='out' context['type']='out'
context['inv_type']='invoice' context['inv_type']='invoice'
if obj.lines: if obj.lines and obj.total:
# XXX need to split function prepare invoice # XXX need to split function prepare invoice
vals={ vals={
"type": "out", "type": "out",
@ -293,112 +294,29 @@ class HDcase(Model):
def confirm(self,ids,context={}): def confirm(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
obj.write({"state":"confirmed"}) obj.write({"state":"in_progress"})
def paid(self,ids,context={}): def reject(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
obj.write({"state":"paid"}) obj.write({"state":"cancelled"})
def approve(self,ids,context={}): def complete(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
obj.make_invoices() obj.make_invoices()
obj.post_invoices() obj.post_invoices()
obj.write({"state":"approved"}) obj.write({
"state":"completed",
'paid': True,
})
return { return {
'next': { 'next': {
'name': 'clinic_hd_case', 'name': 'clinic_hd_case',
'mode': 'form', 'mode': 'form',
'active_id': obj.id, 'active_id': obj.id,
}, },
'flash': '%s has been approved'%obj.number, 'flash': '%s is completed'%obj.number,
} }
def approved(self,ids,context={}):
for obj in self.browse(ids):
user_id=get_active_user()
try:
set_active_user(1)
settings=get_model("clinic.setting").browse(1)
reconcile_id=get_model("account.reconcile").create({})
if obj.patient_id.type == 'mg':
vals={
"narration": obj.number,
"lines": [
("create",{
"description": obj.number,
"account_id": settings.ar_mg_id.id,
"debit": obj.amount,
"credit": 0,
"partner_id": settings.mg_partner_id.id,
"due_date": obj.date,
"reconcile_id":reconcile_id,
}),
("create",{
"description": obj.number,
"account_id": settings.ap_mg_id.id,
"debit": 0,
"credit": obj.amount,
}),
],
"state": "posted",
"date_posted": obj.date,
"date": obj.date,
}
get_model("account.move").create(vals)
elif obj.patient_id.type == 'sc':
vals={
"narration": obj.number,
"lines": [
("create",{
"description": obj.number,
"account_id": settings.ar_sc_id.id,
"debit": obj.amount,
"credit": 0,
"partner_id": settings.sc_partner_id.id,
"due_date": obj.date,
"reconcile_id":reconcile_id,
}),
("create",{
"description": obj.number,
"account_id": settings.ap_sc_id.id,
"debit": 0,
"credit": obj.amount,
}),
],
"state": "posted",
"date_posted": obj.date,
"date": obj.date,
}
get_model("account.move").create(vals)
elif obj.patient_id.type == 'nhso':
vals={
"narration": obj.number,
"lines": [
("create",{
"description": obj.number,
"account_id": settings.ar_nhso_id.id,
"debit": obj.amount,
"credit": 0,
"partner_id": settings.nhso_partner_id.id,
"due_date": obj.date,
"reconcile_id":reconcile_id,
}),
("create",{
"description": obj.number,
"account_id": settings.ap_nhso_id.id,
"debit": 0,
"credit": obj.amount,
}),
],
"state": "posted",
"date_posted": obj.date,
"date": obj.date,
}
get_model("account.move").create(vals)
finally:
set_active_user(user_id)
obj.write({"state":"approved","reconcile_id":reconcile_id})
def journal_report(self,ids,context={}): def journal_report(self,ids,context={}):
obj=self.browse(ids[0]) obj=self.browse(ids[0])
move_id = get_model("account.move").search([["narration","=",obj.number]]) move_id = get_model("account.move").search([["narration","=",obj.number]])

View File

@ -3,6 +3,7 @@ import datetime
from netforce.model import Model, fields, get_model from netforce.model import Model, fields, get_model
from netforce.access import get_active_company, get_active_user, set_active_user from netforce.access import get_active_company, get_active_user, set_active_user
from netforce.utils import get_data_path
class Visit(Model): class Visit(Model):
_name="clinic.visit" _name="clinic.visit"
@ -13,6 +14,8 @@ class Visit(Model):
def _get_visit_late(self,ids,context={}): def _get_visit_late(self,ids,context={}):
res={} res={}
#oneday=datetime.timedelta(days=1)
#yesterday=datetime.datetime.now()-oneday
datenow=time.strftime("%Y-%m-%d") datenow=time.strftime("%Y-%m-%d")
for obj in self.browse(ids): for obj in self.browse(ids):
late=0 late=0
@ -34,6 +37,7 @@ class Visit(Model):
"company_id": fields.Many2One("company","Company"), "company_id": fields.Many2One("company","Company"),
'time_use': fields.Integer("Time Use(hrs)"), 'time_use': fields.Integer("Time Use(hrs)"),
'late_visit': fields.Integer("Late Vist",function="_get_visit_late"), 'late_visit': fields.Integer("Late Vist",function="_get_visit_late"),
"dialyzers": fields.One2Many("clinic.dialyzer.line","visit_id","Dialyzers"),
} }
def _get_number(self,context={}): def _get_number(self,context={}):
@ -93,6 +97,8 @@ class Visit(Model):
# cannot treatment if current date is not same visit date # cannot treatment if current date is not same visit date
if obj.visit_date!=datenow: if obj.visit_date!=datenow:
raise Exception("Today is not treament date!") raise Exception("Today is not treament date!")
if not obj.dialyzers:
raise Exception("Please select dialyzer!")
fmt_date="%Y-%m-%d %H:%M:%S" fmt_date="%Y-%m-%d %H:%M:%S"
date_from=dt.strptime("%s %s"%(obj.visit_date,timenow),fmt_date) date_from=dt.strptime("%s %s"%(obj.visit_date,timenow),fmt_date)
@ -113,6 +119,7 @@ class Visit(Model):
'fee_type': obj.patient_id.type, 'fee_type': obj.patient_id.type,
'lines':[], 'lines':[],
'dialyzers': [], 'dialyzers': [],
'state': 'in_progress',
} }
patient_type={ patient_type={
@ -136,31 +143,15 @@ class Visit(Model):
break break
# find dialyser # find dialyser
for dlz in get_model("clinic.dialyzer").search_browse([['patient_id','=',obj.patient_id.id],['state','=','active']],order="id desc"): if not obj.dialyzers:
use_time=dlz.use_time or 0
use_time+=1
# XXX update dialyzer
dlz.write({
'use_time': use_time,
})
if use_time > dlz.max_use_time:
dlz.write({
"state": "expire",
})
continue
vals['dialyzers'].append(('create',{
"dialyzer_id": dlz.id,
"description": dlz.description,
"use_time": use_time,
"max_use_time": dlz.max_use_time,
"member_type": dlz.member_type,
"dialyzer_type": dlz.dialyzer_type,
"bid_flow_rate": dlz.bid_flow_rate,
"ultrafittration": dlz.ultrafittration,
}))
if not vals['dialyzers']:
raise Exception("%s don't have dialyzer for treatment yet" % obj.patient_id.name) raise Exception("%s don't have dialyzer for treatment yet" % obj.patient_id.name)
hd_case_id=hd_case_obj.create(vals) hd_case_id=hd_case_obj.create(vals)
for dlz in obj.dialyzers:
# TODO check max time and expire day also
dlz.dialyzer_id.write({'use_time': dlz.use_time}) # count use time
dlz.write({
'hd_case_id': hd_case_id,
})
obj.write({"state":"treatment"}) obj.write({"state":"treatment"})
return { return {
'next': { 'next': {
@ -250,4 +241,24 @@ class Visit(Model):
} }
return data return data
def onchange_dialyzer(self,context={}):
data=context["data"]
path=context["path"]
line=get_data_path(data,path,parent=True)
dialyzer_id=line.get("dialyzer_id")
if not dialyzer_id:
return {}
dialyzer=get_model("clinic.dialyzer").browse(dialyzer_id)
use_time=dialyzer.use_time or 0
use_time+=1
line["description"]=dialyzer.description or ""
line["use_time"]=use_time
line["max_use_time"]=dialyzer.max_use_time
line["member_type"]=dialyzer.member_type
line["dialyzer_type"]=dialyzer.dialyzer_type
line["bid_flow_rate"]=dialyzer.bid_flow_rate
line["ultrafittration"]=dialyzer.ultrafittration
line["state"]=dialyzer.state
return data
Visit.register() Visit.register()

View File

@ -14,19 +14,17 @@
-> state -> state
- draft - draft
- confirmed - confirmed
- should dialyzer before treament - should select dialyzer before treament
- buttons - buttons -> ok
- confirm - confirm
- state : draft -> waiting treatment - state : draft -> waiting treatment
- do treatment - do treatment
- state : waiting treatment -> - state : waiting treatment ->
- cancel visit - cancel visit -> ok
- print visit - print visit -> ok
- plaining visit
- day [monday, tueday, wedsday, thursday, friday]
- time
- treament - treament
- print invoice
- time start/stop - time start/stop
- only time - only time
- date treament - date treament
@ -36,12 +34,24 @@
- make next appointment - make next appointment
- make payment - make payment
- state - state
- draft - ready to treatment
- confirm - paid -> no because not realte to accounting
- many2one for dializer - many2one for dializer
- list show percent of progress bar
- plaining visit !!!
- select next day to visit
- copy data to visit
- after click complete
- day [monday, tueday, wedsday, thursday, friday]
- time
- dialyzer - dialyzer
- import payment
- import
- create payment with invoice that found
- post
- undo
======= =======
sequence (support multi company) -> ok sequence (support multi company) -> ok
- visit - visit
- hd case - hd case