001package org.hl7.fhir.convertors.conv30_50.resources30_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext30_50;
004import org.hl7.fhir.convertors.conv30_50.datatypes30_50.Reference30_50;
005import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Annotation30_50;
006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.CodeableConcept30_50;
007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Identifier30_50;
008import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.DateTime30_50;
009import org.hl7.fhir.exceptions.FHIRException;
010
011public class Condition30_50 {
012
013  private static final String CODE_SYSTEM_LEGACY_CONDITION_VER_CLINICAL_URL = "http://hl7.org/fhir/condition-ver-status";
014
015  private static final String CODE_SYSTEM_CONDITION_VER_CLINICAL_URL = "http://terminology.hl7.org/CodeSystem/condition-ver-status";
016
017  private static final String CODE_SYSTEM_LEGACY_CONDITION_CLINICAL_URL = "http://hl7.org/fhir/condition-clinical";
018
019  private static final String CODE_SYSTEM_CONDITION_CLINICAL_URL = "http://terminology.hl7.org/CodeSystem/condition-clinical";
020
021  public static org.hl7.fhir.r5.model.Condition convertCondition(org.hl7.fhir.dstu3.model.Condition src) throws FHIRException {
022    if (src == null)
023      return null;
024    org.hl7.fhir.r5.model.Condition tgt = new org.hl7.fhir.r5.model.Condition();
025    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
026    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
027      tgt.addIdentifier(Identifier30_50.convertIdentifier(t));
028    if (src.hasClinicalStatus())
029      tgt.setClinicalStatus(convertConditionClinicalStatus(src.getClinicalStatus()));
030    if (src.hasVerificationStatus())
031      tgt.setVerificationStatus(convertConditionVerificationStatus(src.getVerificationStatus()));
032    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getCategory())
033      tgt.addCategory(CodeableConcept30_50.convertCodeableConcept(t));
034    if (src.hasSeverity())
035      tgt.setSeverity(CodeableConcept30_50.convertCodeableConcept(src.getSeverity()));
036    if (src.hasCode())
037      tgt.setCode(CodeableConcept30_50.convertCodeableConcept(src.getCode()));
038    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getBodySite())
039      tgt.addBodySite(CodeableConcept30_50.convertCodeableConcept(t));
040    if (src.hasSubject())
041      tgt.setSubject(Reference30_50.convertReference(src.getSubject()));
042    if (src.hasContext())
043      tgt.setEncounter(Reference30_50.convertReference(src.getContext()));
044    if (src.hasOnset())
045      tgt.setOnset(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getOnset()));
046    if (src.hasAbatement())
047      tgt.setAbatement(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getAbatement()));
048    if (src.hasAssertedDate())
049      tgt.setRecordedDateElement(DateTime30_50.convertDateTime(src.getAssertedDateElement()));
050    if (src.hasAsserter())
051      tgt.setAsserter(Reference30_50.convertReference(src.getAsserter()));
052    if (src.hasStage())
053      tgt.addStage(convertConditionStageComponent(src.getStage()));
054    for (org.hl7.fhir.dstu3.model.Condition.ConditionEvidenceComponent t : src.getEvidence())
055      tgt.addEvidence(convertConditionEvidenceComponent(t));
056    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t));
057    return tgt;
058  }
059
060  public static org.hl7.fhir.dstu3.model.Condition convertCondition(org.hl7.fhir.r5.model.Condition src) throws FHIRException {
061    if (src == null)
062      return null;
063    org.hl7.fhir.dstu3.model.Condition tgt = new org.hl7.fhir.dstu3.model.Condition();
064    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
065    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
066      tgt.addIdentifier(Identifier30_50.convertIdentifier(t));
067    if (src.hasClinicalStatus())
068      tgt.setClinicalStatus(convertConditionClinicalStatus(src.getClinicalStatus()));
069    if (src.hasVerificationStatus())
070      tgt.setVerificationStatus(convertConditionVerificationStatus(src.getVerificationStatus()));
071    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getCategory())
072      tgt.addCategory(CodeableConcept30_50.convertCodeableConcept(t));
073    if (src.hasSeverity())
074      tgt.setSeverity(CodeableConcept30_50.convertCodeableConcept(src.getSeverity()));
075    if (src.hasCode())
076      tgt.setCode(CodeableConcept30_50.convertCodeableConcept(src.getCode()));
077    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getBodySite())
078      tgt.addBodySite(CodeableConcept30_50.convertCodeableConcept(t));
079    if (src.hasSubject())
080      tgt.setSubject(Reference30_50.convertReference(src.getSubject()));
081    if (src.hasEncounter())
082      tgt.setContext(Reference30_50.convertReference(src.getEncounter()));
083    if (src.hasOnset())
084      tgt.setOnset(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getOnset()));
085    if (src.hasAbatement())
086      tgt.setAbatement(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getAbatement()));
087    if (src.hasRecordedDate())
088      tgt.setAssertedDateElement(DateTime30_50.convertDateTime(src.getRecordedDateElement()));
089    if (src.hasAsserter())
090      tgt.setAsserter(Reference30_50.convertReference(src.getAsserter()));
091    if (src.hasStage())
092      tgt.setStage(convertConditionStageComponent(src.getStageFirstRep()));
093    for (org.hl7.fhir.r5.model.Condition.ConditionEvidenceComponent t : src.getEvidence())
094      tgt.addEvidence(convertConditionEvidenceComponent(t));
095    for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t));
096    return tgt;
097  }
098
099  static public org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus convertConditionClinicalStatus(org.hl7.fhir.r5.model.CodeableConcept src) throws FHIRException {
100    if (src == null)
101      return null;
102    if (src.hasCoding(CODE_SYSTEM_CONDITION_CLINICAL_URL, "active") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_CLINICAL_URL, "active"))
103      return org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus.ACTIVE;
104    if (src.hasCoding(CODE_SYSTEM_CONDITION_CLINICAL_URL, "recurrence") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_CLINICAL_URL, "recurrence"))
105      return org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus.RECURRENCE;
106    if (src.hasCoding(CODE_SYSTEM_CONDITION_CLINICAL_URL, "inactive") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_CLINICAL_URL, "inactive"))
107      return org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus.INACTIVE;
108    if (src.hasCoding(CODE_SYSTEM_CONDITION_CLINICAL_URL, "remission") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_CLINICAL_URL, "remission"))
109      return org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus.REMISSION;
110    if (src.hasCoding(CODE_SYSTEM_CONDITION_CLINICAL_URL, "resolved") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_CLINICAL_URL, "resolved"))
111      return org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus.RESOLVED;
112    return org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus.NULL;
113  }
114
115  static public org.hl7.fhir.r5.model.CodeableConcept convertConditionClinicalStatus(org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus src) throws FHIRException {
116    if (src == null)
117      return null;
118    org.hl7.fhir.r5.model.CodeableConcept cc = new org.hl7.fhir.r5.model.CodeableConcept();
119    switch (src) {
120      case ACTIVE:
121        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_CLINICAL_URL).setCode("active");
122        return cc;
123      case RECURRENCE:
124        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_CLINICAL_URL).setCode("recurrence");
125        return cc;
126      case INACTIVE:
127        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_CLINICAL_URL).setCode("inactive");
128        return cc;
129      case REMISSION:
130        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_CLINICAL_URL).setCode("remission");
131        return cc;
132      case RESOLVED:
133        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_CLINICAL_URL).setCode("resolved");
134        return cc;
135      default:
136        return null;
137    }
138  }
139
140  public static org.hl7.fhir.r5.model.Condition.ConditionEvidenceComponent convertConditionEvidenceComponent(org.hl7.fhir.dstu3.model.Condition.ConditionEvidenceComponent src) throws FHIRException {
141    if (src == null)
142      return null;
143    org.hl7.fhir.r5.model.Condition.ConditionEvidenceComponent tgt = new org.hl7.fhir.r5.model.Condition.ConditionEvidenceComponent();
144    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
145    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getCode())
146      tgt.addCode(CodeableConcept30_50.convertCodeableConcept(t));
147    for (org.hl7.fhir.dstu3.model.Reference t : src.getDetail()) tgt.addDetail(Reference30_50.convertReference(t));
148    return tgt;
149  }
150
151  public static org.hl7.fhir.dstu3.model.Condition.ConditionEvidenceComponent convertConditionEvidenceComponent(org.hl7.fhir.r5.model.Condition.ConditionEvidenceComponent src) throws FHIRException {
152    if (src == null)
153      return null;
154    org.hl7.fhir.dstu3.model.Condition.ConditionEvidenceComponent tgt = new org.hl7.fhir.dstu3.model.Condition.ConditionEvidenceComponent();
155    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
156    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getCode())
157      tgt.addCode(CodeableConcept30_50.convertCodeableConcept(t));
158    for (org.hl7.fhir.r5.model.Reference t : src.getDetail()) tgt.addDetail(Reference30_50.convertReference(t));
159    return tgt;
160  }
161
162  public static org.hl7.fhir.dstu3.model.Condition.ConditionStageComponent convertConditionStageComponent(org.hl7.fhir.r5.model.Condition.ConditionStageComponent src) throws FHIRException {
163    if (src == null)
164      return null;
165    org.hl7.fhir.dstu3.model.Condition.ConditionStageComponent tgt = new org.hl7.fhir.dstu3.model.Condition.ConditionStageComponent();
166    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
167    if (src.hasSummary())
168      tgt.setSummary(CodeableConcept30_50.convertCodeableConcept(src.getSummary()));
169    for (org.hl7.fhir.r5.model.Reference t : src.getAssessment()) tgt.addAssessment(Reference30_50.convertReference(t));
170    return tgt;
171  }
172
173  public static org.hl7.fhir.r5.model.Condition.ConditionStageComponent convertConditionStageComponent(org.hl7.fhir.dstu3.model.Condition.ConditionStageComponent src) throws FHIRException {
174    if (src == null)
175      return null;
176    org.hl7.fhir.r5.model.Condition.ConditionStageComponent tgt = new org.hl7.fhir.r5.model.Condition.ConditionStageComponent();
177    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
178    if (src.hasSummary())
179      tgt.setSummary(CodeableConcept30_50.convertCodeableConcept(src.getSummary()));
180    for (org.hl7.fhir.dstu3.model.Reference t : src.getAssessment())
181      tgt.addAssessment(Reference30_50.convertReference(t));
182    return tgt;
183  }
184
185  static public org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus convertConditionVerificationStatus(org.hl7.fhir.r5.model.CodeableConcept src) throws FHIRException {
186    if (src == null)
187      return null;
188    if (src.hasCoding(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL, "provisional") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_VER_CLINICAL_URL, "provisional"))
189      return org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus.PROVISIONAL;
190    if (src.hasCoding(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL, "differential") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_VER_CLINICAL_URL, "differential"))
191      return org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus.DIFFERENTIAL;
192    if (src.hasCoding(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL, "confirmed") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_VER_CLINICAL_URL, "confirmed"))
193      return org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus.CONFIRMED;
194    if (src.hasCoding(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL, "refuted") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_VER_CLINICAL_URL, "refuted"))
195      return org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus.REFUTED;
196    if (src.hasCoding(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL, "entered-in-error") || src.hasCoding(CODE_SYSTEM_LEGACY_CONDITION_VER_CLINICAL_URL, "entered-in-error"))
197      return org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus.ENTEREDINERROR;
198    return org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus.NULL;
199  }
200
201  static public org.hl7.fhir.r5.model.CodeableConcept convertConditionVerificationStatus(org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus src) throws FHIRException {
202    if (src == null)
203      return null;
204    org.hl7.fhir.r5.model.CodeableConcept cc = new org.hl7.fhir.r5.model.CodeableConcept();
205    switch (src) {
206      case PROVISIONAL:
207        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL).setCode("provisional");
208        return cc;
209      case DIFFERENTIAL:
210        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL).setCode("differential");
211        return cc;
212      case CONFIRMED:
213        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL).setCode("confirmed");
214        return cc;
215      case REFUTED:
216        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL).setCode("refuted");
217        return cc;
218      case ENTEREDINERROR:
219        cc.addCoding().setSystem(CODE_SYSTEM_CONDITION_VER_CLINICAL_URL).setCode("entered-in-error");
220        return cc;
221      default:
222        return null;
223    }
224  }
225}