Ejemplo n.º 1
0
    def post(self, medical_id):
        """
        复制病历
        :param medical_id:
        :return:
        """
        name = request.jsondata.get("name")
        rank = request.jsondata.get("rank")
        new_medical = MedicalTemplate()
        new_medical.set("name", name)
        new_medical.set("rank", rank)
        new_medical.set("show", False)
        new_medical.set("is_delete", False)
        new_medical.save()

        medical = Query(MedicalTemplate).get(medical_id)
        medical_processes = Query(MedicalProcess).equal_to("parent", medical).equal_to("is_delete", False).find()
        for medical_process in medical_processes:
            new_medical_process = MedicalProcess()
            new_medical_process.set("parent", new_medical)
            new_medical_process.set("is_delete", False)
            new_medical_process.set("name", medical_process.get("name"))
            new_medical_process.set("sort", medical_process.get("sort"))
            new_medical_process.set("icon_url", medical_process.get("icon_url"))
            new_medical_process.save()
            process_cards = Query(ProcessCard).equal_to("parent", medical_process).equal_to("is_delete", False).find()
            for process_card in process_cards:
                new_process_card = ProcessCard()
                new_process_card.set("parent", new_medical_process)
                new_process_card.set("is_delete", False)
                new_process_card.set("name", process_card.get("name"))
                new_process_card.set("card_can_loop", process_card.get("card_can_loop"))
                new_process_card.set("sort", process_card.get("sort"))
                new_process_card.save()
                card_items = Query(CardItem).equal_to("parent", process_card).equal_to("is_delete", False).find()
                for card_item in card_items:
                    new_card_item = CardItem()
                    new_card_item.set("parent", new_process_card)
                    new_card_item.set("is_delete", False)
                    new_card_item.set("item_before_input", card_item.get("item_before_input"))
                    new_card_item.set("item_after_input", card_item.get("item_after_input"))
                    new_card_item.set("item_choice_label", card_item.get("item_choice_label"))
                    new_card_item.set("item_is_must", card_item.get("item_is_must"))
                    new_card_item.set("item_prompt", card_item.get("item_prompt"))
                    new_card_item.set("item_title", card_item.get("item_title"))
                    new_card_item.set("item_type", card_item.get("item_type"))
                    new_card_item.set("name", card_item.get("name"))
                    new_card_item.set("sort", card_item.get("sort"))
                    new_card_item.save()
        return new_medical
Ejemplo n.º 2
0
    @request_validator({"+name": "string",
                        "icon_url": "string"})
    @marshal_with(MedicalProcessFields.resource_fields)
    def post(self, medical_id):
        name = request.jsondata.get('name')
        icon_url = request.jsondata.get('icon_url')
        medical = Query(MedicalTemplate).get(medical_id)
        try:
            total_processes_num = Query(MedicalProcess).equal_to("parent", medical).count()
        except LeanCloudError, e:
            if e.code == 101:  # 服务端对应的 Class 还没创建
                total_processes_num = 0
            else:
                raise e
        process = MedicalProcess()
        process.set("name", name)
        process.set('is_delete', False)
        process.set("parent", medical)
        process.set("sort", total_processes_num)
        process.set("icon_url", icon_url)
        process.save()
        return process

    @request_validator({"sort": "string"})
    @marshal_with(MedicalProcessFields.resource_fields)
    def put(self, medical_id):
        """
        重新排序
        """
        medical = Query(MedicalTemplate).get(medical_id)