Skip to content

Instantly share code, notes, and snippets.

View ppazos's full-sized avatar
🌎
All around

Pablo Pazos Gutiérrez ppazos

🌎
All around
View GitHub Profile
@ppazos
ppazos / is_subclass.groovy
Created May 18, 2023 02:37
Checking if a class is the same or subclass of another class
def a = [
Double.class,
Date.class
]
a.each { clazz ->
if (clazz.equals(Double)) println clazz.toString() +" equals Double 1" // OK
if (clazz == Double) println clazz.toString() +" equals Double 2" // OK
if (Number.isAssignableFrom(clazz)) println clazz.toString() +" anumber 2" // OK: Number is the same or super class of clazz
@ppazos
ppazos / ph_queries.php
Created May 5, 2023 18:35
New API for phresistence queries
<?php
$emp_payor = $EmployerPayor->findBy([
'AND' => [
['employer_id', '=', $employer->get_id()],
'OR' => [
'AND' => [
['valid_to', '>', $dos],
['valid_from', 'IS NULL']
],
@ppazos
ppazos / query_criteria_isnull.groovy
Last active April 3, 2023 15:52
Grails / Hibernate query criteria isNull or multiple value IN set
def getDomain1ById(Long sid) {
return Domain1.createCriteria().get {
createAlias('domain2', 'd2', CriteriaSpecification.LEFT_JOIN)
createAlias('domain3', 'd3', CriteriaSpecification.LEFT_JOIN)
idEq(sid)
'in' ("locationId", locIds)
or {
isNull("domain2")
'in' ("d2.locationId", locIds)
}
@ppazos
ppazos / paths_to_trees.groovy
Last active August 16, 2023 21:52
openEHR data paths to trees
import groovy.json.*
// NOTE: the prefix / was removed to help the recursion, this step could be done before starting of it can be part of the first recursion
def data = [
"name",
"category",
"context/setting",
"context/start_time",
"content(3)/data/origin",
"content(3)/data/events(1)/time",
@ppazos
ppazos / camel_snake_conversions.groovy
Created January 17, 2023 15:00
Conversion from-to camel and snake cases
// from: https://gist.github.com/two7sclash-zz/c3835d83695b46ca2a6a4b6d71272538
// note: snake case should also take into account spaces, println toSnakeCase("Camel Case Class") actually generates camel _case _class
static String toCamelCase( String text, boolean capitalized = false ) {
text = text.replaceAll( "(_)([A-Za-z0-9])", { Object[] it -> it[2].toUpperCase() } )
return capitalized ? capitalize(text) : text
}
static String toSnakeCase( String text ) {
text.replaceAll( /([A-Z])/, /_$1/ ).toLowerCase().replaceAll( /^_/, '' )
@Grab('com.xlson.groovycsv:groovycsv:1.3')
import static com.xlson.groovycsv.CsvParser.parseCsv
def csv = new File("amplify_clinic_services.csv").text
def csv_iterator = parseCsv(csv)
def multiple_columns = [
'SPECIALTY',
'BODY PART',
@ppazos
ppazos / json_append_compare.groovy
Created October 24, 2022 02:09
Groovy compare appending map to another map for serializing JSON vs. string replace on the final JSON string
import groovy.time.TimeCategory
import groovy.time.TimeDuration
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def map = [
_type: 'ORIGINAL_VERSION',
uid: [
_type: 'OBJECT_VERSION_ID',
value: '12341234'
grailsApplication.getArtefacts("Domain").each { domain ->
println domain.toString()
domain.getProperties().each { prop ->
println prop.name +": "+ prop.type.name // DefaultGrailsDomainClassProperty
}
}
@ppazos
ppazos / duration_manipulation.groovy
Created August 11, 2022 03:50
openEHR duration operations
def durations = [
'P1Y',
'P2Y',
'P1Y1M',
'P1Y1M1W',
'P1Y1M1W1D',
'P1Y1M1D',
'P1M',
'P1W',
@ppazos
ppazos / tree_diff_path_list_to_tree.groovy
Last active July 25, 2022 23:24
Takes two trees, geenerates a diff based on the paths, and generates a diff tree back based on the list of paths compared
def tree1 = [
'path': '/',
'children': [
[
'path': '/a(1)',
'children': [
[
'path': '/a(1)/b',
'children': []
],