File Mover Blog

  • 31 Jul

    HL7 (text) File Modification with Limagito File Mover

    HL7 (text) File Modification

    Q: Good morning, thank you again for taking my call! Please find the before and after test files attached.

    1. You’ll see that the FT1 segment, specifically the FT1.25 section, was moved to FT1.7 section. (Each section is delimited by a pipe “|”.)
    2. We also added “CG” (without quotes) to the FT1.6 section. I’ve attached an image to visualize as well.

    I’m urgently trying to get this solution in place! Thank you for your help!!!!

    A: Summary of what we need to do:

    1. Load the HL7 (text) File.
    2. Iterate through the lines in the HL7 File.
    3. Search for a line that starts with ‘FT1|’.
    4. Make the requested adjustments.
    5. Save the HL7 file different from the Source.

    We created a Pascal Script to achieve this (v2021.7.31.0 or higher is needed for this script). Let’s start.

    1) Please add a Source and a File Filter for the .HL7 files you want to adjust
    2) Add the following Pascal Script as Destination, don’t forget to adjust the ctOutputPath const ( must end with a \ ).

    Limagito File Mover Pascal Script as Destination

    Var
      iList: Integer;
      tmpEntry: String;
      tmpError: String;
      tmpField: String;
      tmpFile : String;
      tmpList: TStringList;
      tmpEntryList: TStringList;
    Const
      ctOutputPath = 'C:\Test\IN_HL7\Out\';
    Begin
      psExitCode:= 0;
      // ... add your code here
      tmpFile := psFilePath + psFileName;
      tmpList := TStringList.Create;
      Try
        Try
          tmpList.LoadFromFile(tmpFile);
          // Iterate
          For iList := 0 to (tmpList.Count-1) Do
          Begin
            tmpEntry := tmpList.Strings[iList];
            If Pos('FT1|', tmpEntry) <> 0 Then
            Begin
              tmpEntryList := psDelimitedTextAsList('|', tmpEntry);
              If Assigned(tmpEntryList) Then
              Begin
                tmpEntryList.Delimiter := '|';
                tmpEntryList.StrictDelimiter := True;
                tmpEntryList.Quotechar := #0;
                // 0 indexed
                If tmpEntryList.Count >= 25 Then
                Begin
                  tmpEntryList.Strings[6] := 'CG';
                  tmpEntryList.Strings[7] := tmpEntryList.Strings[25];
                  tmpEntryList.Strings[25] := ''
                  tmpList.Strings[iList] := tmpEntryList.DelimitedText + '|';
                  // Save To File
                  tmpError := psSaveListToFile(tmpList, ctOutputPath + psFileName, False);
                  if tmpError = '' Then
                  begin
                    psExitCode := 1;
                    psLogWrite(1, '', 'Saved adjusted file to: ' + ctOutputPath + psFileName);
                  End
                  Else
                    psLogWrite(1, '', tmpError);
                End Else
                Begin
                  psLogWrite(1, '', 'Field Count error of: ' + tmpEntryList.DelimitedText);
                End;
                // Free
                tmpEntryList.Free;
                // Break
                Break;
              End;
            End;
          End;
        Except
          psLogWrite(1, '', 'Error loading file: ' + tmpFile);
        End;
      Finally
        tmpList.Free;
      End;
    End.
    

    #FileTransfer

    If you need any info about this ‘HL7 (text) File Modification’ request, please let us know.

    Best regards,

    Limagito Team

  • 31 Jul

    Need support about moving files to sub folder ARCHIVE

    Q: Need support about moving files to sub folder ARCHIVE

    I would like to realize a move action with Limagito:

    > Source folder : D:\MECA + Subdir
    –Subdir contains \Customer_ONE, \Customer_TWO, etc.

    info : files to move are stored in each subfolder
    example:
    D:\MECA\Customer_ONE\po_20210720.csv
    D:\MECA\Customer_TWO\po_20210720.csv
    etc.

    > Function : Move

    > Destination folder :
    D:\MECA\Customer_ONE\Archive
    D:\MECA\Customer_TWO\Archive
    etc.

    You can see that Limagito will scan D:\MECA and its subfolders, and have to move files to archive subfolder.
    So objective is too collect the “Customer_ONE”, “Customer_TWO” value when Limagito scans…

    How can I set setting or make Pascal Script to be able to do this rule, and avoid create one rule per folder ?
    Let me know if my request is clear enough. Thanks in advance for your help.

    A: Could you please try the following. Some screenshots to get you started.

    • Source D:\MECA in our example is C:\Test\In_Meca\

    Limagito File Mover Mover to Archive

    • Windows Folder as Source:

    Limagito File Mover Mover to Archive

    • Directory Filter Setup:

    Limagito File Mover Mover to Archive

    • Directory Name Exclude Filter Setup (important)

    Limagito File Mover Mover to Archive

    • Destination Setup, Selected Directory is the same as the Source:

    Limagito File Mover Mover to Archive

    • Destination File & Directory ‘Create Subdir, option’ Setup

    Limagito File Mover Mover to Archive

    • RunTime Log:

    Limagito File Mover Mover to Archive

    If you need any help with this ‘moving files to sub folder ARCHIVE’ request, please let us know.

    #FileTransfer

    Best Regards,

    Limagito Team

    By Limagito-Team WIN ,
  • 31 Jul

    Connecting to Office 365 email using IMAP and OAuth2 authentication

    Q: Connecting to Office 365 email using IMAP and OAuth2 authentication.

    Wir versuchen gerade mit Limagito eine Verbindung zu einem MS Office 365 Email Postfach herzustellen und scheitern an der OAuth2 Authntifizierung. Wir wissen nicht genau was alles in die Felder muss.

    A: Best to use a more recent version since we did quite some code changes for IMAP4 as Source and OAuth2 authentication in version v2021.8.5.0 to make it easier to connect to MS Office 365.

    Important: Setup your App Registration in Azure beforehand. Here are the steps:

    1) In the Azure portal, go to Azure Active Directory. In “App registrations” create a “+ New registration”.

    Azure App registrations
    2) Register the app with Redirect URI = “http://localhost:3017”.

    Azure Register an application
    3) Goto “API permissions” to add permissions. For this OAuth2 authorization flow, we’ll add “Delegated permissions”.
    4) Add IMAP.AccessAsUser.All and offline_access permissions.

    Azure App Permissions

    5) Go to “Certificates & secrets” and add a new client secret.

    Azure Certificates & secrets

    6) In “App registrations”, go to “Endpoints” (located to the right of the “+ New registration” link. Note your endpoints for “OAuth 2.0 authorization endpoint (v2)” and “OAuth 2.0 token endpoint (v2)

    Azure Endpoints

    Azure endpoints

    7) Also, just in case, go to your Microsoft 365 admin center (this is not Azure). Go to your Active users. Click on a user to find the “Manage email apps” link. See Microsoft 365 Manage Email Apps

    Microsoft 365 admin center manage email apps

    Microsoft 365 admin center manage email apps

    8) Click on “Manage email apps”. Then make sure the “IMAP” checkbox is checked.

    Next, configuration of our File Mover:

    • Add IMAP4 as Source

    Limagito File Mover IMAP4 as Source

    • IMAP4 Setup. Be sure to select our second API Vendor: ‘Vendor 2 – CK’.

    Limagito File Mover IMAP4 Setup

    • IMAP4 Security Setup (please use version v2021.8.5.0 or higher).

    Limagito File Mover IMAP4 Security Setup

    • IMAP4 Common Setup

    Limagito File Mover IMAP4 Common Setup

    • IMAP4 OAuth2 Setup

    Limagito File Mover IMAP4 OAuth2 setup

    1) Fill in the correct Authorization and Token Url

    2)Enter Application Client ID and Client Secret Value

    Azure App Client ID

     

    Azure Secret Value

    3) Adjust your scope to: openid profile offline_access https://outlook.office365.com/IMAP.AccessAsUser.All

      • Provide a SPACE separated list of scopes.
      •  Important: The offline_access scope is needed to get a refresh token.

    4) Set Redirect URI to: http://localhost:3017/

    5) Set Redirect Port to 3017

      • This should be the port in the localhost callback URL for your app.
      • The callback URL would look like “http://localhost:3017/”, if the port number is 3017.
      • The redirect must go to http://localhost:/. It must be localhost, and it cannot be “https”.

    Next, click on the <GET> button.

    Should ‘Windows Defender’ popup, please <Allow access>.

    Limagito File Mover IMAP4 Oauth2

    Your browser will open and ask you for ‘Confirmation’.

    Limagito File Mover IMAP4 OAuth2

    Follow the routine in your browser and accept the authorization request.

    Limagito File Mover IMAP4 OAuth2 Access is granted

    Now you can close the browser. The ‘Refresh’ and ‘Access’ Token in the IMAP4 OAuth2 Setup should contain values. Click <Save>.

    Limagito File Mover IMAP4 OAuth2 Setup

    The IMAP as Source configuration is finished. Just add a Destination and you are ready to go.

    If you need any help with this ‘Office 365 email using IMAP’ request, please let us know.

    Some extra information: ‘Explaining OAuth2 Authentication’.

    The OAuth2 Get Token button does a couple of things:

    1. It starts the OAuth2 Authentication process.
    2. Returns a URL that should be displayed in a browser.
    3. Starts a background thread to receive the redirect callback from the browser.

    The flow of control is like this:

    1. The browser (popped up and displayed by our file mover) automatically navigates to the URL provided by Start Authentication.
    2. The user interactively authorizes the access. In doing so, the response sent back to the browser is a redirect to http://localhost:<someport>/
    3. The browser receives the response, and redirects to the http://localhost:<someport>/
    4. The background thread (= temporary HTTP server using <someport>) is the thing that is listening at and receives the response, and then your OAuth2 is completed.

    The redirect must go to http://localhost:<someport>/. It must be localhost, and it cannot be “https”. If you defined your application’s redirect URL to a web address such as “https://yourdomain.com/something…”, then the background thread is just sitting there waiting for the callback, which never happens (because it went to your web server).

    Note 1: For Microsoft API’s such as for OneDrive, make sure that your App on Microsoft Developer Dashboard, inside Authentication, Redirect URIs, set the app type to Web (not public client). Your desktop app is acting as a web server when receiving the single redirect request.

    Note 2: We used the Scope needed for IMAP. Other examples are:

    • openid profile offline_access https://outlook.office365.com/SMTP.Send
    • openid profile offline_access https://outlook.office365.com/POP.AccessAsUser.All

     

    #FileTransfer

    Best Regards,

    Limagito Team

    By Limagito-Team 365 IMAP4 OAuth2 , , ,
1 67 68 69 70 71 72 73 145
SEARCH