This commit is contained in:
Grahame Grieve 2020-06-11 06:24:02 +10:00
commit 3b925f219d
11 changed files with 551 additions and 164 deletions

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.hl7.fhir.convertors.conv30_40.Account30_40;
import org.hl7.fhir.convertors.conv30_40.ActivityDefinition30_40; import org.hl7.fhir.convertors.conv30_40.ActivityDefinition30_40;
import org.hl7.fhir.convertors.conv30_40.AllergyIntolerance30_40; import org.hl7.fhir.convertors.conv30_40.AllergyIntolerance30_40;
import org.hl7.fhir.convertors.conv30_40.Appointment30_40; import org.hl7.fhir.convertors.conv30_40.Appointment30_40;
@ -24,6 +25,7 @@ import org.hl7.fhir.convertors.conv30_40.Composition30_40;
import org.hl7.fhir.convertors.conv30_40.ConceptMap30_40; import org.hl7.fhir.convertors.conv30_40.ConceptMap30_40;
import org.hl7.fhir.convertors.conv30_40.Condition30_40; import org.hl7.fhir.convertors.conv30_40.Condition30_40;
import org.hl7.fhir.convertors.conv30_40.Consent30_40; import org.hl7.fhir.convertors.conv30_40.Consent30_40;
import org.hl7.fhir.convertors.conv30_40.Coverage30_40;
import org.hl7.fhir.convertors.conv30_40.DataElement30_40; import org.hl7.fhir.convertors.conv30_40.DataElement30_40;
import org.hl7.fhir.convertors.conv30_40.DetectedIssue30_40; import org.hl7.fhir.convertors.conv30_40.DetectedIssue30_40;
import org.hl7.fhir.convertors.conv30_40.DeviceUseStatement30_40; import org.hl7.fhir.convertors.conv30_40.DeviceUseStatement30_40;
@ -4931,6 +4933,8 @@ public class VersionConvertor_30_40 {
return null; return null;
if (src instanceof org.hl7.fhir.dstu3.model.Parameters) if (src instanceof org.hl7.fhir.dstu3.model.Parameters)
return Parameters30_40.convertParameters((org.hl7.fhir.dstu3.model.Parameters) src); return Parameters30_40.convertParameters((org.hl7.fhir.dstu3.model.Parameters) src);
if (src instanceof org.hl7.fhir.dstu3.model.Account)
return Account30_40.convertAccount((org.hl7.fhir.dstu3.model.Account) src);
if (src instanceof org.hl7.fhir.dstu3.model.ActivityDefinition) if (src instanceof org.hl7.fhir.dstu3.model.ActivityDefinition)
return ActivityDefinition30_40.convertActivityDefinition((org.hl7.fhir.dstu3.model.ActivityDefinition) src); return ActivityDefinition30_40.convertActivityDefinition((org.hl7.fhir.dstu3.model.ActivityDefinition) src);
if (src instanceof org.hl7.fhir.dstu3.model.AllergyIntolerance) if (src instanceof org.hl7.fhir.dstu3.model.AllergyIntolerance)
@ -4971,6 +4975,8 @@ public class VersionConvertor_30_40 {
return Condition30_40.convertCondition((org.hl7.fhir.dstu3.model.Condition) src); return Condition30_40.convertCondition((org.hl7.fhir.dstu3.model.Condition) src);
if (src instanceof org.hl7.fhir.dstu3.model.Consent) if (src instanceof org.hl7.fhir.dstu3.model.Consent)
return Consent30_40.convertConsent((org.hl7.fhir.dstu3.model.Consent) src); return Consent30_40.convertConsent((org.hl7.fhir.dstu3.model.Consent) src);
if (src instanceof org.hl7.fhir.dstu3.model.Coverage)
return Coverage30_40.convertCoverage((org.hl7.fhir.dstu3.model.Coverage) src);
if (src instanceof org.hl7.fhir.dstu3.model.DataElement) if (src instanceof org.hl7.fhir.dstu3.model.DataElement)
return DataElement30_40.convertDataElement((org.hl7.fhir.dstu3.model.DataElement) src); return DataElement30_40.convertDataElement((org.hl7.fhir.dstu3.model.DataElement) src);
if (src instanceof org.hl7.fhir.dstu3.model.DetectedIssue) if (src instanceof org.hl7.fhir.dstu3.model.DetectedIssue)
@ -5108,6 +5114,8 @@ public class VersionConvertor_30_40 {
else else
return Parameters30_40.convertParameters((org.hl7.fhir.r4.model.Parameters) src); return Parameters30_40.convertParameters((org.hl7.fhir.r4.model.Parameters) src);
} }
if (src instanceof org.hl7.fhir.r4.model.Account)
return Account30_40.convertAccount((org.hl7.fhir.r4.model.Account) src);
if (src instanceof org.hl7.fhir.r4.model.ActivityDefinition) if (src instanceof org.hl7.fhir.r4.model.ActivityDefinition)
return ActivityDefinition30_40.convertActivityDefinition((org.hl7.fhir.r4.model.ActivityDefinition) src); return ActivityDefinition30_40.convertActivityDefinition((org.hl7.fhir.r4.model.ActivityDefinition) src);
if (src instanceof org.hl7.fhir.r4.model.AllergyIntolerance) if (src instanceof org.hl7.fhir.r4.model.AllergyIntolerance)
@ -5148,6 +5156,8 @@ public class VersionConvertor_30_40 {
return Condition30_40.convertCondition((org.hl7.fhir.r4.model.Condition) src); return Condition30_40.convertCondition((org.hl7.fhir.r4.model.Condition) src);
if (src instanceof org.hl7.fhir.r4.model.Consent) if (src instanceof org.hl7.fhir.r4.model.Consent)
return Consent30_40.convertConsent((org.hl7.fhir.r4.model.Consent) src); return Consent30_40.convertConsent((org.hl7.fhir.r4.model.Consent) src);
if (src instanceof org.hl7.fhir.r4.model.Coverage)
return Coverage30_40.convertCoverage((org.hl7.fhir.r4.model.Coverage) src);
if (src instanceof org.hl7.fhir.r4.model.DetectedIssue) if (src instanceof org.hl7.fhir.r4.model.DetectedIssue)
return DetectedIssue30_40.convertDetectedIssue((org.hl7.fhir.r4.model.DetectedIssue) src); return DetectedIssue30_40.convertDetectedIssue((org.hl7.fhir.r4.model.DetectedIssue) src);
if (src instanceof org.hl7.fhir.r4.model.DeviceUseStatement) if (src instanceof org.hl7.fhir.r4.model.DeviceUseStatement)

View File

@ -0,0 +1,191 @@
package org.hl7.fhir.convertors.conv30_40;
import org.hl7.fhir.convertors.VersionConvertor_30_40;
import org.hl7.fhir.exceptions.FHIRException;
/*
Copyright (c) 2011+, HL7, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of HL7 nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
public class Account30_40 extends VersionConvertor_30_40 {
public static org.hl7.fhir.r4.model.Account convertAccount(org.hl7.fhir.dstu3.model.Account src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.r4.model.Account tgt = new org.hl7.fhir.r4.model.Account();
copyDomainResource(src, tgt);
for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t));
if (src.hasStatus())
tgt.setStatusElement(convertAccountStatus(src.getStatusElement()));
if (src.hasType())
tgt.setType(convertCodeableConcept(src.getType()));
if (src.hasName())
tgt.setNameElement(convertString(src.getNameElement()));
if (src.hasSubject()) {
tgt.addSubject(convertReference(src.getSubject()));
}
if (src.hasPeriod())
tgt.setServicePeriod(convertPeriod(src.getPeriod()));
for (org.hl7.fhir.dstu3.model.Account.CoverageComponent t : src.getCoverage()) tgt.addCoverage(convertCoverageComponent(t));
if (src.hasOwner())
tgt.setOwner(convertReference(src.getOwner()));
if (src.hasDescription())
tgt.setDescriptionElement(convertString(src.getDescriptionElement()));
for (org.hl7.fhir.dstu3.model.Account.GuarantorComponent t : src.getGuarantor()) tgt.addGuarantor(convertGuarantorComponent(t));
return tgt;
}
public static org.hl7.fhir.dstu3.model.Account convertAccount(org.hl7.fhir.r4.model.Account src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.dstu3.model.Account tgt = new org.hl7.fhir.dstu3.model.Account();
copyDomainResource(src, tgt);
for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t));
if (src.hasStatus())
tgt.setStatusElement(convertAccountStatus(src.getStatusElement()));
if (src.hasType())
tgt.setType(convertCodeableConcept(src.getType()));
if (src.hasName())
tgt.setNameElement(convertString(src.getNameElement()));
if (src.getSubject().size() > 0) {
tgt.setSubject(convertReference(src.getSubjectFirstRep()));
}
if (src.hasServicePeriod())
tgt.setPeriod(convertPeriod(src.getServicePeriod()));
for (org.hl7.fhir.r4.model.Account.CoverageComponent t : src.getCoverage()) tgt.addCoverage(convertCoverageComponent(t));
if (src.hasOwner())
tgt.setOwner(convertReference(src.getOwner()));
if (src.hasDescription())
tgt.setDescriptionElement(convertString(src.getDescriptionElement()));
for (org.hl7.fhir.r4.model.Account.GuarantorComponent t : src.getGuarantor()) tgt.addGuarantor(convertGuarantorComponent(t));
return tgt;
}
static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Account.AccountStatus> convertAccountStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Account.AccountStatus> src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Account.AccountStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Account.AccountStatusEnumFactory());
VersionConvertor_30_40.copyElement(src, tgt);
switch(src.getValue()) {
case ACTIVE:
tgt.setValue(org.hl7.fhir.r4.model.Account.AccountStatus.ACTIVE);
break;
case INACTIVE:
tgt.setValue(org.hl7.fhir.r4.model.Account.AccountStatus.INACTIVE);
break;
case ENTEREDINERROR:
tgt.setValue(org.hl7.fhir.r4.model.Account.AccountStatus.ENTEREDINERROR);
break;
default:
tgt.setValue(org.hl7.fhir.r4.model.Account.AccountStatus.NULL);
break;
}
return tgt;
}
static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Account.AccountStatus> convertAccountStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Account.AccountStatus> src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Account.AccountStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Account.AccountStatusEnumFactory());
VersionConvertor_30_40.copyElement(src, tgt);
switch(src.getValue()) {
case ACTIVE:
tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.ACTIVE);
break;
case INACTIVE:
tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.INACTIVE);
break;
case ENTEREDINERROR:
tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.ENTEREDINERROR);
break;
case ONHOLD:
tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.ACTIVE);
break;
case UNKNOWN:
tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.ACTIVE);
break;
default:
tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.NULL);
break;
}
return tgt;
}
public static org.hl7.fhir.r4.model.Account.CoverageComponent convertCoverageComponent(org.hl7.fhir.dstu3.model.Account.CoverageComponent src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.r4.model.Account.CoverageComponent tgt = new org.hl7.fhir.r4.model.Account.CoverageComponent();
copyElement(src, tgt);
if (src.hasCoverage())
tgt.setCoverage(convertReference(src.getCoverage()));
if (src.hasPriority())
tgt.setPriorityElement(convertPositiveInt(src.getPriorityElement()));
return tgt;
}
public static org.hl7.fhir.dstu3.model.Account.CoverageComponent convertCoverageComponent(org.hl7.fhir.r4.model.Account.CoverageComponent src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.dstu3.model.Account.CoverageComponent tgt = new org.hl7.fhir.dstu3.model.Account.CoverageComponent();
copyElement(src, tgt);
if (src.hasCoverage())
tgt.setCoverage(convertReference(src.getCoverage()));
if (src.hasPriority())
tgt.setPriorityElement(convertPositiveInt(src.getPriorityElement()));
return tgt;
}
public static org.hl7.fhir.r4.model.Account.GuarantorComponent convertGuarantorComponent(org.hl7.fhir.dstu3.model.Account.GuarantorComponent src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.r4.model.Account.GuarantorComponent tgt = new org.hl7.fhir.r4.model.Account.GuarantorComponent();
copyElement(src, tgt);
if (src.hasParty())
tgt.setParty(convertReference(src.getParty()));
if (src.hasOnHold())
tgt.setOnHoldElement(convertBoolean(src.getOnHoldElement()));
if (src.hasPeriod())
tgt.setPeriod(convertPeriod(src.getPeriod()));
return tgt;
}
public static org.hl7.fhir.dstu3.model.Account.GuarantorComponent convertGuarantorComponent(org.hl7.fhir.r4.model.Account.GuarantorComponent src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.dstu3.model.Account.GuarantorComponent tgt = new org.hl7.fhir.dstu3.model.Account.GuarantorComponent();
copyElement(src, tgt);
if (src.hasParty())
tgt.setParty(convertReference(src.getParty()));
if (src.hasOnHold())
tgt.setOnHoldElement(convertBoolean(src.getOnHoldElement()));
if (src.hasPeriod())
tgt.setPeriod(convertPeriod(src.getPeriod()));
return tgt;
}
}

View File

@ -0,0 +1,154 @@
package org.hl7.fhir.convertors.conv30_40;
import org.hl7.fhir.convertors.VersionConvertor_30_40;
import org.hl7.fhir.exceptions.FHIRException;
/*
Copyright (c) 2011+, HL7, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of HL7 nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
public class Coverage30_40 extends VersionConvertor_30_40 {
public static org.hl7.fhir.dstu3.model.Coverage convertCoverage(org.hl7.fhir.r4.model.Coverage src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.dstu3.model.Coverage tgt = new org.hl7.fhir.dstu3.model.Coverage();
copyDomainResource(src, tgt);
for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t));
if (src.hasStatus())
tgt.setStatusElement(convertCoverageStatus(src.getStatusElement()));
if (src.hasType())
tgt.setType(convertCodeableConcept(src.getType()));
if (src.hasPolicyHolder())
tgt.setPolicyHolder(convertReference(src.getPolicyHolder()));
if (src.hasSubscriber())
tgt.setSubscriber(convertReference(src.getSubscriber()));
if (src.hasSubscriberId())
tgt.setSubscriberIdElement(convertString(src.getSubscriberIdElement()));
if (src.hasBeneficiary())
tgt.setBeneficiary(convertReference(src.getBeneficiary()));
if (src.hasDependent())
tgt.setDependentElement(convertString(src.getDependentElement()));
if (src.hasRelationship())
tgt.setRelationship(convertCodeableConcept(src.getRelationship()));
if (src.hasPeriod())
tgt.setPeriod(convertPeriod(src.getPeriod()));
for (org.hl7.fhir.r4.model.Reference t : src.getPayor()) tgt.addPayor(convertReference(t));
if (src.hasOrder())
tgt.setOrderElement(convertPositiveInt(src.getOrderElement()));
if (src.hasNetwork())
tgt.setNetworkElement(convertString(src.getNetworkElement()));
for (org.hl7.fhir.r4.model.Reference t : src.getContract()) tgt.addContract(convertReference(t));
return tgt;
}
public static org.hl7.fhir.r4.model.Coverage convertCoverage(org.hl7.fhir.dstu3.model.Coverage src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.r4.model.Coverage tgt = new org.hl7.fhir.r4.model.Coverage();
copyDomainResource(src, tgt);
for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t));
if (src.hasStatus())
tgt.setStatusElement(convertCoverageStatus(src.getStatusElement()));
if (src.hasType())
tgt.setType(convertCodeableConcept(src.getType()));
if (src.hasPolicyHolder())
tgt.setPolicyHolder(convertReference(src.getPolicyHolder()));
if (src.hasSubscriber())
tgt.setSubscriber(convertReference(src.getSubscriber()));
if (src.hasSubscriberId())
tgt.setSubscriberIdElement(convertString(src.getSubscriberIdElement()));
if (src.hasBeneficiary())
tgt.setBeneficiary(convertReference(src.getBeneficiary()));
if (src.hasDependent())
tgt.setDependentElement(convertString(src.getDependentElement()));
if (src.hasRelationship())
tgt.setRelationship(convertCodeableConcept(src.getRelationship()));
if (src.hasPeriod())
tgt.setPeriod(convertPeriod(src.getPeriod()));
for (org.hl7.fhir.dstu3.model.Reference t : src.getPayor()) tgt.addPayor(convertReference(t));
if (src.hasOrder())
tgt.setOrderElement(convertPositiveInt(src.getOrderElement()));
if (src.hasNetwork())
tgt.setNetworkElement(convertString(src.getNetworkElement()));
for (org.hl7.fhir.dstu3.model.Reference t : src.getContract()) tgt.addContract(convertReference(t));
return tgt;
}
static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Coverage.CoverageStatus> convertCoverageStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Coverage.CoverageStatus> src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Coverage.CoverageStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Coverage.CoverageStatusEnumFactory());
VersionConvertor_30_40.copyElement(src, tgt);
switch(src.getValue()) {
case ACTIVE:
tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.ACTIVE);
break;
case CANCELLED:
tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.CANCELLED);
break;
case DRAFT:
tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.DRAFT);
break;
case ENTEREDINERROR:
tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.ENTEREDINERROR);
break;
default:
tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.NULL);
break;
}
return tgt;
}
static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Coverage.CoverageStatus> convertCoverageStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Coverage.CoverageStatus> src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Coverage.CoverageStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Coverage.CoverageStatusEnumFactory());
VersionConvertor_30_40.copyElement(src, tgt);
switch(src.getValue()) {
case ACTIVE:
tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.ACTIVE);
break;
case CANCELLED:
tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.CANCELLED);
break;
case DRAFT:
tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.DRAFT);
break;
case ENTEREDINERROR:
tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.ENTEREDINERROR);
break;
default:
tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.NULL);
break;
}
return tgt;
}
}

View File

@ -43,6 +43,9 @@ public class MedicationRequest30_40 {
tgt.setPriorPrescription(VersionConvertor_30_40.convertReference(src.getPriorPrescription())); tgt.setPriorPrescription(VersionConvertor_30_40.convertReference(src.getPriorPrescription()));
for (org.hl7.fhir.dstu3.model.Reference t : src.getDetectedIssue()) tgt.addDetectedIssue(VersionConvertor_30_40.convertReference(t)); for (org.hl7.fhir.dstu3.model.Reference t : src.getDetectedIssue()) tgt.addDetectedIssue(VersionConvertor_30_40.convertReference(t));
for (org.hl7.fhir.dstu3.model.Reference t : src.getEventHistory()) tgt.addEventHistory(VersionConvertor_30_40.convertReference(t)); for (org.hl7.fhir.dstu3.model.Reference t : src.getEventHistory()) tgt.addEventHistory(VersionConvertor_30_40.convertReference(t));
if (src.hasRequester() && src.getRequester().hasAgent()) {
tgt.setRequester(VersionConvertor_30_40.convertReference(src.getRequester().getAgent()));
}
return tgt; return tgt;
} }
@ -84,6 +87,9 @@ public class MedicationRequest30_40 {
tgt.setPriorPrescription(VersionConvertor_30_40.convertReference(src.getPriorPrescription())); tgt.setPriorPrescription(VersionConvertor_30_40.convertReference(src.getPriorPrescription()));
for (org.hl7.fhir.r4.model.Reference t : src.getDetectedIssue()) tgt.addDetectedIssue(VersionConvertor_30_40.convertReference(t)); for (org.hl7.fhir.r4.model.Reference t : src.getDetectedIssue()) tgt.addDetectedIssue(VersionConvertor_30_40.convertReference(t));
for (org.hl7.fhir.r4.model.Reference t : src.getEventHistory()) tgt.addEventHistory(VersionConvertor_30_40.convertReference(t)); for (org.hl7.fhir.r4.model.Reference t : src.getEventHistory()) tgt.addEventHistory(VersionConvertor_30_40.convertReference(t));
if (src.hasRequester()) {
tgt.getRequester().setAgent(VersionConvertor_30_40.convertReference(src.getRequester()));
}
return tgt; return tgt;
} }

View File

@ -40,7 +40,7 @@ public class RelatedPerson30_40 {
tgt.setGenderElement(VersionConvertor_30_40.convertAdministrativeGender(src.getGenderElement())); tgt.setGenderElement(VersionConvertor_30_40.convertAdministrativeGender(src.getGenderElement()));
} }
if (src.hasBirthDate()) { if (src.hasBirthDate()) {
tgt.setBirthDate(tgt.getBirthDate()); tgt.setBirthDate(src.getBirthDate());
} }
for (org.hl7.fhir.r4.model.Address t : src.getAddress()) { for (org.hl7.fhir.r4.model.Address t : src.getAddress()) {
tgt.addAddress(VersionConvertor_30_40.convertAddress(t)); tgt.addAddress(VersionConvertor_30_40.convertAddress(t));
@ -84,7 +84,7 @@ public class RelatedPerson30_40 {
tgt.setGenderElement(VersionConvertor_30_40.convertAdministrativeGender(src.getGenderElement())); tgt.setGenderElement(VersionConvertor_30_40.convertAdministrativeGender(src.getGenderElement()));
} }
if (src.hasBirthDate()) { if (src.hasBirthDate()) {
tgt.setBirthDate(tgt.getBirthDate()); tgt.setBirthDate(src.getBirthDate());
} }
for (org.hl7.fhir.dstu3.model.Address t : src.getAddress()) { for (org.hl7.fhir.dstu3.model.Address t : src.getAddress()) {
tgt.addAddress(VersionConvertor_30_40.convertAddress(t)); tgt.addAddress(VersionConvertor_30_40.convertAddress(t));

View File

@ -183,7 +183,7 @@ public class JsonParser extends ParserBase {
} }
public void parseChildItem(String path, JsonObject object, Element context, Set<String> processed, Property property) { public void parseChildItem(String path, JsonObject object, Element context, Set<String> processed, Property property) {
if (property.isChoice()) { if (property.isChoice() || property.getDefinition().getPath().endsWith("data[x]")) {
for (TypeRefComponent type : property.getDefinition().getType()) { for (TypeRefComponent type : property.getDefinition().getType()) {
String eName = property.getName().substring(0, property.getName().length()-3) + Utilities.capitalize(type.getWorkingCode()); String eName = property.getName().substring(0, property.getName().length()-3) + Utilities.capitalize(type.getWorkingCode());
if (!isPrimitive(type.getWorkingCode()) && object.has(eName)) { if (!isPrimitive(type.getWorkingCode()) && object.has(eName)) {

View File

@ -184,7 +184,7 @@ public class JsonParser extends ParserBase {
} }
public void parseChildItem(String path, JsonObject object, Element context, Set<String> processed, Property property) { public void parseChildItem(String path, JsonObject object, Element context, Set<String> processed, Property property) {
if (property.isChoice()) { if (property.isChoice() || property.getDefinition().getPath().endsWith("data[x]")) {
for (TypeRefComponent type : property.getDefinition().getType()) { for (TypeRefComponent type : property.getDefinition().getType()) {
String eName = property.getName().substring(0, property.getName().length()-3) + Utilities.capitalize(type.getWorkingCode()); String eName = property.getName().substring(0, property.getName().length()-3) + Utilities.capitalize(type.getWorkingCode());
if (!isPrimitive(type.getWorkingCode()) && object.has(eName)) { if (!isPrimitive(type.getWorkingCode()) && object.has(eName)) {

View File

@ -206,7 +206,7 @@ public class Property {
if (definition.getType().size() > 0) if (definition.getType().size() > 0)
return definition.getType().size() == 1 && ("Resource".equals(definition.getType().get(0).getCode()) || "DomainResource".equals(definition.getType().get(0).getCode())); return definition.getType().size() == 1 && ("Resource".equals(definition.getType().get(0).getCode()) || "DomainResource".equals(definition.getType().get(0).getCode()));
else else
return !definition.getPath().contains(".") && (structure.getKind() == StructureDefinitionKind.RESOURCE || structure.getKind() == StructureDefinitionKind.LOGICAL); return !definition.getPath().contains(".") && (structure.getKind() == StructureDefinitionKind.RESOURCE);
} }
public boolean isList() { public boolean isList() {

View File

@ -1,33 +1,33 @@
package org.hl7.fhir.r5.elementmodel; package org.hl7.fhir.r5.elementmodel;
/* /*
Copyright (c) 2011+, HL7, Inc. Copyright (c) 2011+, HL7, Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met: are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of HL7 nor the names of its contributors may be used to * Neither the name of HL7 nor the names of its contributors may be used to
endorse or promote products derived from this software without specific endorse or promote products derived from this software without specific
prior written permission. prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
import java.io.IOException; import java.io.IOException;
@ -210,6 +210,10 @@ public class XmlParser extends ParserBase {
return "h:"; return "h:";
if (ns.equals("urn:hl7-org:v3")) if (ns.equals("urn:hl7-org:v3"))
return "v3:"; return "v3:";
if (ns.equals("urn:hl7-org:sdtc"))
return "sdtc:";
if (ns.equals("urn:ihe:pharm"))
return "pharm:";
return "?:"; return "?:";
} }
@ -538,11 +542,31 @@ public class XmlParser extends ParserBase {
xml.setDefaultNamespace(e.getProperty().getXmlNamespace()); xml.setDefaultNamespace(e.getProperty().getXmlNamespace());
if (hasTypeAttr(e)) if (hasTypeAttr(e))
xml.namespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); xml.namespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
addNamespaces(xml, e);
composeElement(xml, e, e.getType(), true); composeElement(xml, e, e.getType(), true);
xml.end(); xml.end();
} }
private void addNamespaces(IXMLWriter xml, Element e) throws IOException {
String ns = e.getProperty().getXmlNamespace();
if (ns!=null && !xml.getDefaultNamespace().equals(ns)){
if (!xml.namespaceDefined(ns)) {
String prefix = pathPrefix(ns);
if (prefix.endsWith(":")) {
prefix = prefix.substring(0, prefix.length()-1);
}
if ("?".equals(prefix)) {
xml.namespace(ns);
} else {
xml.namespace(ns, prefix);
}
}
}
for (Element c : e.getChildren()) {
addNamespaces(xml, c);
}
}
private boolean hasTypeAttr(Element e) { private boolean hasTypeAttr(Element e) {
if (isTypeAttr(e.getProperty())) if (isTypeAttr(e.getProperty()))
return true; return true;
@ -584,9 +608,9 @@ public class XmlParser extends ParserBase {
if (isText(element.getProperty())) { if (isText(element.getProperty())) {
if (linkResolver != null) if (linkResolver != null)
xml.link(linkResolver.resolveProperty(element.getProperty())); xml.link(linkResolver.resolveProperty(element.getProperty()));
xml.enter(elementName); xml.enter(element.getProperty().getXmlNamespace(),elementName);
xml.text(element.getValue()); xml.text(element.getValue());
xml.exit(elementName); xml.exit(element.getProperty().getXmlNamespace(),elementName);
} else if (!element.hasChildren() && !element.hasValue()) { } else if (!element.hasChildren() && !element.hasValue()) {
if (element.getExplicitType() != null) if (element.getExplicitType() != null)
xml.attribute("xsi:type", element.getExplicitType()); xml.attribute("xsi:type", element.getExplicitType());
@ -595,7 +619,7 @@ public class XmlParser extends ParserBase {
if (element.getType().equals("xhtml")) { if (element.getType().equals("xhtml")) {
String rawXhtml = element.getValue(); String rawXhtml = element.getValue();
if (isCdaText(element.getProperty())) { if (isCdaText(element.getProperty())) {
new CDANarrativeFormat().convert(xml, element.getXhtml()); new CDANarrativeFormat().convert(xml, new XhtmlParser().parseFragment(rawXhtml));
} else { } else {
xml.escapedText(rawXhtml); xml.escapedText(rawXhtml);
xml.anchor("end-xhtml"); xml.anchor("end-xhtml");
@ -614,10 +638,10 @@ public class XmlParser extends ParserBase {
if (linkResolver != null) if (linkResolver != null)
xml.link(linkResolver.resolveProperty(element.getProperty())); xml.link(linkResolver.resolveProperty(element.getProperty()));
if (element.hasChildren()) { if (element.hasChildren()) {
xml.enter(elementName); xml.enter(element.getProperty().getXmlNamespace(), elementName);
for (Element child : element.getChildren()) for (Element child : element.getChildren())
composeElement(xml, child, child.getName(), false); composeElement(xml, child, child.getName(), false);
xml.exit(elementName); xml.exit(element.getProperty().getXmlNamespace(),elementName);
} else } else
xml.element(elementName); xml.element(elementName);
} }
@ -630,16 +654,16 @@ public class XmlParser extends ParserBase {
String av = child.getValue(); String av = child.getValue();
if (ToolingExtensions.hasExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat")) if (ToolingExtensions.hasExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"))
av = convertForDateFormatToExternal(ToolingExtensions.readStringExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"), av); av = convertForDateFormatToExternal(ToolingExtensions.readStringExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"), av);
xml.attribute(child.getName(), av); xml.attribute(child.getProperty().getXmlNamespace(),child.getProperty().getXmlName(), av);
} }
} }
if (linkResolver != null) if (linkResolver != null)
xml.link(linkResolver.resolveProperty(element.getProperty())); xml.link(linkResolver.resolveProperty(element.getProperty()));
xml.enter(elementName); xml.enter(element.getProperty().getXmlNamespace(),elementName);
if (!root && element.getSpecial() != null) { if (!root && element.getSpecial() != null) {
if (linkResolver != null) if (linkResolver != null)
xml.link(linkResolver.resolveProperty(element.getProperty())); xml.link(linkResolver.resolveProperty(element.getProperty()));
xml.enter(element.getType()); xml.enter(element.getProperty().getXmlNamespace(),element.getType());
} }
for (Element child : element.getChildren()) { for (Element child : element.getChildren()) {
if (isText(child.getProperty())) { if (isText(child.getProperty())) {
@ -650,8 +674,8 @@ public class XmlParser extends ParserBase {
composeElement(xml, child, child.getName(), false); composeElement(xml, child, child.getName(), false);
} }
if (!root && element.getSpecial() != null) if (!root && element.getSpecial() != null)
xml.exit(element.getType()); xml.exit(element.getProperty().getXmlNamespace(),element.getType());
xml.exit(elementName); xml.exit(element.getProperty().getXmlNamespace(),elementName);
} }
} }

View File

@ -1,11 +1,14 @@
package org.hl7.fhir.r5.test; package org.hl7.fhir.r5.test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.elementmodel.Manager; import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.FHIRPathEngine;
@ -13,22 +16,33 @@ import org.hl7.fhir.utilities.cache.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.cache.ToolsVersion; import org.hl7.fhir.utilities.cache.ToolsVersion;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class CDARoundTripTests { public class CDARoundTripTests {
// private SimpleWorkerContext context; private static SimpleWorkerContext context;
// old-test private FHIRPathEngine fp; private static FHIRPathEngine fp;
@BeforeAll @BeforeAll
public static void setUp() throws Exception { public static void setUp() throws Exception {
// old-test context = new SimpleWorkerContext(); FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
// old-test PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
// old-test context.loadFromPackage(pcm.loadPackage("hl7.fhir.core", "dev"), null, "StructureDefinition"); fp = new FHIRPathEngine(context);
// old-test context.loadFromPackage(pcm.loadPackage("hl7.fhir.cda", "dev"), null, "StructureDefinition");
// old-test fp = new FHIRPathEngine(context); context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null);
} context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ce.xml"), "ce.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ed.xml"), "ed.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "st.xml"), "st.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cda.xml"), "cda.xml", null);
for (StructureDefinition sd : context.getStructures()) {
if (!sd.hasSnapshot()) {
System.out.println("generate snapshot for " + sd.getUrl());
context.generateSnapshot(sd, true);
}
}
}
// old-test // old-test
// @Test // @Test
@ -172,29 +186,57 @@ public class CDARoundTripTests {
// FhirFormat.TURTLE, OutputStyle.PRETTY, null); // FhirFormat.TURTLE, OutputStyle.PRETTY, null);
// } // }
public void assertsExample(Element cdaExample) {
@Test Assertions.assertEquals("2.16.840.1.113883.3.27.1776", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.templateId.root")));
public void testSimple() throws IOException { Assertions.assertEquals("SoEN", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.displayName")));
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); Assertions.assertEquals("SoEN2", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.sdtcDisplayName")));
SimpleWorkerContext context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); Assertions.assertEquals("c266", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.id.extension")));
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null); Assertions.assertEquals("2.16.840.1.113883.19.4", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.id.root")));
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null); Assertions.assertEquals("X-34133-9", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.code")));
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null); Assertions.assertEquals("2.16.840.1.113883.6.1", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.codeSystem")));
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ce.xml"), "ce.xml", null); Assertions.assertEquals("LOINC", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.codeSystemName")));
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ed.xml"), "ed.xml", null); Assertions.assertEquals("Episode Note", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.title.dataString")));
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "st.xml"), "st.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cda.xml"), "cda.xml", null);
for (StructureDefinition sd : context.getStructures()) {
if (!sd.hasSnapshot()) {
System.out.println("generate snapshot for " + sd.getUrl());
context.generateSnapshot(sd, true);
}
}
Element cda = Manager.parse(context, TestingUtilities.loadTestResourceStream("validator", "cda", "example.xml"), FhirFormat.XML);
FHIRPathEngine fp = new FHIRPathEngine(context);
Assertions.assertEquals("2.16.840.1.113883.3.27.1776", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.templateId.root")));
Assertions.assertEquals("SoEN", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.code.displayName")));
Assertions.assertEquals("SoEN2", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.code.sdtcDisplayName")));
} }
@Test
/**
* Deserializes a simplified CDA example into the logical model and checks that
* xml deserialization/serialization
*
* @throws IOException
*/
public void testClinicalDocumentXmlParser() throws IOException {
Element cda = Manager.parse(context, TestingUtilities.loadTestResourceStream("validator", "cda", "example.xml"),
FhirFormat.XML);
assertsExample(cda);
ByteArrayOutputStream baosXml = new ByteArrayOutputStream();
Manager.compose(context, cda, baosXml, FhirFormat.XML, OutputStyle.PRETTY, null);
Element cdaXmlRoundtrip = Manager.parse(context, new ByteArrayInputStream(baosXml.toString().getBytes()), FhirFormat.XML);
assertsExample(cdaXmlRoundtrip);
}
@Test
/**
* Deserializes a simplified CDA example into the logical model and checks that
* json deserialization/serialization works
*
* @throws IOException
*/
public void testClinicalDocumentJsonParser() throws IOException {
Element cda = Manager.parse(context, TestingUtilities.loadTestResourceStream("validator", "cda", "example.xml"),
FhirFormat.XML);
assertsExample(cda);
ByteArrayOutputStream baosJson = new ByteArrayOutputStream();
Manager.compose(context, cda, baosJson, FhirFormat.JSON, OutputStyle.PRETTY, null);
Element cdaJsonRoundtrip = Manager.parse(context, new ByteArrayInputStream(baosJson.toString().getBytes()),
FhirFormat.JSON);
assertsExample(cdaJsonRoundtrip);
}
} }

