fix bug converting search parameters

This commit is contained in:
Grahame Grieve 2019-06-19 06:40:36 +10:00
parent c002d5b5d1
commit 5e6755e422
6 changed files with 309 additions and 45 deletions

View File

@ -54,6 +54,22 @@ public class VersionConvertor_40_50 {
}
}
protected static void copyEnumeration(org.hl7.fhir.r4.model.Enumeration<?> src, org.hl7.fhir.r5.model.Enumeration<?> tgt) throws FHIRException {
if (src.hasId())
tgt.setId(src.getId());
for (org.hl7.fhir.r4.model.Extension e : src.getExtension()) {
tgt.addExtension(convertExtension(e));
}
}
protected static void copyEnumeration(org.hl7.fhir.r5.model.Enumeration<?> src, org.hl7.fhir.r4.model.Enumeration<?> tgt) throws FHIRException {
if (src.hasId())
tgt.setId(src.getId());
for (org.hl7.fhir.r5.model.Extension e : src.getExtension()) {
tgt.addExtension(convertExtension(e));
}
}
protected static void copyBackboneElement(org.hl7.fhir.r4.model.BackboneElement src, org.hl7.fhir.r5.model.BackboneElement tgt) throws FHIRException {
copyElement(src, tgt);
for (org.hl7.fhir.r4.model.Extension e : src.getModifierExtension()) {

View File

@ -91,7 +91,7 @@ public class SearchParameter extends VersionConvertor_40_50 {
for (org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchComparator> t : src.getComparator())
tgt.addComparator(convertSearchComparator(t.getValue()));
for (org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode> t : src.getModifier())
tgt.addModifier(convertSearchModifierCode(t.getValue()));
tgt.getModifier().add(convertSearchModifierCode(t));
for (org.hl7.fhir.r4.model.StringType t : src.getChain())
tgt.getChain().add(convertString(t));
for (org.hl7.fhir.r4.model.SearchParameter.SearchParameterComponentComponent t : src.getComponent())
@ -151,7 +151,7 @@ public class SearchParameter extends VersionConvertor_40_50 {
for (org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchComparator> t : src.getComparator())
tgt.addComparator(convertSearchComparator(t.getValue()));
for (org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode> t : src.getModifier())
tgt.addModifier(convertSearchModifierCode(t.getValue()));
tgt.getModifier().add(convertSearchModifierCode(t));
for (org.hl7.fhir.r5.model.StringType t : src.getChain())
tgt.getChain().add(convertString(t));
for (org.hl7.fhir.r5.model.SearchParameter.SearchParameterComponentComponent t : src.getComponent())
@ -219,45 +219,51 @@ public class SearchParameter extends VersionConvertor_40_50 {
}
}
public static org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode convertSearchModifierCode(org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode src) throws FHIRException {
public static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode> convertSearchModifierCode(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode> src) throws FHIRException {
if (src == null)
return null;
switch (src) {
case MISSING: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.MISSING;
case EXACT: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.EXACT;
case CONTAINS: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.CONTAINS;
case NOT: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.NOT;
case TEXT: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.TEXT;
case IN: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.IN;
case NOTIN: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.NOTIN;
case BELOW: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.BELOW;
case ABOVE: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.ABOVE;
case TYPE: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.TYPE;
case IDENTIFIER: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.IDENTIFIER;
case OFTYPE: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.OFTYPE;
default: return org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.NULL;
org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode> tgt = new org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode>();
copyEnumeration(src, tgt);
switch (src.getValue()) {
case MISSING: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.MISSING);
case EXACT: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.EXACT);
case CONTAINS: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.CONTAINS);
case NOT: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.NOT);
case TEXT: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.TEXT);
case IN: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.IN);
case NOTIN: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.NOTIN);
case BELOW: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.BELOW);
case ABOVE: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.ABOVE);
case TYPE: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.TYPE);
case IDENTIFIER: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.IDENTIFIER);
case OFTYPE: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.OFTYPE);
default: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.NULL);
}
return tgt;
}
}
public static org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode convertSearchModifierCode(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode src) throws FHIRException {
public static org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode> convertSearchModifierCode(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode> src) throws FHIRException {
if (src == null)
return null;
switch (src) {
case MISSING: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.MISSING;
case EXACT: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.EXACT;
case CONTAINS: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.CONTAINS;
case NOT: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.NOT;
case TEXT: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.TEXT;
case IN: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.IN;
case NOTIN: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.NOTIN;
case BELOW: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.BELOW;
case ABOVE: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.ABOVE;
case TYPE: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.TYPE;
case IDENTIFIER: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.IDENTIFIER;
case OFTYPE: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.OFTYPE;
default: return org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.NULL;
org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode> tgt = new org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode>();
copyEnumeration(src, tgt);
switch (src.getValue()) {
case MISSING: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.MISSING);
case EXACT: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.EXACT);
case CONTAINS: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.CONTAINS);
case NOT: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.NOT);
case TEXT: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.TEXT);
case IN: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.IN);
case NOTIN: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.NOTIN);
case BELOW: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.BELOW);
case ABOVE: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.ABOVE);
case TYPE: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.TYPE);
case IDENTIFIER: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.IDENTIFIER);
case OFTYPE: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.OFTYPE);
default: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.NULL);
}
return tgt;
}
}
public static org.hl7.fhir.r5.model.SearchParameter.SearchParameterComponentComponent convertSearchParameterComponentComponent(org.hl7.fhir.r4.model.SearchParameter.SearchParameterComponentComponent src) throws FHIRException {
if (src == null)

View File

@ -0,0 +1,213 @@
package org.hl7.fhir.r5.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.fhir.ucum.Utilities;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.ConceptMap;
import org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent;
import org.hl7.fhir.r5.model.DateTimeType;
import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
import org.hl7.fhir.r5.model.MetadataResource;
import org.hl7.fhir.r5.model.UrlType;
import org.hl7.fhir.utilities.CSVReader;
public class MappingSheetParser {
public class MappingRow {
private String sequence;
private String identifier;
private String name;
private String dataType;
private String cardinality;
private String condition;
private String attribute;
private String type;
private String minMax;
private String dtMapping;
private String vocabMapping;
private String derived;
private String derivedMapping;
private String comments;
public String getSequence() {
return sequence;
}
public String getIdentifier() {
return identifier;
}
public String getName() {
return name;
}
public String getDataType() {
return dataType;
}
public String getCardinality() {
return cardinality;
}
public String getCondition() {
return condition;
}
public String getAttribute() {
return attribute;
}
public String getType() {
return type;
}
public String getMinMax() {
return minMax;
}
public String getDtMapping() {
return dtMapping;
}
public String getVocabMapping() {
return vocabMapping;
}
public String getDerived() {
return derived;
}
public String getDerivedMapping() {
return derivedMapping;
}
public String getComments() {
return comments;
}
}
private CSVReader csv;
private List<MappingRow> rows = new ArrayList<>();
private Map<String, String> metadata = new HashMap<>();
public MappingSheetParser(InputStream stream, String name) throws FHIRException, IOException {
super();
this.csv = new CSVReader(stream);
checkHeaders1(name);
checkHeaders2(name);
while (csv.line()) {
processRow();
}
}
private void checkHeaders1(String name) throws FHIRException, IOException {
csv.readHeaders();
csv.checkColumn(1, "HL7 v2", "Mapping Sheet "+name);
csv.checkColumn(6, "Condition (IF True)", "Mapping Sheet "+name);
csv.checkColumn(7, "HL7 FHIR", "Mapping Sheet "+name);
csv.checkColumn(14, "Comments", "Mapping Sheet "+name);
csv.checkColumn(16, "Name", "Mapping Sheet "+name);
csv.checkColumn(17, "Value", "Mapping Sheet "+name);
}
private void checkHeaders2(String name) throws FHIRException, IOException {
csv.readHeaders();
csv.checkColumn(1, "Display Sequence", "Mapping Sheet "+name);
csv.checkColumn(2, "Identifier", "Mapping Sheet "+name);
csv.checkColumn(3, "Name", "Mapping Sheet "+name);
csv.checkColumn(4, "Data Type", "Mapping Sheet "+name);
csv.checkColumn(5, "Cardinality", "Mapping Sheet "+name);
csv.checkColumn(7, "FHIR Attribute", "Mapping Sheet "+name);
csv.checkColumn(8, "Data Type", "Mapping Sheet "+name);
csv.checkColumn(9, "Cardinality", "Mapping Sheet "+name);
csv.checkColumn(10, "Data Type Mapping", "Mapping Sheet "+name);
csv.checkColumn(11, "Vocabulary Mapping\n(IS, ID, CE, CNE, CWE)", "Mapping Sheet "+name);
csv.checkColumn(12, "Derived Mapping", "Mapping Sheet "+name);
}
private void processRow() {
MappingRow mr = new MappingRow();
mr.sequence = csv.value(1);
mr.identifier = csv.value(2);
mr.name = csv.value(3);
mr.dataType = csv.value(4);
mr.cardinality = csv.value(5);
mr.condition = csv.value(6);
mr.attribute = csv.value(7);
mr.type = csv.value(8);
mr.minMax = csv.value(9);
mr.dtMapping = csv.value(10);
mr.vocabMapping = csv.value(11);
mr.derived = csv.value(12);
if (!Utilities.noString(mr.derived)) {
String[] s = mr.derived.split("\\=");
mr.derived = s[0].trim();
mr.derivedMapping = s[1].trim();
}
mr.comments = csv.value(14);
rows.add(mr);
if (!org.hl7.fhir.utilities.Utilities.noString(csv.value(16)))
metadata.put(csv.value(16), csv.value(17));
}
public List<MappingRow> getRows() {
return rows;
}
public ConceptMap getConceptMap() throws FHIRException {
ConceptMap map = new ConceptMap();
loadMetadata(map);
if (metadata.containsKey("copyright"))
map.setCopyright(metadata.get("copyright"));
for (MappingRow row : rows) {
SourceElementComponent element = map.getGroupFirstRep().addElement();
element.setCode(row.getIdentifier());
element.setId(row.getSequence());
element.setDisplay(row.getName()+" : "+row.getDataType()+" ["+row.getCardinality()+"]");
if (row.getCondition() != null)
element.getTargetFirstRep().addDependsOn().setProperty("http://hl7.org/fhirpath").setValue(processCondition(row.getCondition()));
element.getTargetFirstRep().setCode(row.getAttribute());
element.getTargetFirstRep().setDisplay(row.getType()+" : ["+row.getMinMax()+"]");
if (row.getDerived() != null)
element.getTargetFirstRep().getProductFirstRep().setProperty(row.getDerived()).setValue(row.getDerivedMapping());
if (row.getComments() != null)
element.getTargetFirstRep().setComment(row.getComments());
if (row.getDtMapping() != null)
element.getTargetFirstRep().addExtension("htp://hl7.org/fhir/StructureDefinition/ConceptMap-type-mapping", new UrlType("todo#"+row.getDtMapping()));
if (row.getVocabMapping() != null)
element.getTargetFirstRep().addExtension("htp://hl7.org/fhir/StructureDefinition/ConceptMap-vocab-mapping", new UrlType("todo#"+row.getVocabMapping()));
}
return map;
}
private String processCondition(String condition) {
if (condition.startsWith("IF ") && condition.endsWith(" IS VALUED"))
return "`"+condition.substring(4, condition.length()-10)+".exists()";
if (condition.startsWith("IF ") && condition.endsWith(" DOES NOT EXIST"))
return "`"+condition.substring(4, condition.length()-15)+".exists()";
throw new Error("not processed yet: "+condition);
}
private void loadMetadata(MetadataResource mr) throws FHIRException {
if (metadata.containsKey("id"))
mr.setId(metadata.get("id"));
if (metadata.containsKey("url"))
mr.setUrl(metadata.get("url"));
if (metadata.containsKey("name"))
mr.setName(metadata.get("name"));
if (metadata.containsKey("title"))
mr.setTitle(metadata.get("title"));
if (metadata.containsKey("version"))
mr.setVersion(metadata.get("version"));
if (metadata.containsKey("status"))
mr.setStatus(PublicationStatus.fromCode(metadata.get("status")));
if (metadata.containsKey("date"))
mr.setDateElement(new DateTimeType(metadata.get("date")));
if (metadata.containsKey("publisher"))
mr.setPublisher(metadata.get("publisher"));
if (metadata.containsKey("description"))
mr.setDescription(metadata.get("description"));
}
public static void main(String[] args) throws FileNotFoundException, IOException, FHIRException {
MappingSheetParser parser = new MappingSheetParser(new FileInputStream("c:\\temp\\v2-pid.csv"), "v2-pid.csv");
ConceptMap cm = parser.getConceptMap();
}
}

View File

@ -191,4 +191,21 @@ public class CSVReader extends InputStreamReader {
}
public void checkColumn(int i, String name, String desc) throws FHIRException {
if (cols.length < i)
throw new FHIRException("Error parsing "+desc+": expected column "+name+" at col "+i+" but only found "+cols.length+" cols");
if (!cols[i-1].equals(name))
throw new FHIRException("Error parsing "+desc+": expected column "+name+" at col "+i+" but found '"+cols[i-1]+"'");
}
public String value(int i) {
if (i > cells.length)
return null;
if (Utilities.noString(cells[i-1]))
return null;
return cells[i-1];
}
}

