Skip to content

Commit

Permalink
added demographic dtp parsers to support demog API
Browse files Browse the repository at this point in the history
  • Loading branch information
ppazos committed Mar 21, 2023
1 parent 1ac747b commit f418888
Show file tree
Hide file tree
Showing 11 changed files with 485 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 1.8.24
version = 1.8.25
group = com.cabolabs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.cabolabs.openehr.dto_1_0_2.demographic

/**
* @author pablo.pazos@cabolabs.com
*
*/
class AgentDto extends ActorDto {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.cabolabs.openehr.dto_1_0_2.demographic

/**
* @author pablo.pazos@cabolabs.com
*
*/
class GroupDto extends ActorDto {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.cabolabs.openehr.dto_1_0_2.demographic

/**
* @author pablo.pazos@cabolabs.com
*
*/
class OrganizationDto extends ActorDto {

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.cabolabs.openehr.dto_1_0_2.demographic



/**
* @author pablo.pazos@cabolabs.com
*
*/
class PersonDto extends ActorDto {
class PersonDto extends ActorDto {

}
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ class OpenEhrJsonParserQuick {
{
throw new JsonParseException("_type required for CARE_ENTRY.protocol")
}
//String path_node_id = (json.protocol.archetype_node_id.startsWith('at') ? json.protocol.archetype_node_id : 'archetype_id='+ json.protocol.archetype_node_id)

String method = 'parse'+ type
c.protocol = this."$method"(json.protocol, parent)
}
Expand All @@ -519,8 +519,6 @@ class OpenEhrJsonParserQuick {
{
this.fillLOCATABLE(p, json, parent)

String path_node_id

if (json.details)
{
def type = json.details._type
Expand All @@ -531,26 +529,19 @@ class OpenEhrJsonParserQuick {
}

def method = 'parse'+ type

path_node_id = (json.details.archetype_node_id.startsWith('at') ? json.details.archetype_node_id : 'archetype_id='+ json.details.archetype_node_id)

this."$method"(json.details, p)
}

if (json.contacts)
{
json.contacts.eachWithIndex { contact, i ->

path_node_id = (contact.archetype_node_id.startsWith('at') ? contact.archetype_node_id : 'archetype_id='+ contact.archetype_node_id)

p.contacts << this.parseCONTACT(contact, p)
}
}

json.identities.eachWithIndex { party_identity, i ->

path_node_id = (party_identity.archetype_node_id.startsWith('at') ? party_identity.archetype_node_id : 'archetype_id='+ party_identity.archetype_node_id)

p.identities << this.parsePARTY_IDENTITY(party_identity, p)
}
}
Expand Down Expand Up @@ -644,6 +635,77 @@ class OpenEhrJsonParserQuick {

// ========= PARSE METHODS =========

// Generic parse for any actor subclass (Person, Organization, ...)
public ActorDto parseActorDto(String json)
{
def slurper = new JsonSlurper()
def map = slurper.parseText(json)

// FIXME: EHR is not LOCATABLE and doesn't have info about the rm_version!
// For the API EHR we could access the EHR_STATUS.archetype_details.rm_version, but for RM EHRs, ehr_status is an OBJECT_REF that should be resolved.
if (this.schemaValidate)
{
// independently from schemaFlavor, this will always be "api" since it is asking to parse an API EhrDto
// for an "rm" Ehr the parseEhr() method should be used
this.jsonValidator = new JsonInstanceValidation("api") // FIXME: this uses the default 1.0.2 version schema!

def errors = jsonValidator.validate(json)
if (errors)
{
this.jsonValidationErrors = errors
return
}
}

String type = map._type

if (!type)
{
throw new JsonParseException("_type required for to parse an ACTOR")
}

def method = 'parse'+ type +'Dto'
this."$method"(map)
}

private PersonDto parsePERSONDto(Map map)
{
def actor = new PersonDto()

this.fillActorDto(actor, map, null)

return actor
}

private GroupDto parseGROUPDto(Map map)
{
def actor = new GroupDto()

this.fillActorDto(actor, map, null)

return actor
}

// NOTE: OrganiZation vs. OrganiSation
private OrganizationDto parseORGANISATIONDto(Map map)
{
def actor = new OrganizationDto()

this.fillActorDto(actor, map, null)

return actor
}

private AgentDto parseAGENTDto(Map map)
{
def actor = new AgentDto()

this.fillActorDto(actor, map, null)

return actor
}

// These methods are used when the type is known beforhand
public PersonDto parsePersonDto(String json)
{
def slurper = new JsonSlurper()
Expand All @@ -665,13 +727,88 @@ class OpenEhrJsonParserQuick {
}
}

def person = new PersonDto()
return this.parsePERSONDto(map)
}

this.fillActorDto(person, map, null)
public OrganizationDto parseOrganizationDto(String json)
{
def slurper = new JsonSlurper()
def map = slurper.parseText(json)

return person
// FIXME: EHR is not LOCATABLE and doesn't have info about the rm_version!
// For the API EHR we could access the EHR_STATUS.archetype_details.rm_version, but for RM EHRs, ehr_status is an OBJECT_REF that should be resolved.
if (this.schemaValidate)
{
// independently from schemaFlavor, this will always be "api" since it is asking to parse an API EhrDto
// for an "rm" Ehr the parseEhr() method should be used
this.jsonValidator = new JsonInstanceValidation("api") // FIXME: this uses the default 1.0.2 version schema!

def errors = jsonValidator.validate(json)
if (errors)
{
this.jsonValidationErrors = errors
return
}
}

return this.parseORGANISATIONDto(map)
}

public GroupDto parseGroupDto(String json)
{
def slurper = new JsonSlurper()
def map = slurper.parseText(json)

// FIXME: EHR is not LOCATABLE and doesn't have info about the rm_version!
// For the API EHR we could access the EHR_STATUS.archetype_details.rm_version, but for RM EHRs, ehr_status is an OBJECT_REF that should be resolved.
if (this.schemaValidate)
{
// independently from schemaFlavor, this will always be "api" since it is asking to parse an API EhrDto
// for an "rm" Ehr the parseEhr() method should be used
this.jsonValidator = new JsonInstanceValidation("api") // FIXME: this uses the default 1.0.2 version schema!

def errors = jsonValidator.validate(json)
if (errors)
{
this.jsonValidationErrors = errors
return
}
}

return this.parseGROUPDto(map)
}

public AgentDto parseAgentDto(String json)
{
def slurper = new JsonSlurper()
def map = slurper.parseText(json)

// FIXME: EHR is not LOCATABLE and doesn't have info about the rm_version!
// For the API EHR we could access the EHR_STATUS.archetype_details.rm_version, but for RM EHRs, ehr_status is an OBJECT_REF that should be resolved.
if (this.schemaValidate)
{
// independently from schemaFlavor, this will always be "api" since it is asking to parse an API EhrDto
// for an "rm" Ehr the parseEhr() method should be used
this.jsonValidator = new JsonInstanceValidation("api") // FIXME: this uses the default 1.0.2 version schema!

def errors = jsonValidator.validate(json)
if (errors)
{
this.jsonValidationErrors = errors
return
}
}

return this.parseAGENTDto(map)
}


// TODO: parse identity dto



// Methods used for LOCATABLE RM parsing (not DTO)

private Person parsePERSON(Map map)
{
def person = new Person()
Expand Down Expand Up @@ -723,8 +860,6 @@ class OpenEhrJsonParserQuick {

this.fillLOCATABLE(pi, map, parent)

String path_node_id

if (map.details)
{
def type = map.details._type
Expand All @@ -736,8 +871,6 @@ class OpenEhrJsonParserQuick {

def method = 'parse'+ type

path_node_id = (map.details.archetype_node_id.startsWith('at') ? map.details.archetype_node_id : 'archetype_id='+ map.details.archetype_node_id)

this."$method"(map.details, pi)
}

Expand All @@ -761,8 +894,6 @@ class OpenEhrJsonParserQuick {

if (map.other_details)
{
String path_node_id = (map.other_details.archetype_node_id.startsWith('at') ? map.other_details.archetype_node_id : 'archetype_id='+ map.other_details.archetype_node_id)

String method = 'parse'+ map.other_details._type
status.other_details = this."$method"(map.other_details, status)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"archetype_node_id": "at0002",
"value": {
"_type": "DV_IDENTIFIER",
"issuer": "",
"issuer": "Hospital de Clinicas",
"assigner": "Hospital de Clinicas",
"id": "",
"type": ""
"id": "12345",
"type": "NHID"
}
}
]
Expand Down
Loading

0 comments on commit f418888

Please sign in to comment.