View File

@ -1,41 +1,28 @@
package org.hl7.fhir.r5.test; package org.hl7.fhir.r5.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.formats.IParser;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.ResourceFactory;
import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.model.StructureMap; import org.hl7.fhir.r5.model.StructureMap;
import org.hl7.fhir.r5.terminologies.ConceptMapEngine;
import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.StructureMapUtilities;
import org.hl7.fhir.r5.utils.StructureMapUtilities.ITransformerServices;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.cache.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.cache.ToolsVersion;
import org.hl7.fhir.utilities.xml.XMLUtil; import org.hl7.fhir.utilities.xml.XMLUtil;
import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.validation.instance.InstanceValidatorFactory; import org.hl7.fhir.validation.instance.InstanceValidatorFactory;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
@ -45,12 +32,13 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
public class FHIRMappingLanguageTests implements ITransformerServices { public class FHIRMappingLanguageTests {
private List<Resource> outputs = new ArrayList<Resource>(); private List<Resource> outputs = new ArrayList<Resource>();
static private ValidationEngine validationEngine;
static private SimpleWorkerContext context; static private SimpleWorkerContext context;
static private JsonParser jsonParser;
public static Stream<Arguments> data() public static Stream<Arguments> data()
throws FileNotFoundException, IOException, ParserConfigurationException, SAXException { throws FileNotFoundException, IOException, ParserConfigurationException, SAXException {
@ -67,91 +55,63 @@ public class FHIRMappingLanguageTests implements ITransformerServices {
@BeforeAll @BeforeAll
public static void setUp() throws Exception { public static void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); validationEngine = new ValidationEngine("hl7.fhir.r4.core#4.0.1");
context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r5.core", "current")); context = validationEngine.getContext();
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ce.xml"), "ce.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ed.xml"), "ed.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "st.xml"), "st.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cda.xml"), "cda.xml", null);
for (StructureDefinition sd : context.getStructures()) {
if (!sd.hasSnapshot()) {
System.out.println("generate snapshot for " + sd.getUrl());
context.generateSnapshot(sd, true);
}
}
if (context.getValidatorFactory() == null) { if (context.getValidatorFactory() == null) {
context.setValidatorFactory(new InstanceValidatorFactory()); context.setValidatorFactory(new InstanceValidatorFactory());
} }
jsonParser = new JsonParser();
jsonParser.setOutputStyle(OutputStyle.PRETTY);
} }
@ParameterizedTest(name = "{index}: {0}") @ParameterizedTest(name = "{index}: {0}")
@MethodSource("data") @MethodSource("data")
public void test(String name, String source, String map, String output) throws Exception { public void test(String name, String source, String map, String output) throws Exception {
InputStream fileSource = TestingUtilities.loadTestResourceStream("r5", "fml", source); byte[] byteSource = TestingUtilities.loadTestResourceBytes("r5", "fml", source);
InputStream fileMap = TestingUtilities.loadTestResourceStream("r5", "fml", map); String stringMap = TestingUtilities.loadTestResource("r5", "fml", map);
String outputJson = TestingUtilities.loadTestResource("r5", "fml", output); String outputJson = TestingUtilities.loadTestResource("r5", "fml", output);
String fileOutputRes = TestingUtilities.tempFile("fml", output) + ".out"; String fileOutputRes = TestingUtilities.tempFile("fml", output) + ".out";
String fileOutputResOrig = TestingUtilities.tempFile("fml", output) + ".orig.out";
ByteArrayOutputStream s = null;
outputs.clear(); outputs.clear();
boolean ok = false;
String msg = null; String msg = null;
Resource resource = null;
try { try {
StructureMapUtilities scu = new StructureMapUtilities(context, this); StructureMap r = new org.hl7.fhir.r5.utils.StructureMapUtilities(context).parse(stringMap, map);
org.hl7.fhir.r5.elementmodel.Element src = Manager.parse(context, context.cacheResource(r);
new ByteArrayInputStream(TextFile.streamToBytes(fileSource)), FhirFormat.JSON); org.hl7.fhir.r5.elementmodel.Element element = validationEngine.transform(byteSource, FhirFormat.JSON, r.getUrl());
StructureMap structureMap = scu.parse(TextFile.streamToString(fileMap), name); s = new ByteArrayOutputStream();
String typeName = scu.getTargetType(structureMap).getType(); if (output.endsWith(".json"))
resource = ResourceFactory.createResource(typeName); new org.hl7.fhir.r5.elementmodel.JsonParser(context).compose(element, s, IParser.OutputStyle.PRETTY, null);
scu.transform(null, src, structureMap, resource); else
ok = true; new org.hl7.fhir.r5.elementmodel.XmlParser(context).compose(element, s, IParser.OutputStyle.PRETTY, null);
context.dropResource(r);
} catch (Exception e) { } catch (Exception e) {
ok = false; assertTrue(e.getMessage(), false);
msg = e.getMessage();
} }
if (ok) { if (output.endsWith("json")) {
ByteArrayOutputStream boas = new ByteArrayOutputStream(); msg = TestingUtilities.checkJsonSrcIsSame(s.toString(), outputJson);
jsonParser.compose(boas, resource);
String result = boas.toString();
log(result);
TextFile.bytesToFile(boas.toByteArray(), fileOutputRes);
msg = TestingUtilities.checkJsonSrcIsSame(result, outputJson);
assertTrue(msg, Utilities.noString(msg));
} else
assertEquals("Error, but proper output was expected (" + msg + ")", "$error", output);
}
@Override
public void log(String message) {
System.out.println(message);
}
@Override
public Base createType(Object appInfo, String name) throws FHIRException {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, name);
if (sd != null && sd.getKind() == StructureDefinitionKind.LOGICAL) {
return Manager.build(context, sd);
} else { } else {
if (name.startsWith("http://hl7.org/fhir/StructureDefinition/")) TextFile.bytesToFile(s.toByteArray(), fileOutputRes);
name = name.substring("http://hl7.org/fhir/StructureDefinition/".length()); TextFile.bytesToFile(outputJson.getBytes(), fileOutputResOrig);
return ResourceFactory.createResourceOrType(name); msg = TestingUtilities.checkXMLIsSame(new FileInputStream(fileOutputRes), new FileInputStream(fileOutputResOrig));
} }
if (!Utilities.noString(msg)) {
System.out.print(s.toString());
}
assertTrue(msg, Utilities.noString(msg));
} }
@Override
public Base createResource(Object appInfo, Base res, boolean atRootofTransform) {
if (atRootofTransform)
outputs.add((Resource) res);
return res;
}
@Override
public Coding translate(Object appInfo, Coding source, String conceptMapUrl) throws FHIRException {
ConceptMapEngine cme = new ConceptMapEngine(context);
return cme.translate(source, conceptMapUrl);
}
@Override
public Base resolveReference(Object appContext, String url) throws FHIRException {
throw new FHIRException("resolveReference is not supported yet");
}
@Override
public List<Base> performSearch(Object appContext, String url) throws FHIRException {
throw new FHIRException("performSearch is not supported yet");
}
} }