示例#1
0
    def test_convert_to_edifact(self):
        TEST_DIR = os.path.dirname(os.path.abspath(__file__))

        expected_file_path = Path(TEST_DIR) / "edifact.txt"
        expected_edifact_interchange = FileUtilities.get_file_string(expected_file_path)

        incoming_file_path = Path(TEST_DIR) / "patient-register-birth.json"
        patient_register_json = FileUtilities.get_file_dict(incoming_file_path)

        outgoing_adaptor = OutgoingAdaptor(operation_dict)
        (sender, recipient, interchange_seq_no, edifact_interchange) = outgoing_adaptor.convert_to_edifact(
            patient_register_json)

        pretty_edifact_interchange = "'\n".join(edifact_interchange.split("'"))
        self.assertEqual(pretty_edifact_interchange, expected_edifact_interchange)
    def test_covert_to_fhir(self):
        """
        Test when the operation is for a birth registration
        """
        TEST_DIR = os.path.dirname(os.path.abspath(__file__))

        expected_file_path = Path(TEST_DIR) / "patient-register-birth-approval.json"
        patient_register_approval_json = FileUtilities.get_file_dict(expected_file_path)

        incoming_file_path = Path(TEST_DIR) / "edifact.txt"
        incoming_interchange_raw = FileUtilities.get_file_string(incoming_file_path)

        incoming_adaptor = IncomingAdaptor(reference_dict)
        op_defs = incoming_adaptor.convert_to_fhir(incoming_interchange_raw)

        op_def_to_compare = op_defs[0][2]
        compare(op_def_to_compare, patient_register_approval_json)
    def __init__(self, interactions_file_name):
        """Create a new InteractionsConfigFile that loads the interaction details from the specified JSON file.

        :param interactions_file_name: The file to load interaction details from. This file should be in JSON format.
        """
        self.interactions = FileUtilities.get_file_dict(interactions_file_name)
示例#4
0
gp_cypher = answers["gp"]

# Determine the fhir payload to read
gp_outbox_path = str(gp_mailbox_dir / gp_cypher / "outbox")
files = os.listdir(gp_outbox_path)
file_choices = [{
    'type': 'list',
    'name': 'file',
    'message': 'Select a file: ',
    'choices': files
}]
file_answer = prompt(file_choices)
file_name = file_answer["file"]

# Read the incoming file
incoming_file_path = f"{gp_outbox_path}/{file_name}"
patient_register_json = FileUtilities.get_file_dict(incoming_file_path)

# run the adaptor
adaptor = OutgoingAdaptor(operation_dict=operation_dict)
(sender, recipient, interchange_seq_no,
 edifact_interchange) = adaptor.convert_to_edifact(patient_register_json)

# create the generated edifact interchange
file_path_to_write = str(nhais_mailbox_dir / recipient / "inbox" /
                         f"{sender}-{interchange_seq_no}.txt")
edifact_file = open(file_path_to_write, "w")
pretty_edifact_interchange = "'\n".join(edifact_interchange.split("'"))
edifact_file.write(pretty_edifact_interchange)
edifact_file.close()
    def test_get_file_dict(self):
        test_json_file = os.path.join(self.test_files_dir, TEST_JSON_FILE)

        loaded_dict = FileUtilities.get_file_dict(test_json_file)

        self.assertEqual(EXPECTED_JSON, loaded_dict, "The dictionary loaded should match the one expected.")