Nova postagem

Pesquisar

Pergunta
· Abr. 11, 2024

Dynamically Generating SQL queries Based on Incremental Column values

I'm facing a challenge in dynamically generating SQL queries based on incremental q_ids for a project I'm working on. Here's the scenario:

  • I have a table log_reports that contains logs of service activities, including timestamps and associated q_ids.
  • Each service log entry is associated with a cls and a q.
  • My goal is to generate SQL queries that calculate statistics such as average, minimum, and maximum time differences between the log creation time and the current timestamp, for each combination of cls_id and q_id.

Current Approach:

Here's the SQL query I'm currently using:

SELECT
    LPAD(FLOOR(AVG(DATEDIFF(HOUR, log.created_at, CURRENT_TIMESTAMP))), 2, '0') || ':' ||
    LPAD(FLOOR(AVG(DATEDIFF(MINUTE, log.created_at, CURRENT_TIMESTAMP))), 2, '0') || ':' ||
    LPAD(FLOOR(AVG(DATEDIFF(SECOND, log.created_at, CURRENT_TIMESTAMP))), 2, '0') AS average_time_difference, 
    
    LPAD(FLOOR(MIN(DATEDIFF(HOUR, log.created_at, CURRENT_TIMESTAMP))), 2, '0') || ':' ||
    LPAD(FLOOR(MIN(DATEDIFF(MINUTE, log.created_at, CURRENT_TIMESTAMP))), 2, '0') || ':' ||
    LPAD(FLOOR(MIN(DATEDIFF(SECOND, log.created_at, CURRENT_TIMESTAMP))), 2, '0') AS min_time_difference,
    
    LPAD(FLOOR(MAX(DATEDIFF(HOUR, log.created_at, CURRENT_TIMESTAMP))), 2, '0') || ':' ||
    LPAD(FLOOR(MAX(DATEDIFF(MINUTE, log.created_at, CURRENT_TIMESTAMP))), 2, '0') || ':' ||
    LPAD(FLOOR(MAX(DATEDIFF(SECOND, log.created_at, CURRENT_TIMESTAMP))), 2, '0') AS max_time_difference
FROM
    log_reports log  
LEFT JOIN
    pass_slip slip ON log.tkt = slip.id  
WHERE
    log.cls_id IN (61)
    AND log.q_id IN (19, 25, 27)
    AND slip.status IS NOT NULL
GROUP BY
     log.cls_id

 

This query works well for a fixed set of q_ids. However, I need to dynamically generate the query to include all q_id up to a certain point.

Expected Solution:

I'm looking for suggestions on how to dynamically generate the SQL query to include q_ids incrementally, such that:

  1. Initially, the query should consider only the first q_id.
  2. In subsequent executions, the query should include an additional q_id until all q_id are covered.

Additional Context:

  • I'm using IRIS Database, which does not support common table expressions (CTEs) or native looping constructs within SQL queries.
  • The solution can involve either SQL techniques.

Questions:

  1. How can I dynamically generate SQL queries to include incremental q_ids without needing to execute the query multiple times?
  2. Are there any best practices or alternative approaches I should consider for this scenario?
  3. What scripting languages or techniques can I use to achieve this dynamic query generation if SQL alone isn't sufficient?

Any insights, code examples, or pointers to relevant resources would be greatly appreciated!

Thank you!

8 Comments
Discussão (8)3
Entre ou crie uma conta para continuar
Pergunta
· Abr. 11, 2024

Hardening the management portal - does this approach make sense?

Hello community,

in addition to HL7 V2 interfaces mediated via TCP/IP, we have been implementing more and more HS.FHIRServer.Interop.Service based services that are addressed via port 57772.
We would like to secure access to the Management Portal now and have come up with a procedure that I would like to discuss.

1. The local server firewall only allows access to port 57772 for the IPs of the administration PCs (and some few other exceptions).
2. A REST service is introduced for access to FHIR endpoints, which listens on a different (accessible) port. This service acts as a proxy and checks the URL suffix to see if a FHIR endpoint is accessed and forwards it to localhost:57772/[FHIR URL]. If not, a 403 is returned. In addition to the existing access control with user credentials this also allows us to restict access with the "Allowed IP Addresses" setting.

The description is somewhat simplified and is only intended to explain the concept. A proof of concept worked and performed quite well. Would you consider this approach to be useful and effective?

I look forward to comments and assessments.

Best regards,
Martin

5 Comments
Discussão (5)2
Entre ou crie uma conta para continuar
Discussão
· Abr. 10, 2024

Share your Ideas on InterSystems IRIS Cloud SQL

Hi Developers!

With InterSystems IRIS Cloud SQL recently becoming Generally Available, some of you may have had a chance to try it out. Or maybe you used it for your contest entry or during the EAP period. We're curious to learn what YOU think of it. So, have you already tried the new service InterSystems IRIS Cloud SQL

We have launched a new Ideas Portal category dedicated to this database-as-a-service (DBaaS) where we're looking for your ideas on how we can improve InterSystems IRIS Cloud SQL. 

Or share your experience with the service in the comments to this post. 

   

Discussão (0)1
Entre ou crie uma conta para continuar
Pergunta
· Abr. 10, 2024

Initiating a Method After a Timeout During Message Delivery

Hello everyone,

I'm currently working on a business operation that employs a retry mechanism with a FailureTimeout = -1. So, this BO attempts to resend the message at the end of a RetryInterval of n seconds (n is configurable).

What I would like to achieve is to set a timer that runs in parallel with the sending mechanism so that, If I don't receive a response within m seconds (also is configurable and m<=n) from the initial message send (with RetryCount = 1), an alert or something similar is triggered. The latter should initiate a second method to run concurrently with the first one (which is still attempting to send), allowing me to send a message to a business process to handle the situation. Then this BP will process the alert appropriately, such as sending an email or notification.

I've tried some solutions using the JOB command and the BO's Alerting settings (for ex., Queue Wait Alert), but I haven't been able to achieve the desired result. I'm not familiar with process parallelization in IRIS, so I was wondering if someone more experienced could point me in the right direction for this implementation.

Thank you

4 Comments
Discussão (4)3
Entre ou crie uma conta para continuar
Anúncio
· Abr. 9, 2024

InterSystems Online Developer Roundtable - April 25, 2024

Hi Developers,

Join us at the upcoming Developer Roundtable on April 25th at 9 am ET | 3 pm CET. 📍
We will have 2 topics covered by the invited experts and open discussion as always.

Tech Talks:
➡ Practical Usage of Embedded Python - by Stefan Wittmann Product Manager, InterSystems

▶ Recording: 

 

Do you have questions which you'd like to discuss on this roundtable? Please share them in the comments to this post. 

Not a Global Masters member yet? Sign in with your InterSystems SSO credentials. 

1 Comment
Discussão (1)1
Entre ou crie uma conta para continuar