View File

@ -745,4 +745,14 @@ public class PackageCacheManager {
return res;
}
public void clear() throws IOException {
for (File f : new File(cacheFolder).listFiles()) {
if (f.isDirectory()) {
Utilities.clearDirectory(f.getAbsolutePath());
f.delete();
}
}
}
}

View File

@ -1,28 +1,30 @@
REM replace versions before running
REM make sure you are committed
@echo off
set oldver=3.8.3
set newver=3.8.4
echo ..
echo =====================================================================
echo upgrade and release fhir.core from 3.8.3-SNAPSHOT to 3.8.4-SNAPSHOT
echo upgrade and release fhir.core from %oldver%-SNAPSHOT to %newver%-SNAPSHOT
echo =====================================================================
echo ..
echo check versions and make sure committed...
pause
call mvn versions:set -DnewVersion=3.8.4-SNAPSHOT
call mvn versions:set -DnewVersion=%newver%-SNAPSHOT
call git commit -a -m "Release new version"
call git push origin master
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.java" --includeSubDirectories --find "3.8.3-SNAPSHOT" --replace "3.8.4-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\fhir-ig-publisher" --fileMask "*.xml" --includeSubDirectories --find "3.8.3-SNAPSHOT" --replace "3.8.4-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.xml" --find "3.8.3-SNAPSHOT" --replace "3.8.4-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.java" --includeSubDirectories --find "%oldver%-SNAPSHOT" --replace "%newver%-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.xml" --find "%oldver%-SNAPSHOT" --replace "%newver%-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\latest-ig-publisher" --fileMask "*.html" --find "%oldver%" --replace "%newver%"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\latest-ig-publisher" --fileMask "*.json" --find "%oldver%" --replace "%newver%"
call mvn deploy
copy org.hl7.fhir.validation.cli\target\org.hl7.fhir.validation.cli-3.8.4-SNAPSHOT.jar ..\latest-ig-publisher\org.hl7.fhir.validator.jar
copy org.hl7.fhir.validation.cli\target\org.hl7.fhir.validation.cli-%newver%-SNAPSHOT.jar ..\latest-ig-publisher\org.hl7.fhir.validator.jar
cd ..\latest-ig-publisher
call git commit -a -m "Release new version 3.8.4-SNAPSHOT"
call git commit -a -m "Release new version %newver%-SNAPSHOT"
call git push origin master
cd ..\org.hl7.fhir.core
call python c:\tools\zulip-api\zulip\zulip\send.py --stream committers/notification --subject "java core" -m "New Java Core v3.8.4-SNAPSHOT released. New Validator at https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.validation.cli&v=3.8.4-SNAPSHOT&e=jar, and also deployed at https://fhir.github.io/latest-ig-publisher/org.hl7.fhir.validator.jar" --config-file zuliprc
call python c:\tools\zulip-api\zulip\zulip\send.py --stream committers/notification --subject "java core" -m "New Java Core v%newver%-SNAPSHOT released. New Validator at https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.validation.cli&v=%newver%-SNAPSHOT&e=jar, and also deployed at https://fhir.github.io/latest-ig-publisher/org.hl7.fhir.validator.jar" --config-file zuliprc
echo ===============================================================
echo all done