From 286c8c7cd93b6c50c5156c4df6f9f5b21632a03a Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 15 Sep 2019 01:16:36 +1000 Subject: [PATCH] add missing class --- .../org/hl7/fhir/r5/utils/KeyGenerator.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/KeyGenerator.java diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/KeyGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/KeyGenerator.java new file mode 100644 index 000000000..d0dc272a1 --- /dev/null +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/KeyGenerator.java @@ -0,0 +1,75 @@ +package org.hl7.fhir.r5.utils; + +import org.hl7.fhir.r5.model.DomainResource; +import org.hl7.fhir.r5.model.MetadataResource; +import org.hl7.fhir.utilities.Utilities; + +public class KeyGenerator { + + private String canonical; + int i = 0; + + public KeyGenerator(String canonical) { + super(); + this.canonical = canonical; + } + + public void genId(DomainResource dr) { + i++; + dr.setId(getAcronym(dr.fhirType())+Integer.toString(i)); + if (dr instanceof MetadataResource) { + MetadataResource mr = (MetadataResource) dr; + mr.setUrl(Utilities.pathURL(canonical, mr.fhirType(), mr.getId())); + } + } + + private String getAcronym(String rt) { + if ("CapabilityStatement".equals(rt)) { + return "cs"; + } + if ("ValueSet".equals(rt)) { + return "vs"; + } + if ("CodeSystem".equals(rt)) { + return "cs"; + } + if ("StructureDefinition".equals(rt)) { + return "sd"; + } + if ("StructureMap".equals(rt)) { + return "sm"; + } + if ("ConceptMap".equals(rt)) { + return "cm"; + } + if ("ImplementationGuide".equals(rt)) { + return ""; + } + if ("SearchParameter".equals(rt)) { + return "sp"; + } + if ("MessageDefinition".equals(rt)) { + return "md"; + } + if ("OperationDefinition".equals(rt)) { + return "od"; + } + if ("CompartmentDefinition".equals(rt)) { + return "cd"; + } + if ("GraphDefinition".equals(rt)) { + return "gd"; + } + if ("ExampleScenario".equals(rt)) { + return "es"; + } + if ("NamingSystem".equals(rt)) { + return "ns"; + } + if ("TerminologyCapabilities".equals(rt)) { + return "tc"; + } + return "r"; + } + +}