Package com.github.clentfort.dota2.parser

Examples of com.github.clentfort.dota2.parser.Parser


                + "PV2|||0112^TESTING|55555^PATIENT IS NORMAL|NONE|||19990225|19990226|1|1|TESTING|555888^NOTREAL^BOB^K^DR^MD||||||||||PROD^003^099|02|ER||NONE|19990225|19990223|19990316|NONE\r"
                + "AL1||SEV|001^POLLEN\r"
                + "AL1||SEV|003^DUST\r"
                + "GT1||0222PL|NOTREAL^BOB^B||STREET^OTHER STREET^CITY^ST^77787|(444)999-3333|(222)777-5555||||MO|111-33-5555||||NOTREAL GILL N|STREET^OTHER STREET^CITY^ST^99999|(111)222-3333\r"
                + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";
        Parser p = new GenericParser();
        Message hapiMsg = p.parse(msg);
       
        /*
         * Another way of reading messages is to use a Terser. The terser
         * accepts a particular syntax to retrieve segments. See the API
         * documentation for the Terser for more information.
         */
        Terser terser = new Terser(hapiMsg);
       
        /*
         * Sending Application is in MSH-3-1 (the first component of the third
         * field of the MSH segment)
         */
        String sendingApplication = terser.get("/.MSH-3-1");
        System.out.println(sendingApplication);
        // HIS
       
        /*
         * We can use brackets to get particular repetitions
         */
        String secondAllergyType = terser.get("/AL1(1)-3-2");
        System.out.println(secondAllergyType);
        // DUST
       
        // We can also use the terser to set values
        terser.set("/.MSH-3-1", "new_sending_app");
       
        // Let's try something more complicated, adding values to an OBX in an ORU^R01
        ORU_R01 oru = new ORU_R01();
        oru.getMSH().getEncodingCharacters().setValue("^~\\&");
        oru.getMSH().getFieldSeparator().setValue("|");
        oru.getMSH().getMessageType().getMessageCode().setValue("ORU");
        oru.getMSH().getMessageType().getTriggerEvent().setValue("R01");
        oru.getMSH().getVersionID().getVersionID().setValue("2.5");
       
        terser = new Terser(oru);
        for (int i = 0; i < 5; i++) {
            terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-1", "" + (i + 1));
            terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-3", "ST");
            terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-5", "This is the value for rep " + i);
        }
       
        System.out.println(p.encode(oru));
       
        /*
         *   MSH|^~\&|||||||ORU^R01|||2.5
         *   OBX|1||ST||This is the value for rep 0
         *   OBX|2||ST||This is the value for rep 1
View Full Code Here


        /*
         * A Parser is used to convert between string representations of messages and instances of
         * HAPI's "Message" object. In this case, we are using a "GenericParser", which is able to
         * handle both XML and ER7 (pipe & hat) encodings.
         */
        Parser p = new GenericParser();

        Message hapiMsg;
        try {
            // The parse method performs the actual parsing
            hapiMsg = p.parse(msg);
        } catch (EncodingNotSupportedException e) {
            e.printStackTrace();
            return;
        } catch (HL7Exception e) {
            e.printStackTrace();
View Full Code Here

            + "AL1||SEV|001^POLLEN\r"
            + "GT1||0222PL|NOTREAL^BOB^B||STREET^OTHER STREET^CITY^ST^77787|(444)999-3333|(222)777-5555||||MO|111-33-5555||||NOTREAL GILL N|STREET^OTHER STREET^CITY^ST^99999|(111)222-3333\r"
            + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";

        // Let's create a special parser to handle this:
        Parser parser = new PipeParser() {

            // We override the parse method to correct issues
            public Message parse(String theMessage) throws HL7Exception, EncodingNotSupportedException {
                theMessage = theMessage.replace("\rPI|", "\rPID|");
                return super.parse(theMessage);
            }};
       
        Message message = parser.parse(msg);
       
        System.out.println(parser.encode(message));
       
        /* PI has been fixed:
        
            MSH|^~\&|HIS|RIH|EKG|EKG|199904140038||ADT^A01||P|2.2
            PID|0001|00009874|00001122|A00977|SMITH^JOHN^M|MOM|19581119|F|NOTREAL^LINDA^M|C|564 SPRING ST^^NEEDHAM^MA^02494^US|0002|(818)565-1551|(425)828-3344|E|S|C|0000444444|252-00-4414||||SA|||SA||||NONE|V1|0001|I|D.ER^50A^M110^01|ER|P00055|11B^M011^02|070615^BATMAN^GEORGE^L|555888^NOTREAL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^NOTREAL^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|199904101200||||5555112333|||666097^NOTREAL^MANNY^P
View Full Code Here

        /*
         * In a real situation, of course, many more segments and fields would be populated
         */
               
        // Now, let's encode the message and look at the output
        Parser parser = new PipeParser();
        String encodedMessage = parser.encode(adt);
        System.out.println("Printing ER7 Encoded Message:");
        System.out.println(encodedMessage);
       
        /*
         * Prints:
         *
         * MSH|^~\&|TestSendingSystem||||200701011539||ADT^A01^ADT A01||||123
         * PID|||123456||Doe^John
         */

        // Next, let's use the XML parser to encode as XML
        parser = new DefaultXMLParser();
        encodedMessage = parser.encode(adt);
        System.out.println("Printing XML Encoded Message:");
        System.out.println(encodedMessage);
       
        /*
         * Prints:
 
View Full Code Here

                + "PV1|0001|I|D.ER^1F^M950^01|ER|P000998|11B^M011^02|070615^BATMAN^GEORGE^L|555888^OKNEL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^VOICE^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|||||5555112333|||666097^DNOTREAL^MANNY^P\r"
                + "PV2|||0112^TESTING|55555^PATIENT IS NORMAL|NONE|||19990225|19990226|1|1|TESTING|555888^NOTREAL^BOB^K^DR^MD||||||||||PROD^003^099|02|ER||NONE|19990225|19990223|19990316|NONE\r"
                + "AL1||SEV|001^POLLEN\r"
                + "GT1||0222PL|NOTREAL^BOB^B||STREET^OTHER STREET^CITY^ST^77787|(444)999-3333|(222)777-5555||||MO|111-33-5555||||NOTREAL GILL N|STREET^OTHER STREET^CITY^ST^99999|(111)222-3333\r"
                + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";
        Parser p = new GenericParser();
        Message adt = p.parse(msg);

        // The connection hub connects to listening servers
        ConnectionHub connectionHub = ConnectionHub.getInstance();

        // A connection object represents a socket attached to an HL7 server
View Full Code Here

      object.remove(BASE_ABILITY);
    }
    else throw new ParserException("The ParserObject is not a valid items object!");
   
    Ability baseAbility = baseAbility(baseObject);
    Abilities a = new Abilities();
    List<Ability> abilities = a.getAbility();
   
    for (Iterator i = object.keys(); i.hasNext();) {
      String key = (String)i.next();
      if (!(object.get(key) instanceof ParserObject)) continue;
      ParserObject abilityObject = object.getParserObject(key);
View Full Code Here

    }
    return;
  }
 
  protected static Ability baseAbility(ParserObject baseObject) throws ParserException {
    Ability baseAbility = new Ability();
    baseAbility.setId(baseObject.getInt("ID"));
    baseAbility.setName(baseObject.getString("AbilityName"));
    baseAbility.setType(baseObject.getString("AbilityType"));
    baseAbility.setBehavior(baseObject.getString("AbilityBehavior"));
   
    fillAbilityLevelBasedList(baseAbility.getCastRange(), baseObject.getString("AbilityCastRange"));
    fillAbilityLevelBasedList(baseAbility.getChannelTime(), baseObject.getString("AbilityChannelTime"));
    fillAbilityLevelBasedList(baseAbility.getCooldown(), baseObject.getString("AbilityCooldown"));
    fillAbilityLevelBasedList(baseAbility.getDuration(), baseObject.getString("AbilityDuration"));
    fillAbilityLevelBasedList(baseAbility.getDamage(), baseObject.getString("AbilityDamage"));
    fillAbilityLevelBasedList(baseAbility.getManacost(), baseObject.getString("AbilityManaCost"));
   
    return baseAbility;
  }
View Full Code Here

      baseObject = object.getParserObject(BASE_ABILITY);
      object.remove(BASE_ABILITY);
    }
    else throw new ParserException("The ParserObject is not a valid items object!");
   
    Ability baseAbility = baseAbility(baseObject);
    Abilities a = new Abilities();
    List<Ability> abilities = a.getAbility();
   
    for (Iterator i = object.keys(); i.hasNext();) {
      String key = (String)i.next();
      if (!(object.get(key) instanceof ParserObject)) continue;
      ParserObject abilityObject = object.getParserObject(key);
      Ability ability = new Ability(baseAbility);
     
      if (abilityObject.has("ID"))
        ability.setId(abilityObject.getInt("ID"));
      if (abilityObject.has("AbilityName"))
        ability.setName(abilityObject.getString("AbilityName"));
      if (abilityObject.has("AbilityType"))
        ability.setType(abilityObject.getString("AbilityType"));
      if (abilityObject.has("AbilityBehavior"))
        ability.setBehavior("AbilityBehavior");

      if (abilityObject.has("AbilityCastRange"))
        fillAbilityLevelBasedList(ability.getCastRange(), abilityObject.getString("AbilityCastRange"));
      if (abilityObject.has("AbilityChannelTime"))
        fillAbilityLevelBasedList(ability.getChannelTime(), abilityObject.getString("AbilityChannelTime"));
      if (abilityObject.has("AbilityCooldown"))
        fillAbilityLevelBasedList(ability.getCooldown(), abilityObject.getString("AbilityCooldown"));
      if (abilityObject.has("AbilityDuration"))
        fillAbilityLevelBasedList(ability.getDuration(), abilityObject.getString("AbilityDuration"));
      if (abilityObject.has("AbilityDamage"))
        fillAbilityLevelBasedList(ability.getDamage(), abilityObject.getString("AbilityDamage"));
      if (abilityObject.has("AbilityManaCost"))
        fillAbilityLevelBasedList(ability.getManacost(), abilityObject.getString("AbilityManaCost"));
     
      abilities.add(ability);
    }
   
    return a;
View Full Code Here

   
  protected static void fillAbilityLevelBasedList(List<AbilityLevelBasedType> list, String string) {
    String[] values = string.split(" ");
    list.clear();
    for (int i = 0; i < values.length; i++) {
      AbilityLevelBasedType type = new AbilityLevelBasedType();
      type.setLevel(i);
      type.setValue(Double.parseDouble((String)values[i]));
      list.add(type);
    }
    return;
  }
View Full Code Here

    List<Unit> units = u.getUnit();
    Heroes h = new Heroes();
    List<Hero> heroes = h.getHero();
    for (Unit unit : units) {
      //Hero hero = (Hero)unit;
      Hero hero = new Hero(unit);
      ParserObject heroObject = object.getParserObject(hero.getName());
      if (heroObject.has("HeroID"))
        hero.setId(heroObject.getInt("HeroID"));
     
      if (heroObject.has("Role"))
        hero.setRole(HeroRole.fromValue(heroObject.getString("Role")));
     
      if (heroObject.has("NameAliases"))
        hero.setAlias(heroObject.getString("NameAliases"));
     
      heroes.add(hero);
    }
    return h;
  }
View Full Code Here

TOP

Related Classes of com.github.clentfort.dota2.parser.Parser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.