diff --git a/README.md b/README.md index a3936323..d37773e3 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ String path = "vital_signs.xml" File file = new File(getClass().getResource(path).toURI()) String xml = file.text def parser = new OpenEhrXmlParser() -Composition c = (Composition)parser.parseXml(xml) +Composition c = (Composition)parser.parseLocatable(xml) ``` ### Serialize a COMPOSITION to XML @@ -249,7 +249,7 @@ report.errors.each { error -> ```groovy String xml = ... def parser = new OpenEhrXmlParser() -Composition c = (Composition)parser.parseXml(xml) +Composition c = (Composition)parser.parseLocatable(xml) def serializer = new OpenEhrJsonSerializer() String json = serializer.serialize(c) ``` diff --git a/gradle.properties b/gradle.properties index c5bafd6e..9bb5bda9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 1.9.10 +version = 1.9.11 group = com.cabolabs \ No newline at end of file diff --git a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonParser.groovy b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonParser.groovy index 49eeb772..db02607f 100644 --- a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonParser.groovy +++ b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonParser.groovy @@ -162,6 +162,7 @@ class OpenEhrJsonParser { return ehr } + // FIXME: this should be parseLocatable // used to parse compositions and other descendant from Locatable // TODO: FOLDER and EHR_STATUS are above, we might need to use this one instead Locatable parseJson(String json) diff --git a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonSerializer.groovy b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonSerializer.groovy index b6103e07..a3768122 100644 --- a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonSerializer.groovy +++ b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrJsonSerializer.groovy @@ -186,6 +186,8 @@ class OpenEhrJsonSerializer { { this.fillPartyDto(a, out) + def method + // optional if (a.languages) { @@ -218,6 +220,8 @@ class OpenEhrJsonSerializer { { this.fillParty(a, out) + def method + // optional if (a.languages) { @@ -674,8 +678,7 @@ class OpenEhrJsonSerializer { out.system_id = a.system_id - String method - method = this.method(a.committer) + String method = this.method(a.committer) out.committer = [_type: this.openEhrType(a.committer)] + this."$method"(a.committer) out.time_committed = this.serializeDvDateTime(a.time_committed) @@ -698,8 +701,7 @@ class OpenEhrJsonSerializer { // AuditDetails fields out.system_id = a.system_id - def method - method = this.method(a.committer) + def method = this.method(a.committer) out.committer = [_type: this.openEhrType(a.committer)] + this."$method"(a.committer) out.time_committed = this.serializeDvDateTime(a.time_committed) @@ -911,9 +913,11 @@ class OpenEhrJsonSerializer { { this.fillEntry(o, out) + String method + if (o.protocol) { - String method = this.method(o.protocol) + method = this.method(o.protocol) out.protocol = [_type: this.openEhrType(o.protocol)] + this."$method"(o.protocol) // TODO: check if this is needed diff --git a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrXmlParser.groovy b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrXmlParser.groovy index 3c05dbe6..bc896d4a 100644 --- a/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrXmlParser.groovy +++ b/src/main/groovy/com/cabolabs/openehr/formats/OpenEhrXmlParser.groovy @@ -215,7 +215,7 @@ class OpenEhrXmlParser { catch (Exception e) { println e.message - throw new XmlParseException("Can't parse XML, check ${type} is a VERSION type. If you tried to parse a LOCATABLE, use the parseXml method", e) + throw new XmlParseException("Can't parse XML, check ${type} is a VERSION type. If you tried to parse a LOCATABLE, use the parseLocatable method", e) } return out } diff --git a/src/main/groovy/com/cabolabs/openehr/opt/Main.groovy b/src/main/groovy/com/cabolabs/openehr/opt/Main.groovy index 4888e3dd..0f30bdeb 100644 --- a/src/main/groovy/com/cabolabs/openehr/opt/Main.groovy +++ b/src/main/groovy/com/cabolabs/openehr/opt/Main.groovy @@ -115,7 +115,6 @@ class Main { def destination_path = args[2] verifyFolder(destination_path) - // TODO: separate xml/json from the composition/version in two params def format = 'json' def generate = 'locatable' @@ -282,6 +281,7 @@ class Main { printer.flush() printer.close() break + // TODO: trans FOLDER, EHR_STATUS, ACTOR, PARTY_RELATIONSHIP case "composition": String path = args[2] // composition @@ -302,7 +302,7 @@ class Main { // Parse XML String xml = f.text def parser = new OpenEhrXmlParser() - Composition c = (Composition)parser.parseXml(xml) + Composition c = (Composition)parser.parseLocatable(xml) // debug // out = JsonOutput.toJson(c) @@ -457,7 +457,7 @@ class Main { static validateXMLWithOPT(File xml) { def parser = new OpenEhrXmlParser() - def instance = parser.parseXml(xml.text) // should be a composition, if the file is a version it won't parse + def instance = parser.parseLocatable(xml.text) // xml should be a locatable validateCompositionWithOPT(instance) } diff --git a/src/main/groovy/com/cabolabs/openehr/opt/instance_generator/RmInstanceGenerator.groovy b/src/main/groovy/com/cabolabs/openehr/opt/instance_generator/RmInstanceGenerator.groovy index 1e8d94a4..562052f2 100644 --- a/src/main/groovy/com/cabolabs/openehr/opt/instance_generator/RmInstanceGenerator.groovy +++ b/src/main/groovy/com/cabolabs/openehr/opt/instance_generator/RmInstanceGenerator.groovy @@ -930,7 +930,7 @@ class RmInstanceGenerator { _denominator = 1 break case 2: // percent - _numerator = (random_gen.nextFloat() * (num_hi - num_lo) + num_lo).round(1) + _numerator = (random_gen.nextFloat() * 100).round(1) // NOTE: for a percentage, 100 is the high value _denominator = 100 break case [3,4]: // fraction, integer_fraction diff --git a/src/main/resources/opts/com.cabolabs.openehr_opt.namespaces.default/monitoreo_de_signos_vitales.opt b/src/main/resources/opts/com.cabolabs.openehr_opt.namespaces.default/monitoreo_de_signos_vitales.opt new file mode 100644 index 00000000..14f39365 --- /dev/null +++ b/src/main/resources/opts/com.cabolabs.openehr_opt.namespaces.default/monitoreo_de_signos_vitales.opt @@ -0,0 +1,833 @@ + + + \ No newline at end of file diff --git a/src/test/groovy/com/cabolabs/openehr/opt/RmValidationTest.groovy b/src/test/groovy/com/cabolabs/openehr/opt/RmValidationTest.groovy index c789e8f3..c460e3b2 100644 --- a/src/test/groovy/com/cabolabs/openehr/opt/RmValidationTest.groovy +++ b/src/test/groovy/com/cabolabs/openehr/opt/RmValidationTest.groovy @@ -11,15 +11,13 @@ class RmValidationTest extends GroovyTestCase { private static String PS = System.getProperty("file.separator") - /* - void testValidationFromXmlComposition() { String path = "/canonical_xml/test_all_datatypes.composition.en.xml" File file = new File(getClass().getResource(path).toURI()) String xml = file.text def parser = new OpenEhrXmlParser() - Composition c = (Composition)parser.parseXml(xml) + Composition c = (Composition)parser.parseLocatable(xml) // TODO: add support for S3 repo String opt_repo_path = "/opts" @@ -36,13 +34,14 @@ class RmValidationTest extends GroovyTestCase { } } + /* void testValidationFromXmlComposition2() { String path = "/canonical_xml/test_all_datatypes.composition.en.xml" File file = new File(getClass().getResource(path).toURI()) String xml = file.text def parser = new OpenEhrXmlParser() // TODO: create a quick parser that doesn't calculate paths - Composition c = (Composition)parser.parseXml(xml) + Composition c = (Composition)parser.parseLocatable(xml) // TODO: add support for S3 repo String opt_repo_path = "/opts"