package org.endeavourhealth.transform.hl7v2.transform;


import org.endeavourhealth.transform.hl7v2.parser.ParseException;
import org.endeavourhealth.transform.hl7v2.parser.segments.ObxSegment;
import org.endeavourhealth.transform.hl7v2.transform.converters.CodeableConceptHelper;
import org.hl7.fhir.instance.model.Observation;
import org.hl7.fhir.instance.model.StringType;
import org.hl7.fhir.instance.model.Type;

public class ObservationTransform {

    public static Observation fromHl7v2(ObxSegment source) throws ParseException, TransformException {
        Observation observation = new Observation();

        observation.setStatus(Observation.ObservationStatus.FINAL);

        observation.setCode(CodeableConceptHelper.getCodeableConceptFromString(source.getObservationIdentifier().getAsString()));

        observation.setValue(CodeableConceptHelper.getCodeableConceptFromString(source.getObservationValue()));

        return observation;
    }

}

@@ -289,90 +289,71 @@
 org.
-hl7.fhir.instance.model.Observation;%0Aimport org
+endeavourhealth.transform
 .hl7
-.fhir.instance.model.StringTy
+v2.transform.converters.DateHel
 pe
+r
 ;%0Aim
@@ -389,12 +389,9 @@
 del.
-Type
+*
 ;%0A%0Ap
@@ -779,24 +779,96 @@
 tring()));%0A%0A
+        switch (source.getValueType()) %7B%0A            case %22CE%22:%0A        
         obse
@@ -963,24 +963,873 @@
 nValue()));%0A
+                break;%0A            case %22DT%22:%0A                observation.setValue(DateTimeType.parseV3(source.getObservationValue()));%0A                break;%0A            case %22ST%22:%0A                observation.setValue(new StringType().setValue(source.getObservationValue()));%0A                break;%0A            case %22NM%22:%0A                observation.setValue(new IntegerType().setValue(Integer.parseInt(source.getObservationValue())));%0A                break;%0A%0A            //Homerton specific%0A            case %22CD%22:%0A                observation.setValue(CodeableConceptHelper.getCodeableConceptFromString(source.getObservationValue()));%0A                break;%0A            //Default to string type%0A            default:%0A                observation.setValue(new StringType().setValue(source.getObservationValue()));%0A                break;%0A        %7D%0A%0A%0A%0A%0A
 %0A        ret

Set value type according to defined value type in the OBX segment