Advertisement
strike_noir

mcu_json_input_2

Dec 11th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 37.59 KB | None | 0 0
  1.  
  2. from openerp import models, fields, api
  3. from datetime import datetime, date
  4. from openerp.exceptions import Warning
  5.  
  6. class McuJsonInput(models.Model):
  7.     _inherit = "mcu.record"
  8.  
  9.     # query_mode: can be "mcu" or "outpatient"
  10.     # header_id: id of the header record can be "mcu.record" or "outpatient.laboratory.record"
  11.     # line: the mcu.record.line dictionary not the model itself
  12.     # data: the mcu.data
  13.     # create: flag whether to create or not to create the related model
  14.     def _query_mcu_data(self, query_mode, header_id, line, data, create=False):
  15.         # import ipdb; ipdb.set_trace();
  16.        
  17.         if (header_id==False or header_id==None):
  18.             return line
  19.  
  20.         header = None
  21.         header_link = None
  22.         domain = None
  23.         patient_id = None
  24.        
  25.         if query_mode=="mcu":
  26.             header = self.env["mcu.record"].search([("id", "=", header_id)])
  27.             header_link = {"patient_mcu_id": header_id}
  28.             patient_id = header.patient_id.id
  29.             domain = [("patient_mcu_id", "=", header_id)]
  30.        
  31.         if query_mode=="outpatient":
  32.             header = self.env["outpatient.laboratory.record"].search([("id", "=", header_id)])
  33.             header_link = {"outpatient_lab_id": header_id}
  34.             patient_id = header.patient_id.id
  35.             domain = [("outpatient_lab_id", "=", header_id)]
  36.            
  37.         if query_mode=="inpatient":
  38.             header = self.env["inpatient.laboratory.record"].search([("id", "=", header_id)])
  39.             header_link = {"inpatient_lab_id": header_id}
  40.             patient_id = header.patient_id.id
  41.             domain = [("inpatient_lab_id", "=", header_id)]
  42.            
  43.         # if header.state!="sampling":
  44.             # return line
  45.  
  46.         if (line["data_model"]=="mcu.data.health.history"):
  47.             mcu_health = self.env[line["data_model"]]
  48.             # mcu_res = data.health_history_id
  49.             # if mcu_res == False:
  50.                 # mcu_res = mcu_health.search(domain)
  51.             # if (len(mcu_res)==0 and create):
  52.                 # health_data = {
  53.                     # "exam_id": line["exam_id"],
  54.                     # "data_id": data.id,
  55.                 # }
  56.                 # health_data.update(header_link)
  57.                 # mcu_res = mcu_health.create(health_data)
  58.                 # data.health_history_id = mcu_res.id
  59.             # line["res_id"] = mcu_res.id
  60.  
  61.         elif (line["data_model"]=="fhg.patient.cons.param"):
  62.             # import ipdb; ipdb.set_trace();
  63.             mcu_parameter = self.env[line["data_model"]]
  64.             # mcu_res = data.patient_cons_param_id
  65.             # if mcu_res == False:
  66.                 # mcu_res = mcu_parameter.search(domain)
  67.             # if (len(mcu_res)==0 and create):
  68.                 # value_set = {
  69.                     # "patient_id": patient_id,
  70.                     # "data_id": data.id,
  71.                 # }
  72.                 # value_set.update(header_link)
  73.                 # mcu_res = mcu_parameter.create(value_set)
  74.                 # data.patient_cons_param_id = mcu_res.id
  75.             # line["res_id"] = mcu_res.id
  76.  
  77.         elif (line["data_model"]=="mcu.data.body"):
  78.             try :
  79.                 mcu_body = self.env[line["data_model"]]
  80.             except :
  81.                 text = "You need to put mcu.data.body on the package of %s" % (self.mcu_pack_id.name)
  82.                 raise Warning(text)
  83.             # mcu_res = data.body_id
  84.             # if mcu_res == False:
  85.                 # mcu_res = mcu_body.search(domain)
  86.             # if (len(mcu_res)==0 and create):
  87.                 # value_set = {
  88.                     # "patient_id": patient_id,
  89.                     # "exam_id": line["exam_id"],
  90.                     # "data_id": data.id,
  91.                 # }
  92.                 # value_set.update(header_link)
  93.                 # mcu_res = mcu_body.create(value_set)
  94.                 # data.body_id = mcu_res.id
  95.             # line["res_id"] = mcu_res.id
  96.  
  97.         elif (line["data_model"]=="mcu.data.physical.examination"):
  98.             try :
  99.                 mcu_physical_examination = self.env[line["data_model"]]
  100.             except :
  101.                 text = "You need to put mcu.data.physical.examination on the package of %s" % (self.mcu_pack_id.name)
  102.                 raise Warning(text)
  103.  
  104.             # mcu_res = data.physical_examination_id
  105.             # if mcu_res == False:
  106.                 # mcu_res = mcu_physical_examination.search(domain)
  107.             # if (len(mcu_res)==0 and create):
  108.                 # value_set = {
  109.                     # "patient_id": patient_id,
  110.                     # "data_id": data.id,
  111.                 # }
  112.                 # value_set.update(header_link)
  113.                 # mcu_res = mcu_physical_examination.create(value_set)
  114.                 # data.physical_examination_id = mcu_res.id
  115.             # line["res_id"] = mcu_res.id
  116.  
  117.         elif (line["data_model"]=="mcu.data.spirometry"):
  118.             try :
  119.                 mcu_spiro = self.env[line["data_model"]]
  120.             except :
  121.                 text = "You need to put mcu.data.spirometry on the package of %s" % (self.mcu_pack_id.name)
  122.                 raise Warning(text)
  123.             # mcu_res = data.spirometry_id
  124.             # if mcu_res == False:
  125.                 # mcu_res = mcu_spiro.search(domain)
  126.             # if (len(mcu_res)==0 and create):
  127.                 # value_set = {
  128.                     # "patient_id": patient_id,
  129.                     # "exam_id": line["exam_id"],
  130.                     # "data_id": data.id,
  131.                 # }
  132.                 # value_set.update(header_link)
  133.                 # mcu_res = mcu_spiro.create(value_set)
  134.                 # data.spirometry_id = mcu_res.id
  135.             # line["res_id"] = mcu_res.id
  136.  
  137.         elif (line["data_model"]=="mcu.data.framingham"):
  138.             try :
  139.                 mcu_framingham = self.env[line["data_model"]]
  140.             except :
  141.                 text = "You need to put mcu.data.framingham on the package of %s" % (self.mcu_pack_id.name)
  142.                 raise Warning(text)
  143.  
  144.             # mcu_res = data.framingham_id
  145.             # if mcu_res == False:
  146.                 # mcu_res = mcu_framingham.search(domain)
  147.             # if (len(mcu_res)==0 and create):
  148.                 # value_set = {
  149.                     # "patient_id": patient_id,
  150.                     # "exam_id": line["exam_id"],
  151.                     # "data_id": data.id,
  152.                 # }
  153.                 # value_set.update(header_link)
  154.                 # mcu_res = mcu_framingham.create(value_set)
  155.                 # data.framingham_id = mcu_res.id
  156.             # line["res_id"] = mcu_res.id
  157.  
  158.         elif (line["data_model"]=="mcu.data.audio"):
  159.             try :
  160.                 mcu_audiometry = self.env[line["data_model"]]
  161.             except :
  162.                 text = "You need to put mcu.data.audio on the package of %s" % (self.mcu_pack_id.name)
  163.                 raise Warning(text)
  164.  
  165.             # mcu_res = data.audio_id
  166.             # if mcu_res == False:
  167.                 # mcu_res = mcu_audiometry.search(domain)
  168.             # if (len(mcu_res)==0 and create):
  169.                 # value_set = {
  170.                     # "patient_id": patient_id,
  171.                     # "exam_id": line["exam_id"],
  172.                     # "data_id": data.id,
  173.                 # }
  174.                 # value_set.update(header_link)
  175.                 # mcu_res = mcu_audiometry.create(value_set)
  176.                 # data.audio_id = mcu_res.id
  177.             # line["res_id"] = mcu_res.id
  178.  
  179.         elif (line["data_model"]=="mcu.data.vision"):
  180.             try :
  181.                 mcu_vision = self.env[line["data_model"]]
  182.             except :
  183.                 text = "You need to put mcu.data.vision on the package of %s" % (self.mcu_pack_id.name)
  184.                 raise Warning(text)
  185.  
  186.             # mcu_res = data.vision_id
  187.             # if mcu_res == False:
  188.                 # mcu_res = mcu_vision.search(domain)
  189.             # if (len(mcu_res)==0 and create):
  190.                 # value_set = {
  191.                     # "patient_id": patient_id,
  192.                     # "data_id": data.id,
  193.                 # }
  194.                 # value_set.update(header_link)
  195.                 # mcu_res = mcu_vision.create(value_set)
  196.                 # data.vision_id = mcu_res.id
  197.             # line["res_id"] = mcu_res.id
  198.  
  199.         elif (line["data_model"]=="mcu.data.tonometry"):
  200.             try :
  201.                 mcu_tonometry = self.env[line["data_model"]]
  202.             except :
  203.                 text = "You need to put mcu.data.tonometry on the package of %s" % (self.mcu_pack_id.name)
  204.                 raise Warning(text)
  205.  
  206.             # mcu_res = data.tonometry_id
  207.             # if mcu_res == False:
  208.                 # mcu_res = mcu_tonometry.search(domain)
  209.             # if (len(mcu_res)==0 and create):
  210.                 # value_set = {
  211.                     # "patient_id": patient_id,
  212.                     # "data_id": data.id,
  213.                 # }
  214.                 # value_set.update(header_link)
  215.                 # mcu_res = mcu_tonometry.create(value_set)
  216.                 # data.tonometry_id = mcu_res.id
  217.             # line["res_id"] = mcu_res.id
  218.  
  219.         elif (line["data_model"]=="mcu.data.ophtalmologist" or line["data_model"]=="mcu.data.ophtalmology"):
  220.             try :
  221.                 mcu_ophtalmology = self.env[line["data_model"]]
  222.             except :
  223.                 text = "You need to put mcu.data.ophtalmology on the package of %s" % (self.mcu_pack_id.name)
  224.                 raise Warning(text)
  225.  
  226.             # mcu_res = data.ophtalmology_id
  227.             # if mcu_res == False:
  228.                 # mcu_res = mcu_ophtalmology.search(domain)
  229.             # if (len(mcu_res)==0 and create):
  230.                 # value_set = {
  231.                     # "patient_id": patient_id,
  232.                     # "data_id": data.id,
  233.                 # }
  234.                 # value_set.update(header_link)
  235.                 # mcu_res = mcu_ophtalmology.create(value_set)
  236.                 # data.ophtalmology_id = mcu_res.id
  237.             # line["res_id"] = mcu_res.id
  238.  
  239.         elif (line["data_model"]=="mcu.data.widal"):
  240.             try :
  241.                 mcu_widal = self.env[line["data_model"]]
  242.             except :
  243.                 text = "You need to put mcu.data.widal on the package of %s" % (self.mcu_pack_id.name)
  244.                 raise Warning(text)
  245.  
  246.             # mcu_res = data.widal_id
  247.             # if mcu_res == False:
  248.                 # mcu_res = mcu_widal.search(domain)
  249.             # if (len(mcu_res)==0 and create):
  250.                 # value_set = {
  251.                     # "patient_id": patient_id,
  252.                     # "data_id": data.id,
  253.                 # }
  254.                 # value_set.update(header_link)
  255.                 # mcu_res = mcu_widal.create(value_set)
  256.                 # data.widal_id = mcu_res.id
  257.             # line["res_id"] = mcu_res.id
  258.  
  259.         elif (line["data_model"]=="mcu.data.thrombocyte.aggregation"):
  260.             try :
  261.                 mcu_thrombocyte_aggregation = self.env[line["data_model"]]
  262.             except :
  263.                 text = "You need to put mcu.data.thrombocyte.aggregation on the package of %s" % (self.mcu_pack_id.name)
  264.                 raise Warning(text)
  265.  
  266.             # mcu_res = data.thrombocyte_aggregation_id
  267.             # if mcu_res == False:
  268.                 # mcu_res = mcu_thrombocyte_aggregation.search(domain)
  269.             # if (len(mcu_res)==0 and create):
  270.                 # value_set = {
  271.                     # "patient_id": patient_id,
  272.                     # "data_id": data.id,
  273.                 # }
  274.                 # value_set.update(header_link)
  275.                 # mcu_res = mcu_thrombocyte_aggregation.create(value_set)
  276.                 # data.thrombocyte_aggregation_id = mcu_res.id
  277.             # line["res_id"] = mcu_res.id
  278.  
  279.         elif (line["data_model"]=="mcu.data.confirmation.alcohol.in.blood"):
  280.             try :
  281.                 mcu_data_confirmation_alcohol_in_blood = self.env[line["data_model"]]
  282.             except :
  283.                 text = "You need to put mcu.data.confirmation.alcohol.in.blood on the package of %s" % (self.mcu_pack_id.name)
  284.                 raise Warning(text)
  285.  
  286.             # mcu_res = data.confirmation_alcohol_in_blood_id
  287.             # if mcu_res == False:
  288.                 # mcu_res = mcu_data_confirmation_alcohol_in_blood.search(domain)
  289.             # if (len(mcu_res)==0 and create):
  290.                 # value_set = {
  291.                     # "patient_id": patient_id,
  292.                     # "data_id": data.id,
  293.                 # }
  294.                 # value_set.update(header_link)
  295.                 # mcu_res = mcu_data_confirmation_alcohol_in_blood.create(value_set)
  296.                 # data.confirmation_alcohol_in_blood_id = mcu_res.id
  297.             # line["res_id"] = mcu_res.id
  298.  
  299.         elif (line["data_model"]=="mcu.data.confirmation.cannabis.in.urine"):
  300.             try :
  301.                 mcu_data_confirmation_cannabis_in_urine = self.env[line["data_model"]]
  302.             except :
  303.                 text = "You need to put mcu.data.confirmation.cannabis.in.urine on the package of %s" % (self.mcu_pack_id.name)
  304.                 raise Warning(text)
  305.  
  306.             # mcu_res = data.confirmation_cannabis_in_urine_id
  307.             # if mcu_res == False:
  308.                 # mcu_res = mcu_data_confirmation_cannabis_in_urine.search(domain)
  309.             # if (len(mcu_res)==0 and create):
  310.                 # value_set = {
  311.                     # "patient_id": patient_id,
  312.                     # "data_id": data.id,
  313.                 # }
  314.                 # value_set.update(header_link)
  315.                 # mcu_res = mcu_data_confirmation_cannabis_in_urine.create(value_set)
  316.                 # data.confirmation_cannabis_in_urine_id = mcu_res.id
  317.             # line["res_id"] = mcu_res.id
  318.  
  319.         elif (line["data_model"]=="mcu.data.confirmation.opiates.in.urine"):
  320.             try :
  321.                 mcu_data_confirmation_opiates_in_urine = self.env[line["data_model"]]
  322.             except :
  323.                 text = "You need to put mcu.data.confirmation.opiates.in.urine on the package of %s" % (self.mcu_pack_id.name)
  324.                 raise Warning(text)
  325.  
  326.             # mcu_res = data.confirmation_opiates_in_urine_id
  327.             # if mcu_res == False:
  328.                 # mcu_res = mcu_data_confirmation_opiates_in_urine.search(domain)
  329.             # if (len(mcu_res)==0 and create):
  330.                 # value_set = {
  331.                     # "patient_id": patient_id,
  332.                     # "data_id": data.id,
  333.                 # }
  334.                 # value_set.update(header_link)
  335.                 # mcu_res = mcu_data_confirmation_opiates_in_urine.create(value_set)
  336.                 # data.confirmation_opiates_in_urine_id = mcu_res.id
  337.             # line["res_id"] = mcu_res.id
  338.  
  339.         elif (line["data_model"]=="mcu.data.confirmation.benzodiazepine.in.urine"):
  340.             try :
  341.                 mcu_data_confirmation_benzodiazepine_in_urine = self.env[line["data_model"]]
  342.             except :
  343.                 text = "You need to put mcu.data.confirmation.benzodiazepine.in.urine on the package of %s" % (self.mcu_pack_id.name)
  344.                 raise Warning(text)
  345.  
  346.             # mcu_res = data.confirmation_benzodiazepine_in_urine_id
  347.             # if mcu_res == False:
  348.                 # mcu_res = mcu_data_confirmation_benzodiazepine_in_urine.search(domain)
  349.             # if (len(mcu_res)==0 and create):
  350.                 # value_set = {
  351.                     # "patient_id": patient_id,
  352.                     # "data_id": data.id,
  353.                 # }
  354.                 # value_set.update(header_link)
  355.                 # mcu_res = mcu_data_confirmation_benzodiazepine_in_urine.create(value_set)
  356.                 # data.confirmation_benzodiazepine_in_urine_id = mcu_res.id
  357.             # line["res_id"] = mcu_res.id
  358.  
  359.         elif (line["data_model"]=="mcu.data.confirmation.barbiturate.in.blood"):
  360.             try :
  361.                 mcu_data_confirmation_barbiturate_in_blood = self.env[line["data_model"]]
  362.             except :
  363.                 text = "You need to put mcu.data.confirmation.barbiturate.in.blood on the package of %s" % (self.mcu_pack_id.name)
  364.                 raise Warning(text)
  365.  
  366.             # mcu_res = data.confirmation_barbiturate_in_blood_id
  367.             # if mcu_res == False:
  368.                 # mcu_res = mcu_data_confirmation_barbiturate_in_blood.search(domain)
  369.             # if (len(mcu_res)==0 and create):
  370.                 # value_set = {
  371.                     # "patient_id": patient_id,
  372.                     # "data_id": data.id,
  373.                 # }
  374.                 # value_set.update(header_link)
  375.                 # mcu_res = mcu_data_confirmation_barbiturate_in_blood.create(value_set)
  376.                 # data.confirmation_barbiturate_in_blood_id = mcu_res.id
  377.             # line["res_id"] = mcu_res.id
  378.  
  379.         elif (line["data_model"]=="xray.record" or line["data_model"]=="ecg.record" or line["data_model"]=="usg.record" or line["data_model"]=="treadmill.record"):
  380.             # import ipdb; ipdb.set_trace();
  381.             patient_xray = self.env[line["data_model"]]
  382.            
  383.             # domain_ext = domain[:]
  384.             # if line["exam_id"] :
  385.                 # domain_ext.extend([("exam_id", "=", line["exam_id"])])
  386.            
  387.             # mcu_res = patient_xray.search(domain_ext)
  388.             # if (len(mcu_res)==0 and create):
  389.                 # mcu_note = ", ".join([doc.name for doc in rec.child_ids])
  390.                 # value_set = {
  391.                     # "patient_id": patient_id,
  392.                     # "medical_center_id": self.medical_center_id.id,
  393.                     # "medical_staff_id": self.medical_staff_id.id,
  394.                     # "exam_id": line["exam_id"],
  395.                     # "data_id": data.id,
  396.                 # }
  397.                 # value_set.update(header_link)
  398.                 # mcu_res = patient_xray.create(value_set)
  399.                
  400.                 # if line["data_model"]=="xray.record":
  401.                     # data.xray_record_id = mcu_res.id
  402.                
  403.                 # if line["data_model"]=="ecg.record":
  404.                     # data.ecg_record_id = mcu_res.id
  405.                
  406.                 # if line["data_model"]=="usg.record":
  407.                     # data.usg_record_id = mcu_res.id
  408.                
  409.                 # if line["data_model"]=="treadmill.record":
  410.                     # data.treadmill_record_id = mcu_res.id
  411.            
  412.             # import ipdb; ipdb.set_trace();
  413.             # line["res_id"] = mcu_res.id
  414.  
  415.         elif (line["data_model"]=="mcu.data.culture.sensitivity"):
  416.             culture = self.env[line["data_model"]]
  417.             # mcu_res = data.culture_sensitivity_id
  418.             # if mcu_res == False:
  419.                 # mcu_res = culture.search(domain)
  420.             # if (len(mcu_res)==0 and create):
  421.                 # value_set = {
  422.                     # "mcu_data_id": data.id,
  423.                     # "patient_id": patient_id,
  424.                     # "data_id": data.id,
  425.                 # }
  426.                 # value_set.update(header_link)
  427.                 # mcu_res = culture.create(value_set)
  428.                 # data.culture_sensitivity_id = mcu_res.id
  429.             # line["res_id"] = mcu_res.id
  430.        
  431.         elif (line["data_model"]=="mcu.data.hb.electrophoresis"):
  432.             hbe = self.env[line["data_model"]]
  433.             # mcu_res = data.hb_electrophoresis_id
  434.             # if mcu_res == False:
  435.                 # mcu_res = hbe.search(domain)
  436.             # if (len(mcu_res)==0 and create):
  437.                 # value_set = {
  438.                     # "patient_id": patient_id,
  439.                     # "data_id": data.id,
  440.                 # }
  441.                 # value_set.update(header_link)
  442.                 # mcu_res = hbe.create(value_set)
  443.                 # data.hb_electrophoresis_id = mcu_res.id
  444.             # line["res_id"] = mcu_res.id
  445.  
  446.         elif (line["data_model"]=="mcu.data.brief.mental.status"):
  447.             try :
  448.                 mcu_brief_mental_status = self.env[line["data_model"]]
  449.             except :
  450.                 text = "You need to put mcu.data.brief.mental.status on the package of %s" % (self.mcu_pack_id.name)
  451.                 raise Warning(text)
  452.  
  453.             # mcu_res = data.brief_mental_status_id
  454.             # if mcu_res == False:
  455.                 # mcu_res = mcu_brief_mental_status.search(domain)
  456.             # if (len(mcu_res)==0 and create):
  457.                 # value_set = {
  458.                     # "patient_id": patient_id,
  459.                     # "data_id": data.id,
  460.                 # }
  461.                 # value_set.update(header_link)
  462.                 # mcu_res = mcu_brief_mental_status.create(value_set)
  463.                 # data.brief_mental_status_id = mcu_res.id
  464.             # line["res_id"] = mcu_res.id
  465.  
  466.         elif (line["data_model"]=="mcu.data.mercury"):
  467.             try :
  468.                 mcu_data_mercury = self.env[line["data_model"]]
  469.             except :
  470.                 text = "You need to put mcu.data.mercury on the package of %s" % (self.mcu_pack_id.name)
  471.                 raise Warning(text)
  472.  
  473.             # mcu_res = data.mercury_id
  474.             # if mcu_res == False:
  475.                 # mcu_res = mcu_data_mercury.search(domain)
  476.             # if (len(mcu_res)==0 and create):
  477.                 # value_set = {
  478.                     # "patient_id": patient_id,
  479.                     # "data_id": data.id,
  480.                 # }
  481.                 # value_set.update(header_link)
  482.                 # mcu_res = mcu_data_mercury.create(value_set)
  483.                 # data.mercury_id = mcu_res.id
  484.             # line["res_id"] = mcu_res.id
  485.  
  486.         elif (line["data_model"]=="mcu.data.lead"):
  487.             try :
  488.                 mcu_data_lead = self.env[line["data_model"]]
  489.             except :
  490.                 text = "You need to put mcu.data.lead on the package of %s" % (self.mcu_pack_id.name)
  491.                 raise Warning(text)
  492.  
  493.             # mcu_res = data.lead_id
  494.             # if mcu_res == False:
  495.                 # mcu_res = mcu_data_lead.search(domain)
  496.             # if (len(mcu_res)==0 and create):
  497.                 # value_set = {
  498.                     # "patient_id": patient_id,
  499.                     # "data_id": data.id,
  500.                 # }
  501.                 # value_set.update(header_link)
  502.                 # mcu_res = mcu_data_lead.create(value_set)
  503.                 # data.lead_id = mcu_res.id
  504.             # line["res_id"] = mcu_res.id
  505.  
  506.         elif (line["data_model"]=="mcu.data.arsenic"):
  507.             try :
  508.                 mcu_data_arsenic = self.env[line["data_model"]]
  509.             except :
  510.                 text = "You need to put mcu.data.arsenic on the package of %s" % (self.mcu_pack_id.name)
  511.                 raise Warning(text)
  512.  
  513.             # mcu_res = data.arsenic_id
  514.             # if mcu_res == False:
  515.                 # mcu_res = mcu_data_arsenic.search(domain)
  516.             # if (len(mcu_res)==0 and create):
  517.                 # value_set = {
  518.                     # "patient_id": patient_id,
  519.                     # "data_id": data.id,
  520.                 # }
  521.                 # value_set.update(header_link)
  522.                 # mcu_res = mcu_data_arsenic.create(value_set)
  523.                 # data.arsenic_id = mcu_res.id
  524.             # line["res_id"] = mcu_res.id
  525.  
  526.         elif (line["data_model"]=="mcu.data.xylene"):
  527.             try :
  528.                 mcu_data_xylene = self.env[line["data_model"]]
  529.             except :
  530.                 text = "You need to put mcu.data.xylene on the package of %s" % (self.mcu_pack_id.name)
  531.                 raise Warning(text)
  532.  
  533.             # mcu_res = data.xylene_id
  534.             # if mcu_res == False:
  535.                 # mcu_res = mcu_data_xylene.search(domain)
  536.             # if (len(mcu_res)==0 and create):
  537.                 # value_set = {
  538.                     # "patient_id": patient_id,
  539.                     # "data_id": data.id,
  540.                 # }
  541.                 # value_set.update(header_link)
  542.                 # mcu_res = mcu_data_xylene.create(value_set)
  543.                 # data.xylene_id = mcu_res.id
  544.             # line["res_id"] = mcu_res.id
  545.  
  546.         elif (line["data_model"]=="mcu.data.benzene"):
  547.             try :
  548.                 mcu_data_benzene = self.env[line["data_model"]]
  549.             except :
  550.                 text = "You need to put mcu.data.benzene on the package of %s" % (self.mcu_pack_id.name)
  551.                 raise Warning(text)
  552.  
  553.             # mcu_res = data.benzene_id
  554.             # if mcu_res == False:
  555.                 # mcu_res = mcu_data_benzene.search(domain)
  556.             # if (len(mcu_res)==0 and create):
  557.                 # value_set = {
  558.                     # "patient_id": patient_id,
  559.                     # "data_id": data.id,
  560.                 # }
  561.                 # value_set.update(header_link)
  562.                 # mcu_res = mcu_data_benzene.create(value_set)
  563.                 # data.benzene_id = mcu_res.id
  564.             # line["res_id"] = mcu_res.id
  565.  
  566.         elif (line["data_model"]=="mcu.data.toluene"):
  567.             try :
  568.                 mcu_data_toluene = self.env[line["data_model"]]
  569.             except :
  570.                 text = "You need to put mcu.data.toluene on the package of %s" % (self.mcu_pack_id.name)
  571.                 raise Warning(text)
  572.  
  573.             # mcu_res = data.toluene_id
  574.             # if mcu_res == False:
  575.                 # mcu_res = mcu_data_toluene.search(domain)
  576.             # if (len(mcu_res)==0 and create):
  577.                 # value_set = {
  578.                     # "patient_id": patient_id,
  579.                     # "data_id": data.id,
  580.                 # }
  581.                 # value_set.update(header_link)
  582.                 # mcu_res = mcu_data_toluene.create(value_set)
  583.                 # data.toluene_id = mcu_res.id
  584.             # line["res_id"] = mcu_res.id
  585.  
  586.         elif (line["data_model"]=="mcu.data.health.history.dslng"):
  587.             try :
  588.                 mcu_data_dslng = self.env[line["data_model"]]
  589.             except :
  590.                 text = "You need to put mcu.data.health.history.dslng on the package of %s" % (self.mcu_pack_id.name)
  591.                 raise Warning(text)
  592.  
  593.             # mcu_res = data.health_history_dslng_id
  594.             # if mcu_res == False:
  595.                 # mcu_res = mcu_data_dslng.search(domain)
  596.             # if (len(mcu_res)==0 and create):
  597.                 # value_set = {
  598.                     # "patient_id": patient_id,
  599.                     # "data_id": data.id,
  600.                 # }
  601.                 # value_set.update(header_link)
  602.                 # mcu_res = mcu_data_dslng.create(value_set)
  603.                 # data.health_history_dslng_id = mcu_res.id
  604.             # line["res_id"] = mcu_res.id
  605.  
  606.         elif (line["data_model"]=="mcu.data.general.physical"):
  607.             try :
  608.                 mcu_general_physical = self.env[line["data_model"]]
  609.             except :
  610.                 text = "You need to put mcu.data.general.physical on the package of %s" % (self.mcu_pack_id.name)
  611.                 raise Warning(text)
  612.  
  613.             # mcu_res = data.general_physical_id
  614.             # if mcu_res == False:
  615.                 # mcu_res = mcu_general_physical.search(domain)
  616.             # if (len(mcu_res)==0 and create):
  617.                 # value_set = {
  618.                     # "patient_id": patient_id,
  619.                     # "data_id": data.id,
  620.                 # }
  621.                 # value_set.update(header_link)
  622.                 # mcu_res = mcu_general_physical.create(value_set)
  623.                 # data.general_physical_id = mcu_res.id
  624.             # line["res_id"] = mcu_res.id
  625.  
  626.         elif (line["data_model"]=="mcu.data.hearing.assessment"):
  627.             try :
  628.                 mcu_hearing_assessment = self.env[line["data_model"]]
  629.             except :
  630.                 text = "You need to put mcu.data.hearing.assessment on the package of %s" % (self.mcu_pack_id.name)
  631.                 raise Warning(text)
  632.  
  633.             # mcu_res = data.hearing_assessment_id
  634.             # if mcu_res == False:
  635.                 # mcu_res = mcu_hearing_assessment.search(domain)
  636.             # if (len(mcu_res)==0 and create):
  637.                 # value_set = {
  638.                     # "patient_id": patient_id,
  639.                     # "data_id": data.id,
  640.                 # }
  641.                 # value_set.update(header_link)
  642.                 # mcu_res = mcu_hearing_assessment.create(value_set)
  643.                 # data.hearing_asssessment_id = mcu_res.id
  644.             # line["res_id"] = mcu_res.id
  645.  
  646.         elif (line["data_model"]=="mcu.data.visual.assessment"):
  647.             try :
  648.                 mcu_visual_assessment = self.env[line["data_model"]]
  649.             except :
  650.                 text = "You need to put mcu.data.visual.assessment on the package of %s" % (self.mcu_pack_id.name)
  651.                 raise Warning(text)
  652.  
  653.             # mcu_res = data.visual_assessment_id
  654.             # if mcu_res == False:
  655.                 # mcu_res = mcu_visual_assessment.search(domain)
  656.             # if (len(mcu_res)==0 and create):
  657.                 # value_set = {
  658.                     # "patient_id": patient_id,
  659.                     # "data_id": data.id,
  660.                 # }
  661.                 # value_set.update(header_link)
  662.                 # mcu_res = mcu_visual_assessment.create(value_set)
  663.                 # data.visual_assessment_id = mcu_res.id
  664.             # line["res_id"] = mcu_res.id
  665.  
  666.         elif (line["data_model"]=="mcu.data.neurological"):
  667.             try :
  668.                 mcu_data_neurological = self.env[line["data_model"]]
  669.             except :
  670.                 text = "You need to put mcu.data.neurological on the package of %s" % (self.mcu_pack_id.name)
  671.                 raise Warning(text)
  672.  
  673.             # mcu_res = data.neurological_id
  674.             # if mcu_res == False:
  675.                 # mcu_res = mcu_data_neurological.search(domain)
  676.             # if (len(mcu_res)==0 and create):
  677.                 # value_set = {
  678.                     # "patient_id": patient_id,
  679.                     # "data_id": data.id,
  680.                 # }
  681.                 # value_set.update(header_link)
  682.                 # mcu_res = mcu_data_neurological.create(value_set)
  683.                 # data.neurological_id = mcu_res.id
  684.             # line["res_id"] = mcu_res.id
  685.  
  686.         elif (line["data_model"]=="mcu.data.musculoskeletal"):
  687.             try :
  688.                 mcu_data_musculoskeletal = self.env[line["data_model"]]
  689.             except :
  690.                 text = "You need to put mcu.data.mcu.data.musculoskeletal on the package of %s" % (self.mcu_pack_id.name)
  691.                 raise Warning(text)
  692.  
  693.             # mcu_res = data.musculoskeletal_id
  694.             # if mcu_res == False:
  695.                 # mcu_res = mcu_data_musculoskeletal.search(domain)
  696.             # if (len(mcu_res)==0 and create):
  697.                 # value_set = {
  698.                     # "patient_id": patient_id,
  699.                     # "data_id": data.id,
  700.                 # }
  701.                 # value_set.update(header_link)
  702.                 # mcu_res = mcu_data_musculoskeletal.create(value_set)
  703.                 # data.musculoskeletal_id = mcu_res.id
  704.             # line["res_id"] = mcu_res.id
  705.  
  706.         elif (line["data_model"]=="mcu.data.respiratory"):
  707.             try :
  708.                 mcu_data_respiratory = self.env[line["data_model"]]
  709.             except :
  710.                 text = "You need to put mcu.data.respiratory on the package of %s" % (self.mcu_pack_id.name)
  711.                 raise Warning(text)
  712.  
  713.             # mcu_res = data.respiratory_id
  714.             # if mcu_res == False:
  715.                 # mcu_res = mcu_data_respiratory.search(domain)
  716.             # if (len(mcu_res)==0 and create):
  717.                 # value_set = {
  718.                     # "patient_id": patient_id,
  719.                     # "data_id": data.id,
  720.                 # }
  721.                 # value_set.update(header_link)
  722.                 # mcu_res = mcu_data_respiratory.create(value_set)
  723.                 # data.respiratory_id = mcu_res.id
  724.             # line["res_id"] = mcu_res.id
  725.  
  726.         elif (line["data_model"]=="mcu.data.abdomen"):
  727.             try :
  728.                 mcu_data_abdomen = self.env[line["data_model"]]
  729.             except :
  730.                 text = "You need to put mcu.data.abdomen on the package of %s" % (self.mcu_pack_id.name)
  731.                 raise Warning(text)
  732.  
  733.             # mcu_res = data.abdomen_id
  734.             # if mcu_res == False:
  735.                 # mcu_res = mcu_data_abdomen.search(domain)
  736.             # if (len(mcu_res)==0 and create):
  737.                 # value_set = {
  738.                     # "patient_id": patient_id,
  739.                     # "data_id": data.id,
  740.                 # }
  741.                 # value_set.update(header_link)
  742.                 # mcu_res = mcu_data_abdomen.create(value_set)
  743.                 # data.abdomen_id = mcu_res.id
  744.             # line["res_id"] = mcu_res.id
  745.  
  746.         elif (line["data_model"]=="mcu.data.cardiovascular"):
  747.             try :
  748.                 mcu_data_cardiovascular = self.env[line["data_model"]]
  749.             except :
  750.                 text = "You need to put mcu.data.cardiovascular on the package of %s" % (self.mcu_pack_id.name)
  751.                 raise Warning(text)
  752.  
  753.             # mcu_res = data.cardiovascular_id
  754.             # if mcu_res == False:
  755.                 # mcu_res = mcu_data_cardiovascular.search(domain)
  756.             # if (len(mcu_res)==0 and create):
  757.                 # value_set = {
  758.                     # "patient_id": patient_id,
  759.                     # "data_id": data.id,
  760.                 # }
  761.                 # value_set.update(header_link)
  762.                 # mcu_res = mcu_data_cardiovascular.create(value_set)
  763.                 # data.cardiovascular_id = mcu_res.id
  764.             # line["res_id"] = mcu_res.id
  765.  
  766.         elif (line["data_model"]=="finding.recommendation"):
  767.             try :
  768.                 finding_recommendation = self.env[line["data_model"]]
  769.             except :
  770.                 text = "You need to finding.recommendation on the package of %s" % (self.mcu_pack_id.name)
  771.                 raise Warning(text)
  772.  
  773.             # mcu_res = finding_recommendation.search(domain)
  774.             # if (len(mcu_res)==0 and create):
  775.                 # value_set = {
  776.                     # "patient_id": patient_id,
  777.                     # "data_id": data.id,
  778.                 # }
  779.                 # value_set.update(header_link)
  780.                 # mcu_res = finding_recommendation.create(value_set)
  781.                 # data.find_recom_id = mcu_res.id
  782.             # line["res_id"] = mcu_res.id
  783.  
  784.         else:
  785.             # if rec.name == "Examination":
  786.                 # import ipdb; ipdb.set_trace();
  787.  
  788.             mcu_data = self.env["mcu.data"]
  789.             mcu_res = None
  790.             domain_ext = domain[:]
  791.             if line["exam_id"] :
  792.                 domain_ext.extend([("mcu_record_line_id", "!=", False), ("exam_id", "=", line["exam_id"])])
  793.                 mcu_res = mcu_data.search(domain_ext)
  794.             else :
  795.                 domain_ext.extend([("mcu_record_line_id", "=", line["id"])])
  796.                 mcu_res = mcu_data.search(domain_ext)
  797.            
  798.             # if len(mcu_res) > 1:
  799.                 # import ipdb; ipdb.set_trace();
  800.             if len(mcu_res) :
  801.                 line["res_id"] = mcu_res.id
  802.  
  803.             # check the children
  804.             domain_ext = domain[:] #reset the domain_ext
  805.             domain_ext.extend([("parent_mcu_data_id", "=", mcu_res.id)])
  806.             mcu_children = mcu_data.search(domain_ext)
  807.            
  808.             # import ipdb; ipdb.set_trace();
  809.  
  810.             if len(mcu_children) != line["count_childs"]:
  811.                 # mcu_res = mcu_data.search([["patient_mcu_id", "=", patient_mcu_id], ["mcu_record_line_id", "=", rec.id]])
  812.                 line["res_id"] = data.id
  813.  
  814.         return line
  815.  
  816.     def _checkup_lines(self, query_mode, header_id, parent_id=False, dictionary=""):
  817.         mcu_line = self.env["mcu.record.line"]
  818.         mcu_data = self.env["mcu.data"]
  819.  
  820.         dictionary = [];
  821.  
  822.         domain = None
  823.        
  824.         if query_mode=="mcu":
  825.             domain = [("patient_mcu_id", "=", header_id)]
  826.  
  827.         if query_mode=="outpatient":
  828.             domain = [("outpatient_lab_id", "=", header_id)]
  829.        
  830.         if query_mode=="inpatient":
  831.             domain = [("inpatient_lab_id", "=", header_id)]
  832.        
  833.         domain.extend([("parent_id", "=", parent_id), ("include", "=", True)])
  834.         recs = mcu_line.search(domain, order="sequence asc")
  835.         # recs = mcu_line.search([["patient_mcu_id", "=", patient_mcu_id], ("parent_id", "=", parent_id)], order="sequence asc")
  836.        
  837.         for rec in recs:
  838.             value = {
  839.                 "id": rec.id,
  840.                 "name": rec.name,
  841.                 "parent_id": parent_id,
  842.                 "variety": rec.variety,
  843.                 "interest": rec.interest,
  844.                 "unit": rec.unit,
  845.                 "si_unit": rec.si_unit,
  846.                 "data_model": rec.data_model,
  847.                 "product_id": rec.product_id.id,
  848.                 "sequence": rec.sequence,
  849.                 "patient_mcu_id": header_id,
  850.                 "display_name": rec.display_name,
  851.                 "exam_id": rec.exam_id.id,
  852.                 "count_childs": rec.count_childs
  853.             }
  854.  
  855.             rec_id = rec.id
  856.            
  857.             data = mcu_data.search([["mcu_record_line_id", "=", rec_id]])
  858.            
  859.             value = self._query_mcu_data(query_mode, header_id, value, data) # get res_id
  860.  
  861.             childs = mcu_line.search([["parent_id", "=", rec_id]])
  862.             if len(childs):
  863.                 value["childs"] = self._checkup_lines(query_mode, header_id, rec_id)
  864.             else:
  865.                 value = self._query_mcu_data(query_mode, header_id, value, data) # get res_id
  866.  
  867.             dictionary.append(value);
  868.  
  869.         return dictionary
  870.  
  871.     @api.multi
  872.     def get_checkup_line(self, query_mode, header_id):
  873.         #CR an UID default dari Call Javascript
  874.         line_dictionary = self._checkup_lines(query_mode, header_id)
  875.         import json
  876.         return json.dumps(line_dictionary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement